Skip to content

Commit 1ba5ee5

Browse files
fix(web): style shortcuts inside a shown bold word nest again
Only a collapsed caret next to shown markers goes through the source toggle; elsewhere Tiptap's own toggle nests the style as before, instead of the re-reveal dropping the stored mark. AI-assisted; verified with the tests and tools listed above. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0548ca0 commit 1ba5ee5

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,23 @@ it.each([
174174
expect(textWithMark(editor, mark)).toEqual(["now"]);
175175
});
176176

177+
it.each([
178+
{ key: "i", expected: "ship it **n*X*ow** done" },
179+
{ key: "e", expected: "ship it **n`X`ow** done" },
180+
])("Mod+$key inside a bold word styles the next typed text", async ({ key, expected }) => {
181+
await using screen = await mountEditor("ship it **now** done");
182+
const { editor } = screen;
183+
const mod = isMacPlatform(navigator.platform) ? "Meta" : "Control";
184+
await act(async () => {
185+
editor.commands.focus();
186+
editor.commands.setTextSelection(10);
187+
});
188+
await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
189+
await userEvent.keyboard(`{${mod}>}${key}{/${mod}}`);
190+
await userEvent.keyboard("X");
191+
await vi.waitFor(() => expect(serializeEditorDoc(editor.state.doc).value).toBe(expected));
192+
});
193+
177194
it.each([
178195
{ word: "ship", prefix: "", source: ["**ship**"] },
179196
{ word: "path\\", prefix: "", source: [] },

‎apps/web/src/composer-markdown-source.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,16 @@ export const ComposerMarkdownSourceExtension = TiptapMark.create({
550550
// in another style. Parse the source first and toggle the result.
551551
const toggle = (name: RichTextMark) => () => {
552552
const { state } = this.editor;
553-
const touched = sourceRegions(state.doc, this.type).some((region) =>
554-
touches(state.selection, region),
555-
);
553+
const { selection } = state;
554+
const touched = sourceRegions(state.doc, this.type).some((region) => {
555+
if (!touches(selection, region)) return false;
556+
if (!selection.empty) return true;
557+
// Typing next to a marker would land in the markers. Elsewhere Tiptap's own
558+
// toggle nests the style inside the source correctly.
559+
const { units } = regionUnits(state.doc, region);
560+
const offset = selection.from - region.from;
561+
return units[offset - 1] === null || units[offset] === null;
562+
});
556563
if (!touched) return false;
557564
return this.editor.chain().command(collapseShownMarkdownSource).toggleMark(name).run();
558565
};

0 commit comments

Comments
 (0)