S009: spell menu finds the misspelled word in text fields (no caretRangeFromPoint in Servo); spell smoke test
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
eb494ff332
commit
fadad79ab6
1 changed files with 57 additions and 4 deletions
|
|
@ -119,6 +119,10 @@ const BRIDGE_JS: &str = r#"if (window.__nacre) return;
|
|||
if (r && r.startContainer.nodeType === 3) { const s = r.startContainer.data, i = r.startOffset;
|
||||
const m = /[\p{L}'’-]*$/u.exec(s.slice(0, i))[0] + /^[\p{L}'’-]*/u.exec(s.slice(i))[0]; word = m; } } catch (e) {}
|
||||
const field = t && t.closest && t.closest('input,textarea,[contenteditable=""],[contenteditable=true]');
|
||||
// Servo has no caretRangeFromPoint, and text fields have no text node anyway: the spell check's mirror
|
||||
// underlines the misspelled words, so the one under the pointer is the one clicked.
|
||||
if (!word && field) for (const u of document.querySelectorAll('.__nacre_spell_mirror u'))
|
||||
for (const r of u.getClientRects()) if (e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom) word = u.textContent;
|
||||
__send('context', { selection: sel.slice(0, 2000), word, editable: !!field,
|
||||
media: media ? { src: media.currentSrc || media.src || '', kind: media.tagName.toLowerCase() } : null,
|
||||
x: e.clientX, y: e.clientY });
|
||||
|
|
|
|||
Loading…
Reference in a new issue