From 18be0943b3d8f0ba4138207a8ae59e81173f2ce9 Mon Sep 17 00:00:00 2001 From: Yuvraj P Date: Fri, 17 Jul 2026 22:02:35 -0400 Subject: [PATCH 1/3] fixed the suggestions replace function --- packages/lint-framework/src/lint/Box.ts | 2 +- .../lint-framework/src/lint/SuggestionBox.ts | 6 ++-- .../computeLintBoxes/googleDocsUtilities.ts | 34 ++++++++++--------- .../src/lint/googleDocsAdapter.ts | 4 +-- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/packages/lint-framework/src/lint/Box.ts b/packages/lint-framework/src/lint/Box.ts index 057f21ec38..abbfe3d5db 100644 --- a/packages/lint-framework/src/lint/Box.ts +++ b/packages/lint-framework/src/lint/Box.ts @@ -17,7 +17,7 @@ export type LintBox = Box & { source: SourceElement; /** Optionally provided to improve highlight rendering performance. */ range?: Range; - applySuggestion: (sug: UnpackedSuggestion) => void; + applySuggestion: (sug: UnpackedSuggestion) => void | Promise; }; export type IgnorableLintBox = LintBox & { diff --git a/packages/lint-framework/src/lint/SuggestionBox.ts b/packages/lint-framework/src/lint/SuggestionBox.ts index 990cba36e3..65768040e1 100644 --- a/packages/lint-framework/src/lint/SuggestionBox.ts +++ b/packages/lint-framework/src/lint/SuggestionBox.ts @@ -193,6 +193,7 @@ function button( className: 'harper-btn', style: extraStyle, onclick: onClick, + onmousedown: (e: Event) => e.preventDefault(), title: desc, type: 'button', 'aria-label': desc, @@ -546,8 +547,9 @@ export default function SuggestionBox( body(box.lint.message_html), footer( suggestions(box.lint.lint_kind, box.lint.suggestions, (v) => { - box.applySuggestion(v); - close(); + Promise.resolve(box.applySuggestion(v)).finally(() => { + close(); + }); }), [ box.lint.lint_kind === 'Spelling' && actions.addToUserDictionary diff --git a/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts b/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts index 427b37d442..cfb402addb 100644 --- a/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts +++ b/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts @@ -302,11 +302,11 @@ function getGoogleDocsPositionedLeafHost(child: Node, target: HTMLElement): HTML * The payload includes nearby context so the bridge can recover when the original * offsets have gone stale by the time the suggestion is applied. */ -export function replaceGoogleDocsValue( +export async function replaceGoogleDocsValue( span: { start: number; end: number }, replacementText: string, source: string, -) { +): Promise { try { const safeStart = Math.max(0, Math.min(span.start, source.length)); const safeEnd = Math.max(safeStart, Math.min(span.end, source.length)); @@ -323,23 +323,25 @@ export function replaceGoogleDocsValue( beforeContext, afterContext, }; - // This looks awkward because lint-framework cannot import chrome-plugin code directly. - // The content script puts the bridge client on window so this shared package can call it. + const bridgeClient = (window as WindowWithGoogleDocsBridgeClient) .__harperGoogleDocsBridgeClient; if (bridgeClient && typeof bridgeClient.replaceText === 'function') { - void Promise.resolve( - bridgeClient.replaceText( - payload.start, - payload.end, - payload.replacementText, - payload.expectedText, - payload.beforeContext, - payload.afterContext, - ), + const applied = await bridgeClient.replaceText( + payload.start, + payload.end, + payload.replacementText, + payload.expectedText, + payload.beforeContext, + payload.afterContext, ); + return Boolean(applied); } - } catch { - // Ignore bridge dispatch failures. + + return false; + } catch (e) { + // Yeah never ignore silent failures bruh + console.error('[harper] replaceGoogleDocsValue failed:', e); + return false; } -} +} \ No newline at end of file diff --git a/packages/lint-framework/src/lint/googleDocsAdapter.ts b/packages/lint-framework/src/lint/googleDocsAdapter.ts index 4fc31c8dcc..858943baa4 100644 --- a/packages/lint-framework/src/lint/googleDocsAdapter.ts +++ b/packages/lint-framework/src/lint/googleDocsAdapter.ts @@ -58,9 +58,9 @@ export function maybeComputeGoogleDocsLintBoxes( lint, source: editor, rule, - applySuggestion: (suggestion: UnpackedSuggestion) => { + applySuggestion: async (suggestion: UnpackedSuggestion) => { const replacementText = suggestionToReplacementText(suggestion, resolvedSpan, source); - replaceGoogleDocsValue(resolvedSpan, replacementText, source); + await replaceGoogleDocsValue(resolvedSpan, replacementText, source); }, ignoreLint: opts.ignoreLint ? () => opts.ignoreLint!(lint.context_hash) : undefined, }); From 3d9ab0aca5ea3a66c6b674d95f77071bdfb29753 Mon Sep 17 00:00:00 2001 From: Yuvraj P Date: Fri, 17 Jul 2026 22:52:38 -0400 Subject: [PATCH 2/3] removed debug and silly comments --- .../src/lint/computeLintBoxes/googleDocsUtilities.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts b/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts index cfb402addb..c427723fe2 100644 --- a/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts +++ b/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts @@ -340,8 +340,6 @@ export async function replaceGoogleDocsValue( return false; } catch (e) { - // Yeah never ignore silent failures bruh - console.error('[harper] replaceGoogleDocsValue failed:', e); return false; } } \ No newline at end of file From 600700dbfc6bcc70dcda4a0f6c68a54f12715372 Mon Sep 17 00:00:00 2001 From: Yuvraj P Date: Fri, 17 Jul 2026 23:13:08 -0400 Subject: [PATCH 3/3] peak ragebait ngl formatting fix --- .../src/lint/computeLintBoxes/googleDocsUtilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts b/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts index c427723fe2..4269a60730 100644 --- a/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts +++ b/packages/lint-framework/src/lint/computeLintBoxes/googleDocsUtilities.ts @@ -342,4 +342,4 @@ export async function replaceGoogleDocsValue( } catch (e) { return false; } -} \ No newline at end of file +}