Skip to content

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

fix(chrome-ext): properly position highlights in Ghost editor DOM (#1691)

Elijah Potterb1dfb9197479
diff --git a/packages/chrome-plugin/src/Highlights.ts b/packages/chrome-plugin/src/Highlights.ts
index 340e23b42..0031c04e4 100644
--- a/packages/chrome-plugin/src/Highlights.ts
+++ b/packages/chrome-plugin/src/Highlights.ts
@@ -4,6 +4,7 @@ import type { LintBox } from './Box';
import {
getCMRoot,
getDraftRoot,
+ getGhostRoot,
getGutenbergRoot,
getLexicalRoot,
getMediumRoot,
@@ -141,6 +142,7 @@ export default class Highlights {
}
const queries = [
+ getGhostRoot,
getDraftRoot,
getPMRoot,
getCMRoot,
diff --git a/packages/chrome-plugin/src/editorUtils.ts b/packages/chrome-plugin/src/editorUtils.ts
index 43f9342f0..e61e03862 100644
--- a/packages/chrome-plugin/src/editorUtils.ts
+++ b/packages/chrome-plugin/src/editorUtils.ts
@@ -70,6 +70,12 @@ export function getLexicalEditable(el: HTMLElement): HTMLElement | null {
return findChild(lexical, (node: HTMLElement) => node.getAttribute('contenteditable') == 'true');
}
+/** Determines if a given node is a child of a Ghost editor instance.
+ * If so, returns the root node of that instance. */
+export function getGhostRoot(el: HTMLElement): HTMLElement | null {
+ return findAncestor(el, (node: HTMLElement) => node.classList.contains('gh-editor'));
+}
+
/** Determines if a given node is a child of a Slate.js editor instance.
* If so, returns the root node of that instance. */
export function getSlateRoot(el: HTMLElement): HTMLElement | null {