mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Bug 1837268, update inline spellchecker when text data is modified, a=RyanVM
Using the test for bug 1602526 as the basis for the new test but tweaking it by adding the event listener used in the first testcase of the bug. Original Revision: https://phabricator.services.mozilla.com/D184987 Differential Revision: https://phabricator.services.mozilla.com/D195233
This commit is contained in:
parent
9eb1c78759
commit
fa1c9b453d
@ -4551,6 +4551,24 @@ MOZ_CAN_RUN_SCRIPT_BOUNDARY void HTMLEditor::ContentRemoved(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY void HTMLEditor::CharacterDataChanged(
|
||||||
|
nsIContent* aContent, const CharacterDataChangeInfo& aInfo) {
|
||||||
|
if (!mInlineSpellChecker || !aContent->IsEditable() ||
|
||||||
|
!IsInObservedSubtree(aContent) ||
|
||||||
|
GetTopLevelEditSubAction() != EditSubAction::eNone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIContent* parent = aContent->GetParent();
|
||||||
|
if (!parent || !parent->InclusiveDescendantMayNeedSpellchecking(this)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<nsRange> range = nsRange::Create(aContent);
|
||||||
|
range->SelectNodesInContainer(parent, aContent, aContent);
|
||||||
|
DebugOnly<nsresult> rvIgnored = mInlineSpellChecker->SpellCheckRange(range);
|
||||||
|
}
|
||||||
|
|
||||||
nsresult HTMLEditor::SelectEntireDocument() {
|
nsresult HTMLEditor::SelectEntireDocument() {
|
||||||
MOZ_ASSERT(IsEditActionDataAvailable());
|
MOZ_ASSERT(IsEditActionDataAvailable());
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@ class HTMLEditor final : public EditorBase,
|
|||||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
||||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
||||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
||||||
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
|
||||||
|
|
||||||
// nsIHTMLEditor methods
|
// nsIHTMLEditor methods
|
||||||
NS_DECL_NSIHTMLEDITOR
|
NS_DECL_NSIHTMLEDITOR
|
||||||
|
@ -40,6 +40,7 @@ skip-if = true
|
|||||||
[test_bug1602526.html]
|
[test_bug1602526.html]
|
||||||
[test_bug1761273.html]
|
[test_bug1761273.html]
|
||||||
[test_bug1773802.html]
|
[test_bug1773802.html]
|
||||||
|
[test_bug1837268.html]
|
||||||
[test_bug366682.html]
|
[test_bug366682.html]
|
||||||
[test_bug432225.html]
|
[test_bug432225.html]
|
||||||
[test_bug484181.html]
|
[test_bug484181.html]
|
||||||
|
79
editor/spellchecker/tests/test_bug1837268.html
Normal file
79
editor/spellchecker/tests/test_bug1837268.html
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Mozilla bug 1837268</title>
|
||||||
|
<link rel=stylesheet href="/tests/SimpleTest/test.css">
|
||||||
|
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
||||||
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script src="/tests/editor/spellchecker/tests/spellcheck.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1837268">Mozilla Bug 1837268</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none;">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="contenteditable" contenteditable=true>aabbcc</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const { maybeOnSpellCheck } = SpecialPowers.ChromeUtils.importESModule(
|
||||||
|
"resource://testing-common/AsyncSpellCheckTestHelper.sys.mjs"
|
||||||
|
);
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
|
||||||
|
function getEditor() {
|
||||||
|
return SpecialPowers.wrap(window).docShell.editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
SimpleTest.waitForFocus(async () => {
|
||||||
|
let contenteditable = document.getElementById("contenteditable");
|
||||||
|
contenteditable.addEventListener("beforeinput", (ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
let text = contenteditable.textContent;
|
||||||
|
const sel = window.getSelection();
|
||||||
|
let offset = sel.anchorOffset;
|
||||||
|
switch (ev.inputType) {
|
||||||
|
case "insertText":
|
||||||
|
text = text.substring(0, offset) + ev.data + text.substring(offset);
|
||||||
|
offset += 1;
|
||||||
|
break;
|
||||||
|
case "deleteContentBackward":
|
||||||
|
text = text.substring(0, offset - 1) + text.substring(offset);
|
||||||
|
offset -= 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (contenteditable.firstChild) {
|
||||||
|
contenteditable.firstChild.nodeValue = text;
|
||||||
|
} else {
|
||||||
|
contenteditable.textContent = text;
|
||||||
|
}
|
||||||
|
sel.collapse(contenteditable.firstChild ?? contenteditable, offset);
|
||||||
|
});
|
||||||
|
|
||||||
|
let misspelledWords = [];
|
||||||
|
misspelledWords.push("aabbc"); // One c removed.
|
||||||
|
|
||||||
|
contenteditable.focus();
|
||||||
|
window.getSelection().collapse(contenteditable.firstChild, contenteditable.firstChild.length);
|
||||||
|
|
||||||
|
// Run spell checker
|
||||||
|
await new Promise((resolve) => { maybeOnSpellCheck(contenteditable, resolve); });
|
||||||
|
|
||||||
|
synthesizeKey("KEY_Backspace");
|
||||||
|
synthesizeKey(" ");
|
||||||
|
|
||||||
|
await new Promise((resolve) => { maybeOnSpellCheck(contenteditable, resolve); });
|
||||||
|
let editor = getEditor();
|
||||||
|
// isSpellingCheckOk is defined in spellcheck.js
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
ok(isSpellingCheckOk(editor, misspelledWords), "correct word is selected as misspelled");
|
||||||
|
|
||||||
|
SimpleTest.finish();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user