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) {