Commit 673dd7ce authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make CorrectedSelectionAfterCommand() to check Position offset

This patch changes |CorrectedSelectionAfterCommand()| to use |Position::
IsValidFor()| to make it to check |Position| offset and return valid
selection.

Bug: 873037
Change-Id: I70c7d6f514a39414a4c3245b59969d19beb13f45
Reviewed-on: https://chromium-review.googlesource.com/1170458Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582090}
parent 021565ba
......@@ -615,11 +615,8 @@ void DispatchInputEventEditableContentChanged(
SelectionInDOMTree CorrectedSelectionAfterCommand(
const SelectionForUndoStep& passed_selection,
const Document* document) {
if (!passed_selection.Base().IsConnected() ||
!passed_selection.Extent().IsConnected() ||
passed_selection.Base().GetDocument() != document ||
passed_selection.Base().GetDocument() !=
passed_selection.Extent().GetDocument())
if (!passed_selection.Base().IsValidFor(*document) ||
!passed_selection.Extent().IsValidFor(*document))
return SelectionInDOMTree();
return passed_selection.AsSelection();
}
......
......@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/clipboard/system_clipboard.h"
#include "third_party/blink/renderer/core/dom/text.h"
#include "third_party/blink/renderer/core/editing/commands/editor_command.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
......@@ -106,4 +107,19 @@ TEST_F(EditorTest, ReplaceSelection) {
EXPECT_EQ("HENEWLLO", text_control.value());
}
// http://crbug.com/873037
TEST_F(EditorTest, UndoWithInvalidSelection) {
const SelectionInDOMTree selection = SetSelectionTextToBody(
"<div contenteditable><div></div><b>^abc|</b></div>");
Selection().SetSelection(selection, SetSelectionOptions());
Text& abc = ToText(*selection.Base().ComputeContainerNode());
// Push Text node "abc" into undo stack
GetDocument().execCommand("italic", false, "", ASSERT_NO_EXCEPTION);
// Change Text node "abc" in undo stack
abc.setData("");
GetDocument().GetFrame()->GetEditor().Undo();
EXPECT_EQ("<div contenteditable><div></div><b>|</b></div>",
GetSelectionTextFromBody());
}
} // namespace blink
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