Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import type { ServerProviderSkill } from "@t3tools/contracts";
import type { Editor } from "@tiptap/core";
import { redoDepth, undoDepth } from "@tiptap/pm/history";
import { NodeSelection } from "@tiptap/pm/state";
import { createElement, createRef, useEffect, useState } from "react";
import { describe, expect, it, vi } from "vite-plus/test";
import { userEvent } from "vite-plus/test/browser";
Expand Down Expand Up @@ -212,6 +213,34 @@ it.each([
},
);

it("keeps a styled atom selected when its Markdown source is revealed", async () => {
const reference = formatInlineContextReference(fileContextReference(file));
await using screen = await mountEditor(`**${reference}** after`);
const { editor } = screen;
await act(async () => {
editor.commands.setTextSelection(editor.state.doc.content.size - 1);
});
let atom = -1;
editor.state.doc.descendants((node, pos) => {
if (node.isInline && node.isAtom && !node.isText) atom = pos;
});
expect(atom).toBeGreaterThan(0);
await act(async () => {
editor.commands.setNodeSelection(atom);
});
expect(editor.state.selection).toBeInstanceOf(NodeSelection);
expect((editor.state.selection as NodeSelection).node.isAtom).toBe(true);
expect((editor.state.selection as NodeSelection).node.isText).toBe(false);
await act(async () => {
editor.commands.deleteSelection();
});
let atoms = 0;
editor.state.doc.descendants((node) => {
if (node.isInline && node.isAtom && !node.isText) atoms++;
});
expect(atoms).toBe(0);
expect(serializeEditorDoc(editor.state.doc).value).toContain("after");
});
it.each([false, true])(
"composes an umlaut without wrapping the preedit text (rich text: %s)",
async (richTextEnabled) => {
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/composer-markdown-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ function revealStyledText(tr: Transaction, type: MarkType, typed: boolean, takes
let next = pos;
for (const { at, length, closing } of insertions) {
const inside = typed && selection.empty && (closing ? takesBefore : !takesBefore);
if (at < pos || (at === pos && closing !== inside)) next += length;
if (at < pos || (at === pos && (selection instanceof NodeSelection || closing !== inside)))
next += length;
}
return next;
};
Expand Down
Loading