Skip to content

Commit

Permalink
Move the caret by paragraph granularity should cross editing boundary
Browse files Browse the repository at this point in the history
Consider this test case:
<div contenteditable>
  <p id="one">P1</p>
  <p id="two">
    Paragraph 1: Hello World Test\n
    Paragraph 2: <span contenteditable="false">Hello</span> World|
  </p>
</div>
The expected behavior of
`selection.modify('move', 'backward', 'paragraph')` is to
move the caret to the end of p#one. But due to the presence of
the non-editable node, the behavior looks like "line" granularity.

`Next/PreviousParagraphPosition` calls
`Next/PreviousLinePosition` to get the specified position until
it is no longer in the same paragraph. But `InSameParagraph`
does not allow cross `EditingBoundary`, so when there is
a non-editable node, the behavior is similar to the line.

Firefox doesn't implement paragraph, so a tentative test is added.

Bug: 326554272
Change-Id: I68115cebe3bc3845a3dfe29ef56c6a5c8f1f9969
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5319076
Reviewed-by: Koji Ishii <kojii@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Peng Zhou <zhoupeng.1996@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#1317952}
  • Loading branch information
zhoupeng authored and chromium-wpt-export-bot committed Jun 21, 2024
1 parent e4bd6a4 commit 6560580
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions selection/move-paragraph-cross-editing-boundary.tentative.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<meta charset="utf-8">
<link rel="author" title="Peng Zhou" href="mailto:zhoupeng.1996@bytedance.com">
<link rel="help" href="https://github.com/w3c/selection-api/issues/173">
<link rel="help" href="https://issues.chromium.org/issues/326554272">
<title>Selection.modify(): move by paragraph cross editing boundary</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div contenteditable style="width: 140px; font-size: 14px;">
<p>P1</p>
<p>
Line 1: Hello World
Line 2: <span contenteditable="false">Hello</span> <span id="end">World</span>
</p>
</div>
<script>
const selection = getSelection();
const end = document.querySelector('#end');
function runTest() {
selection.collapse(end.childNodes[0], 5);
selection.modify('move', 'backward', 'paragraph');
assert_equals(selection.anchorNode.nodeValue, 'P1');
assert_equals(selection.anchorOffset, 2);
}

test(() => {
runTest();
}, 'cross editing boundary');

test(() => {
const editable = document.querySelector('span[contenteditable=false]');
editable.setAttribute('contenteditable', true);
runTest();
}, 'not cross editing boundary');
</script>

0 comments on commit 6560580

Please sign in to comment.