Skip to content

Commit 7b6053c

Browse files
ElliotDrelshivamhwp
authored andcommitted
fix(web): count backslash parity before adjacent composer markers
1 parent 17c7b4f commit 7b6053c

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ it.each([
155155
{ word: "path\\", prefix: "", source: [] },
156156
{ word: "2*3", prefix: "", source: [] },
157157
{ word: "b", prefix: "*", source: [] },
158+
{ word: "word", prefix: "\\\\*", source: [] },
159+
{ word: "word", prefix: "\\\\**", source: [] },
158160
{ word: "word", prefix: "\\", source: [] },
159161
{ word: "word", prefix: "\\\\", source: ["**word**"] },
160162
{ word: "word", prefix: "\\\\\\", source: [] },

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ function withAdjacentDelimiters(doc: ProseMirrorNode, region: TextRange): TextRa
161161
const text = before.text!;
162162
let count = 0;
163163
while (count < text.length && DELIMITER.test(text[text.length - 1 - count]!)) count += 1;
164-
// A backslash escapes the delimiter after it.
165-
if (count > 0 && text[text.length - 1 - count] === "\\") count -= 1;
164+
// Only an odd backslash run escapes the first adjacent delimiter.
165+
let backslashes = 0;
166+
while (text[text.length - 1 - count - backslashes] === "\\") backslashes += 1;
167+
if (count > 0 && backslashes % 2 === 1) count -= 1;
166168
from -= count;
167169
}
168170
if (after?.isText && after.marks.length === 0) {

0 commit comments

Comments
 (0)