w3c / selection-api

Selection API
http://w3c.github.io/selection-api/
Other
47 stars 29 forks source link

Clarify how `selection.modify()` when the granularity parameter is `paragraphboundary` handles non-editable elements in an editing host #179

Open zp1996 opened 3 months ago

zp1996 commented 3 months ago

The specification doesn't define the behavior of seleciton.modify() when the granularity parameter is paragraphboundary.

Consider this test case

<div contenteditable id="container">
  this <a contenteditable="false">link</a> after
</div>

<p>1. Make the selection like "this link after|".</p>
<p>2. Click button to move the caret by line.</p>

<button>Move</button>

<script>
document.querySelector('button').addEventListener('click', (event) => {
  document.getElementById('container').focus();
  const selection = window.getSelection();
  selection.modify('move', 'backward', 'paragraphboundary');
});
</script>

The behavior of browsers:

If we make a to be editable, the behavior of browsers:

The behavior of selection.modify() when the granularity parameter is paragraphboundary should be be consistent, whether a is editable or not.

zp1996 commented 3 months ago

We believe the new behavior is correct, therefore we will implement it in Chromium and will add a tentative test.