Commit 1e0e9ebf authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Don't move out of editing host when adjusting caret move result for editing boundaries

https://codereview.chromium.org/2250133004 introduced a regression that
editing boundary adjustment may move the result position out of the
editing host. This patch fixes it.

Bug: 936613
Change-Id: If07d33df991635291672370fe8a89fc3a35520da
Reviewed-on: https://chromium-review.googlesource.com/c/1493391Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636487}
parent ea4d913a
...@@ -680,8 +680,16 @@ PositionTemplate<Strategy> FirstEditablePositionAfterPositionInRootAlgorithm( ...@@ -680,8 +680,16 @@ PositionTemplate<Strategy> FirstEditablePositionAfterPositionInRootAlgorithm(
// sibling position. If not, we can't get the next paragraph in // sibling position. If not, we can't get the next paragraph in
// InsertListCommand::doApply's while loop. See http://crbug.com/571420 // InsertListCommand::doApply's while loop. See http://crbug.com/571420
if (non_editable_node && if (non_editable_node &&
non_editable_node->IsDescendantOf(editable_position.AnchorNode())) non_editable_node->IsDescendantOf(editable_position.AnchorNode())) {
editable_position = NextVisuallyDistinctCandidate(editable_position); // Make sure not to move out of |highest_root|
const PositionTemplate<Strategy> boundary =
PositionTemplate<Strategy>::LastPositionInNode(highest_root);
const PositionTemplate<Strategy> next_candidate =
NextVisuallyDistinctCandidate(editable_position);
editable_position = next_candidate.IsNotNull()
? std::min(boundary, next_candidate)
: boundary;
}
return editable_position; return editable_position;
} }
......
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
// Regression tests for crbug.com/936613
selection_test(
[
'<div contenteditable>',
'|<span contenteditable="false">line 1</span>',
'</div>'
].join(''),
selection => selection.modify('move', 'right', 'character'),
[
'<div contenteditable>',
'<span contenteditable="false">line 1</span>|',
'</div>'
].join(''),
'Move right over ineditable inline');
selection_test(
[
'<div contenteditable>',
'|<span contenteditable="false">line 1</span>',
'</div>',
'some more content'
].join(''),
selection => selection.modify('move', 'right', 'character'),
[
'<div contenteditable>',
'<span contenteditable="false">line 1</span>|',
'</div>',
'some more content'
].join(''),
'Move right over ineditable inline ignoring content outside editing host');
selection_test(
[
'<div contenteditable>',
'|<span contenteditable="false">line 1</span><br>',
'line 2',
'</div>',
].join(''),
selection => selection.modify('move', 'right', 'character'),
[
'<div contenteditable>',
'<span contenteditable="false">line 1</span>|<br>',
'line 2',
'</div>',
].join(''),
'Move right over ineditable inline with another editable line');
selection_test(
[
'<div contenteditable>',
'|<span contenteditable="false">line 1</span>',
'<div>line 2</div>',
'</div>',
].join(''),
selection => selection.modify('move', 'right', 'character'),
[
'<div contenteditable>',
// TODO(editing-dev): "</span>|" seems to be a better result. The
// current behavior might be an artifact of crrev.com/412925.
'<span contenteditable="false">line 1</span>',
'<div>|line 2</div>',
'</div>'
].join(''),
'Move right over ineditable inline with another editable block');
</script>
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