Skip to content

Commit 238091e

Browse files
fix(web): style shortcuts next to a shown styled word apply again
Only turning a style off just inside its own shown markers goes through the source toggle. Adding a style at a marker boundary falls back to Tiptap's toggle, 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 1ba5ee5 commit 238091e

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

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

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,28 @@ it.each([
175175
});
176176

177177
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-
});
178+
{ key: "i", caret: 10, expected: "ship it **n*X*ow** done" },
179+
{ key: "e", caret: 10, expected: "ship it **n`X`ow** done" },
180+
{ key: "i", caret: 9, expected: "ship it *X***now** done" },
181+
{ key: "i", caret: "{ArrowLeft>5/}", expected: "ship it **now***X* done" },
182+
{ key: "e", caret: "{ArrowLeft>5/}", expected: "ship it **now**`X` done" },
183+
])(
184+
"Mod+$key at $caret in a bold word styles the next typed text",
185+
async ({ key, caret, expected }) => {
186+
await using screen = await mountEditor("ship it **now** done");
187+
const { editor } = screen;
188+
const mod = isMacPlatform(navigator.platform) ? "Meta" : "Control";
189+
await act(async () => {
190+
if (typeof caret === "number") editor.commands.focus(caret);
191+
else editor.commands.focus("end");
192+
});
193+
await vi.waitFor(() => expect(document.activeElement).toBe(editor.view.dom));
194+
if (typeof caret === "string") await userEvent.keyboard(caret);
195+
await userEvent.keyboard(`{${mod}>}${key}{/${mod}}`);
196+
await userEvent.keyboard("X");
197+
await vi.waitFor(() => expect(serializeEditorDoc(editor.state.doc).value).toBe(expected));
198+
},
199+
);
193200

194201
it.each([
195202
{ word: "ship", prefix: "", source: ["**ship**"] },

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,15 @@ export const ComposerMarkdownSourceExtension = TiptapMark.create({
554554
const touched = sourceRegions(state.doc, this.type).some((region) => {
555555
if (!touches(selection, region)) return false;
556556
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.
557+
// Turning a style off just inside its own markers would type into them.
558+
// Everywhere else Tiptap's own toggle styles the typed text correctly.
559559
const { units } = regionUnits(state.doc, region);
560560
const offset = selection.from - region.from;
561-
return units[offset - 1] === null || units[offset] === null;
561+
const [before, after] = [units[offset - 1], units[offset]];
562+
return (
563+
(before === null && after?.includes(name) === true) ||
564+
(after === null && before?.includes(name) === true)
565+
);
562566
});
563567
if (!touched) return false;
564568
return this.editor.chain().command(collapseShownMarkdownSource).toggleMark(name).run();

0 commit comments

Comments
 (0)