Quill: Selection direction support

Created on 3 Aug 2017  路  9Comments  路  Source: quilljs/quill

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.

feature

Most helpful comment

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.

All 9 comments

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.

  1. I have to use MDN - Selection.extend that doesn't works for IE. Looks like it's the only way to set reversed selection.
  2. When I set/get selection I check if it's reversed. So I create a range as usual and then check if it has been collapsed (by browser). Don't know if there is better solution.
  3. There is various methods like 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?

Was this page helpful?
0 / 5 - 0 ratings