Commit 6869f052 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Polish idle time spell checker's typing progress checking algorithm

This patch makes idle time spell checker consider the possibility of
typing in a partial word even with closed typing command, so that
we won't be marking partial words due to JS closing typing command
in the middle of typing.

Bug: 749934
Change-Id: I426392adf69c30803a5c6de475680c2c9d55cfc5
Reviewed-on: https://chromium-review.googlesource.com/592789
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491959}
parent f6ca6cc7
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script src="spellcheck_test.js"></script>
<script>
// Regression test for crbug.com/749934
spellcheck_test(
'<div contenteditable>|</div>',
document => {
const div = document.querySelector('div');
const selection = document.getSelection();
document.execCommand('insertText', false, 'zz');
selection.collapse(div.firstChild, 2); // Closes typing
},
'<div contenteditable>zz</div>',
'Do not check partial word even if the last typing command is closed');
</script>
...@@ -44,11 +44,12 @@ EphemeralRange CurrentWordIfTypingInPartialWord(const Element& editable) { ...@@ -44,11 +44,12 @@ EphemeralRange CurrentWordIfTypingInPartialWord(const Element& editable) {
if (RootEditableElementOf(selection.Base()) != &editable) if (RootEditableElementOf(selection.Base()) != &editable)
return EphemeralRange(); return EphemeralRange();
CompositeEditCommand* typing_command = CompositeEditCommand* last_command = frame.GetEditor().LastEditCommand();
frame.GetEditor().LastTypingCommandIfStillOpenForTyping(); if (!last_command || !last_command->IsTypingCommand())
if (!typing_command)
return EphemeralRange(); return EphemeralRange();
if (typing_command->EndingVisibleSelection().AsSelection() != selection) if (!last_command->EndingSelection().IsValidFor(*frame.GetDocument()))
return EphemeralRange();
if (last_command->EndingSelection().AsSelection() != selection)
return EphemeralRange(); return EphemeralRange();
return AdjacentWordIfExists(selection.Base()); return AdjacentWordIfExists(selection.Base());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment