Nothing Special   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
Fix test and handle mousemove.
Browse files Browse the repository at this point in the history
  • Loading branch information
sanketj committed Jul 26, 2024
1 parent 3c09913 commit f73b2dd
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions spellcheck-custom-highlight-sample-with-highlightsFromPoint.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,7 @@
let grammarHighlight = new Highlight(...grammarRanges);
CSS.highlights.set('grammar-highlight', grammarHighlight);

// function createActiveHighlight(caretPosition) {
// for (spellingRange of spellingRanges) {
// if (spellingRange.startOffset <= caretPosition.startOffset && caretPosition.endOffset <= spellingRange.endOffset) {
// CSS.highlights.delete('active-spellcheck-highlight');
// CSS.highlights.delete('active-grammar-highlight');
// let activeSpellingHighlight = new Highlight(spellingRange);
// CSS.highlights.set('active-spellcheck-highlight', activeSpellingHighlight);
// break;
// }
// }
// for (grammarRange of grammarRanges) {
// if (grammarRange.startOffset <= caretPosition.startOffset && caretPosition.endOffset <= grammarRange.endOffset) {
// CSS.highlights.delete('active-spellcheck-highlight');
// CSS.highlights.delete('active-grammar-highlight');
// let activeGrammarHighlight = new Highlight(grammarRange);
// CSS.highlights.set('active-grammar-highlight', activeGrammarHighlight);
// break;
// }
// }
// }

div.addEventListener('mouseover', (event) => {
listenForMouseMove = true;
// let caretPosition = document.caretRangeFromPoint(event.clientX, event.clientY);
// createActiveHighlight(caretPosition);
let highlights = CSS.highlights.highlightsFromPoint(event.clientX, event.clientY);
function createActiveHighlights(highlights) {
for (highlight of highlights) {
if (highlight.name === 'spellcheck-highlight') {
CSS.highlights.delete('active-spellcheck-highlight');
Expand All @@ -95,12 +70,18 @@
CSS.highlights.set('active-grammar-highlight', activeGrammarHighlight);
}
}
}

div.addEventListener('mouseover', (event) => {
listenForMouseMove = true;
let highlights = CSS.highlights.highlightsFromPoint(event.clientX, event.clientY);
createActiveHighlights(highlights);
});

div.addEventListener('mousemove', (event) => {
if (listenForMouseMove) {
// let caretPosition = document.caretRangeFromPoint(event.clientX, event.clientY);
// createActiveHighlight(caretPosition);
let highlights = CSS.highlights.highlightsFromPoint(event.clientX, event.clientY);
createActiveHighlights(highlights);
}
});

Expand Down

0 comments on commit f73b2dd

Please sign in to comment.