ReplaceStep merge optimization

I am trying Step.merge. It is quite a common case during editing:

  1. input some text, say it is a test
  2. locates the cursor back and modify the text just inputed, resulting in it is another test
  3. select some text just inputed and delete it, resulting in it is test

All those steps are ReplaceStep instances, and I find they are not merged:

"slice":{"content":[{"type":"text","text":"This is a test"}]}},

IMHO, from step 1, it is known that it covers the range from 10 to 24 (from + "This is a test".length). Step 2 just takes place in this range. So they should be mergable, resulting in some new step like {"stepType":"replace","from":10,"to":10,"slice":{"content":[{"type":"text","text":"This is another test"}]}}.

And step 3 should also merge into the new step for the same reason.

This wouldn’t be trivial to implement, and probably not help a lot (I don’t think this specific pattern is as common as you make it out to be).

Well, I want to save document changes by steps. But it grows very quickly. Especially for CJK users, you first input some English letters, and then they are turned into CJK characters, which is the case just like step 2.

Yes, it would not be trivial, there are quite a few cases to deal with in order to be perfect. But I want to try out on the cases I listed.

It would be helpful if you give me some hints on what should be what should be watched out.