Re: [selection-api] caret-based selection movement (#27)

Here is a possible algorithm for move caret. It relies on carets only being allowed in visible text nodes.
1) For directional caret movement (arrow key, etc), determine the next position in the given direction in the current text node if it exists. If it doesn't exist, use the closest position in the closest text node in the given direction. Call this position "proposedPosition".
2) For non-directional caret movement (click, etc), determine the closest position in the closest visible text node to the location of the click with left-gravity, on the closest line to the location of the click. Call this position "proposedPosition".
3) Fire beforeSelectionChange, indicating prosposedPosition and the source event (click, keyboard, etc) in the beforeSelectionChange event. If script does not like the proposedLocation, it can create a text node and place the selection where it wants, and call preventDefault.
4) If preventDefault is not called, move the caret to proposedLocation.

For <p>Hello <i>Austri|a</i></p>, this means moving right would still be italic. Moving left past the "A" would still be italic. Moving left again to the 'o' and moving right from there would not be italic. Clicking left of the 'A' would not be italic and clicking right of the 'a' would be italic (left-gravity).

For abc|<span style="display:none">invisible</span>def, moving right would be after the d, moving left from there would be at abc<span style="display:none">invisible</span>|def

---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/selection-api/issues/27#issuecomment-66354762

Received on Tuesday, 9 December 2014 20:48:28 UTC