Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(chrome-ext): Typst editors did not properly use `<br>` (#4732)
Elijah Potter3e08646c2109
diff --git a/packages/chrome-plugin/tests/testUtils.ts b/packages/chrome-plugin/tests/testUtils.tsindex f466b2409..4ffc7cc17 100644--- a/packages/chrome-plugin/tests/testUtils.ts+++ b/packages/chrome-plugin/tests/testUtils.ts@@ -93,8 +93,9 @@ export async function replaceEditorContent(editorEl: Locator, text: string, softif (needsCharacterInput) {// Draft.js needs character key events at a normal typing cadence for its selection model.await editorEl.pressSequentially(lines[i], { delay: 200 });- } else {+ } else if (lines[i]) {// Native text input updates the editor model without exposing partial words to linting.+ // Firefox rejects empty insertText calls; the break key below creates empty lines.await editorEl.page().keyboard.insertText(lines[i]);}if (i < lines.length - 1) {diff --git a/packages/chrome-plugin/tests/typst.spec.ts b/packages/chrome-plugin/tests/typst.spec.tsindex ba164141c..e0427ef67 100644--- a/packages/chrome-plugin/tests/typst.spec.ts+++ b/packages/chrome-plugin/tests/typst.spec.ts@@ -24,6 +24,31 @@ test('Typst CodeMirror editor can apply a suggestion', async ({ page }) => {await expect(editor).toContainText('This is a test');});+for (const blankLines of [1, 3, 5]) {+ test(`Typst CodeMirror can apply a suggestion after ${blankLines} blank lines`, async ({+ page,+ }) => {+ test.slow();+ await page.goto(TEST_PAGE_URL, { waitUntil: 'domcontentloaded' });++ const editor = page.locator('.cm-editor .cm-content[contenteditable="true"]').first();+ await expect(editor).toBeVisible({ timeout: 30000 });+ await replaceEditorContent(+ editor,+ `This is correct.${'\n'.repeat(blankLines + 1)}This is an test`,+ );++ await assertHighlightCount(page, 1);++ expect(await clickHarperHighlight(page)).toBe(true);+ await page.getByTitle('Click to replace "an" with "a"').click();++ await expect(editor).toContainText('This is correct.');+ await expect(editor).toContainText('This is a test');+ await assertHighlightCount(page, 0);+ });+}+test('Typst CodeMirror handles multiline suggestions distinctly', async ({ page }) => {test.setTimeout(120000);await page.goto(TEST_PAGE_URL, { waitUntil: 'domcontentloaded' });diff --git a/packages/lint-framework/src/lint/domUtils.ts b/packages/lint-framework/src/lint/domUtils.tsindex 76cc02c9f..5e01de57e 100644--- a/packages/lint-framework/src/lint/domUtils.ts+++ b/packages/lint-framework/src/lint/domUtils.ts@@ -95,6 +95,7 @@ export function leafNodes(node: Node): Node[] {/*** Given an element and a Span of text inside it, compute the Range that represents the region of the DOM represented.* Accounts for `<br>` elements which `innerText` converts to newlines.+ * CodeMirror spans already exclude line breaks, so its placeholder `<br>` elements count as zero.* @param target* @param span*/@@ -110,7 +111,7 @@ export function getRangeForTextSpan(target: Element, span: Span): Range | null {const child = children[i] as HTMLElement;if (child.nodeName === 'BR') {- traversed += 1;+ traversed += child.closest('.cm-line') ? 0 : 1;continue;}