When you select some text with mouse d&d or Shift + Arrows selection has a certain direction. So when you press Shift + Arrows selection will extend/collapse in a different way depending on direction (hope I describe it good enough to understand).
The problem is I can't define the direction with setSelction(). For example:
1) I have text with mention blot inside.
2) I have special keyboard handlers to disallow partial selection of mention.
3) Each time handler calls setSelection() selection lose it's direction and I can't fix it with quill.
As I understood creating a new range with start at anchor + Selection.extend() is a real way to do define direction. I suggest something like setSelection(10, -4) would be nice and clean. We just have to modify setSelection() to support negative length values.
Don't know if it will course any other problems and conflicts.
I'll have to scope out the work but if this were added I think it would also have to change getSelection and on('selection-change') to report negative lengths if the range is backwards.
I think what'd I'd like to see is to have getSelection() and related methods return a Selection object that is the same as Range but with the addition of an integer field for the index of the caret.
Tried to play with it in my forked version. I'm able to set and get reversed selection range. But I ran into 3 problems.
getText() and others remains the same and does not support reversed selection.I can make PR as soon as I figure out how to deal with it.
@meantime that makes sense. I tried to implement it like setSelection(10, -4) and it breaks a lot of things in Quill itself and custom code. And it also keeps getText() and other methods and functions valid as is.
Don't know if it's ready for PR. All tests are passing. #1773
Sorry for that, recreated.
@DmitrySkripkin Has there been any progress with this?
Most helpful comment
I think what'd I'd like to see is to have
getSelection()and related methods return aSelectionobject that is the same asRangebut with the addition of an integer field for the index of the caret.