Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(chrome-ext): ProseMirror problems in ChatGPT (#1459)

Elijah Potter1efb57b53bc3
diff --git a/packages/chrome-plugin/src/Highlights.ts b/packages/chrome-plugin/src/Highlights.ts
index 696a5643e..851ec1b42 100644
--- a/packages/chrome-plugin/src/Highlights.ts
+++ b/packages/chrome-plugin/src/Highlights.ts
@@ -6,10 +6,12 @@ import patch from 'virtual-dom/patch';
import { type LintBox, isBoxInScreen } from './Box';
import RenderBox from './RenderBox';
import {
+ getCMRoot,
getLexicalRoot,
getMediumRoot,
getNotionRoot,
getP2Root,
+ getPMRoot,
getQuillJsRoot,
getShredditComposerRoot,
getSlateRoot,
@@ -127,6 +129,8 @@ export default class Highlights {
}
const queries = [
+ getPMRoot,
+ getCMRoot,
getNotionRoot,
getSlateRoot,
getMediumRoot,
diff --git a/packages/chrome-plugin/src/background/index.ts b/packages/chrome-plugin/src/background/index.ts
index a851489a5..bd9d6bad9 100644
--- a/packages/chrome-plugin/src/background/index.ts
+++ b/packages/chrome-plugin/src/background/index.ts
@@ -77,6 +77,7 @@ async function enableDefaultDomains() {
'www.slatejs.org',
'localhost',
'writewithharper.com',
+ 'prosemirror.net',
];
for (const item of defaultEnabledDomains) {
diff --git a/packages/chrome-plugin/src/contentScript/index.ts b/packages/chrome-plugin/src/contentScript/index.ts
index ec680816a..b5978cc4d 100644
--- a/packages/chrome-plugin/src/contentScript/index.ts
+++ b/packages/chrome-plugin/src/contentScript/index.ts
@@ -19,6 +19,10 @@ function scan() {
});
$('[contenteditable="true"],[contenteditable]').each(function () {
+ if (this.spellcheck == false) {
+ return;
+ }
+
const leafs = leafNodes(this);
for (const leaf of leafs) {
diff --git a/packages/chrome-plugin/src/editorUtils.ts b/packages/chrome-plugin/src/editorUtils.ts
index 00534779a..a7fb63c1e 100644
--- a/packages/chrome-plugin/src/editorUtils.ts
+++ b/packages/chrome-plugin/src/editorUtils.ts
@@ -68,3 +68,15 @@ export function getMediumRoot(el: HTMLElement): HTMLElement | null {
export function getNotionRoot(el: HTMLElement): HTMLElement | null {
return document.getElementById('notion-app');
}
+
+/** Determines if a given node is a child of a CodeMirror editor instance.
+ * If so, returns the root node of that instance. */
+export function getCMRoot(el: HTMLElement): HTMLElement | null {
+ return findAncestor(el, (node: HTMLElement) => node.classList.contains('cm-editor'));
+}
+
+/** Determines if a given node is a child of a ProseMirror editor instance.
+ * If so, returns the root node of that instance. */
+export function getPMRoot(el: HTMLElement): HTMLElement | null {
+ return findAncestor(el, (node: HTMLElement) => node.classList.contains('ProseMirror'));
+}
diff --git a/packages/chrome-plugin/tests/prosemirror.spec.ts b/packages/chrome-plugin/tests/prosemirror.spec.ts
new file mode 100644
index 000000000..775a078e3
--- /dev/null
+++ b/packages/chrome-plugin/tests/prosemirror.spec.ts
@@ -0,0 +1,42 @@
+import { expect, test } from './fixtures';
+import { clickHarperHighlight, getProseMirrorEditor, replaceEditorContent } from './testUtils';
+
+const TEST_PAGE_URL = 'https://prosemirror.net/';
+
+test('Can apply basic suggestion.', async ({ page }) => {
+ await page.goto(TEST_PAGE_URL);
+
+ const pm = getProseMirrorEditor(page);
+ await replaceEditorContent(pm, 'This is an test');
+
+ await page.waitForTimeout(3000);
+
+ await clickHarperHighlight(page);
+ await page.getByTitle('Replace with "a"').click();
+
+ await page.waitForTimeout(3000);
+
+ await expect(pm).toContainText('This is a test');
+ await pm.press('Control+ArrowDown');
+
+ await pm.pressSequentially(' of Harper’s grammar checking.');
+ await expect(pm).toContainText('This is a test of Harper’s grammar checking.');
+});
+
+test('Can ignore suggestion.', async ({ page }) => {
+ await page.goto(TEST_PAGE_URL);
+ const pm = getProseMirrorEditor(page);
+
+ await replaceEditorContent(pm, 'This is an test.');
+
+ await page.waitForTimeout(3000);
+
+ await clickHarperHighlight(page);
+ await page.getByTitle('Ignore this lint').click();
+
+ await page.waitForTimeout(3000);
+
+ // Nothing should change.
+ expect(pm).toContainText('This is an test');
+ expect(await clickHarperHighlight(page)).toBe(false);
+});
diff --git a/packages/chrome-plugin/tests/testUtils.ts b/packages/chrome-plugin/tests/testUtils.ts
index 0c6c33674..9d4c8e585 100644
--- a/packages/chrome-plugin/tests/testUtils.ts
+++ b/packages/chrome-plugin/tests/testUtils.ts
@@ -10,6 +10,11 @@ export function getLexicalEditor(page: Page): Locator {
return page.locator('[data-lexical-editor="true"]');
}
+/** Locate the ProseMirror editor on the page. */
+export function getProseMirrorEditor(page: Page): Locator {
+ return page.locator('.ProseMirror');
+}
+
/** Replace the content of a text editor. */
export async function replaceEditorContent(editorEl: Locator, text: string) {
await editorEl.selectText();