ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

What actions should trigger `TextWatcher`?

Open scofalik opened this issue 3 years ago • 0 comments

📝 Provide a description of the improvement

Originally reported in: https://github.com/ckeditor/ckeditor5/pull/12460#issuecomment-1245308472.

When working on above PR, we started discussion about how TextWatcher should work in the context of auto-formatting and mentions. More precisely, whether TextWatcher should trigger on backspace or only typing and what are TextWatcher uses.

Below are original posts:


I wonder if TextWatcher should fire an event on text deletion. IDK if there are cases where this could be useful/is already used. In general, if you are deleting stuff, you must have added it earlier, which means that the TextWatcher already had a chance to act. Unless you pasted some text (e.g. you pasted lorem http://foo.pl ipsum). But in this case, AFAIK, we don't want TextWatcher to autolink after removing ipsum right? So, maybe we should also change how TextWatcher works?


TextWatcher is also used by mentions. I tested quickly how mentions work e.g. in Slack and when you start with this:

Hello, @reinmarX[]

And press delete, the mention panel will be triggered once "X" is removed.

Our current implementation, from what I quickly tested, works the same way as Slack's. So I consider this correct.

However, there's a chance that TextWatcher should indeed be improved. For instance, if you a content like this in GH Writer:

Text[]
#123
#234
Text

And start to navigate through this content with the up/down arrows, you'll be constantly triggering mentions, blocking the navigation. GH's native editor does not have this shortcoming. But... Slack's has if you have content with unfinished mentions:

Hello, @re[]
Hello, @re

Long story short, I'd be really cautious when changing something, but there's a chance that we should.

There's also a chance that autolink should work differently than mentions.


Having mentions in mind, it seems that it is better to add modifications in auto-formatting features (autoformat, autolink, etc.) if needed. We could also manage this behavior through an option parameter when creating TextWatcher instance (to what it should react: typing, deleting, selection change).

scofalik avatar Sep 15 '22 09:09 scofalik