From dad997773fbe6975bef64b2ba083e131f470d265 Mon Sep 17 00:00:00 2001 From: Elliot Drel Date: Wed, 4 Nov 2026 08:23:48 -0500 Subject: [PATCH] fix(web): count backslash parity before adjacent composer markers --- .../ComposerPromptEditorTiptap.input.browser.test.tsx | 2 ++ apps/web/src/composer-markdown-source.ts | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx index 236eddf84330..9b71fd8d1f43 100644 --- a/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +++ b/apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx @@ -155,6 +155,8 @@ it.each([ { word: "path\\", prefix: "", source: [] }, { word: "2*3", prefix: "", source: [] }, { word: "b", prefix: "*", source: [] }, + { word: "word", prefix: "\\\\*", source: [] }, + { word: "word", prefix: "\\\\**", source: [] }, { word: "word", prefix: "\\", source: [] }, { word: "word", prefix: "\\\\", source: ["**word**"] }, { word: "word", prefix: "\\\\\\", source: [] }, diff --git a/apps/web/src/composer-markdown-source.ts b/apps/web/src/composer-markdown-source.ts index b75dca552815..cefaf812c8af 100644 --- a/apps/web/src/composer-markdown-source.ts +++ b/apps/web/src/composer-markdown-source.ts @@ -161,8 +161,10 @@ function withAdjacentDelimiters(doc: ProseMirrorNode, region: TextRange): TextRa const text = before.text!; let count = 0; while (count < text.length && DELIMITER.test(text[text.length - 1 - count]!)) count += 1; - // A backslash escapes the delimiter after it. - if (count > 0 && text[text.length - 1 - count] === "\\") count -= 1; + // Only an odd backslash run escapes the first adjacent delimiter. + let backslashes = 0; + while (text[text.length - 1 - count - backslashes] === "\\") backslashes += 1; + if (count > 0 && backslashes % 2 === 1) count -= 1; from -= count; } if (after?.isText && after.marks.length === 0) {