Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix(chrome-ext): don't close popup when the context_hash changes (#4658)
Elijah Potterfbb7a6605b84
diff --git a/packages/chrome-plugin/tests/testUtils.ts b/packages/chrome-plugin/tests/testUtils.tsindex 744e00827..f466b2409 100644--- a/packages/chrome-plugin/tests/testUtils.ts+++ b/packages/chrome-plugin/tests/testUtils.ts@@ -161,8 +161,14 @@ export async function waitForHighlightsToSettle(export async function waitForHarperHighlightCenter(page: Page,timeoutMs = 30000,+ /** Require that the highlight in question have this "problemText" before returning. */+ problemText: string | null = null,): Promise<ScreenPoint | null> {- const highlight = getHarperHighlights(page).first();+ let highlight = getHarperHighlights(page).first();++ if (problemText != null) {+ highlight = highlight.and(page.locator(`[data-problem-text="${problemText}"]`));+ }try {await highlight.waitFor({ state: 'visible', timeout: timeoutMs });@@ -197,8 +203,12 @@ export async function assertLocatorsResolveEqually(page: Page, a: Locator, b: Lo/** Click the first Harper highlight and check that its popup opens.* Returns false if no highlight was found; a missing popup fails the test. */-export async function clickHarperHighlight(page: Page): Promise<boolean> {- const center = await waitForHarperHighlightCenter(page);+export async function clickHarperHighlight(+ page: Page,+ /** Require that the highlight be over specific text before clicking it. */+ problemText: string | null = null,+): Promise<boolean> {+ const center = await waitForHarperHighlightCenter(page, undefined, problemText);if (center == null) return false;await page.mouse.click(center.x, center.y);@@ -300,7 +310,7 @@ export async function testBasicSuggestion(await assertEditorText(editor, 'This is an test');await waitForHighlightsToSettle(page);- const opened = await clickHarperHighlight(page);+ const opened = await clickHarperHighlight(page, 'an');expect(opened).toBe(true);const suggestion = page.getByTitle('Click to replace "an" with "a"');await expect(suggestion).toBeVisible();@@ -349,7 +359,7 @@ export async function testCanIgnoreSuggestion(await expect(getHarperHighlights(page)).toHaveCount(1, { timeout: 30000 });// Open the popup for the highlight and click Ignore.- const opened = await clickHarperHighlight(page);+ const opened = await clickHarperHighlight(page, 'mistaek');expect(opened).toBe(true);// The popup captures the editor's cursor state on the next animation frame.diff --git a/packages/lint-framework/src/lint/Highlights.ts b/packages/lint-framework/src/lint/Highlights.tsindex dbc4102b1..05a07aa27 100644--- a/packages/lint-framework/src/lint/Highlights.ts+++ b/packages/lint-framework/src/lint/Highlights.ts@@ -214,6 +214,9 @@ export default class Highlights {backgroundColor: `${lintKindColor(box.lint.lint_kind)}22`,},id: 'harper-highlight',+ attributes: {+ 'data-problem-text': box.lint.problem_text,+ },},[],);diff --git a/packages/lint-framework/src/lint/PopupHandler.ts b/packages/lint-framework/src/lint/PopupHandler.tsindex 61573aa18..e25a33d22 100644--- a/packages/lint-framework/src/lint/PopupHandler.ts+++ b/packages/lint-framework/src/lint/PopupHandler.ts@@ -219,13 +219,11 @@ export default class PopupHandler {.slice(0, this.popupLint).filter((box) =>- box.lint.context_hash === previous.lint.context_hash &&box.source === previous.source &&box.lint.span.start === previous.lint.span.start &&box.lint.span.end === previous.lint.span.end,).length;const matches = boxes.flatMap((box, index) =>- box.lint.context_hash === previous.lint.context_hash &&box.source === previous.source &&box.lint.span.start === previous.lint.span.start &&box.lint.span.end === previous.lint.span.end &&