Reason for invalidating caret before undo?

37 views
Skip to first unread message

Mitchell

unread,
Oct 22, 2023, 11:02:38 AM10/22/23
to scintilla...@googlegroups.com
Hi Neil,

Is there a reason for invalidating the caret before performing undo, and
then setting an empty selection after successful undo? If you have
multiple selections active and you are typing into all of them at once,
but perform undo, you lose those multiple selections. It would be really
helpful to leave them be. I commented out "InvalidateCaret()" and
"SetEmptySelection(newPos)" from Editor::Undo() and I'm not getting any
weird behavior with some basic tests.

I also changed Editor::Redo() to increment each selection range's anchor
and caret based on the difference between "SelectionStart().Position()"
and "newPos", and basic testing shows expected behavior -- my multiple
carets move to their prior positions before undo-redo.

We can probably keep old behavior if "sel.Count() == 1", but for the
case where it's greater than one, perhaps we can change it? I can
prepare a patch for your consideration if you think it's worth it.

Cheers,
Mitchell

Neil Hodgson

unread,
Oct 22, 2023, 5:01:37 PM10/22/23
to scintilla-interest
Mitchell:

Is there a reason for invalidating the caret before performing undo,

Both the current and new caret positions(s) are redrawn as the caret will (likely) disappear from the current position and appear at the new position.

Your later statements inferr that caret invalidation affects more than it does.

and then setting an empty selection after successful undo?

Undo does not restore selections so a reasonable default is applied.
 
If you have
multiple selections active and you are typing into all of them at once,
but perform undo, you lose those multiple selections. It would be really
helpful to leave them be.

That may lead to situations with unexpected (and potentially off-screen) selections and thus extra unintended copies of added text.

Neil

Mitchell

unread,
Oct 23, 2023, 9:09:53 AM10/23/23
to scintilla...@googlegroups.com
Hi Neil,
I see. Thanks for the insight.

Cheers,
Mitchell

Neil Hodgson

unread,
Oct 24, 2023, 5:45:15 PM10/24/23
to scintilla-interest
Mitchell:

I see. Thanks for the insight.

   After much bug fixing, I tend to examine changes from the point of view of 'what can go wrong'. It may be interesting to experiment with retaining multiple selections through undo but remembering selections would be more accurate. There may eventually be an option to remember selections but each added feature can make other features more difficult to implement. There are other additions to undo that I think are more important.

   Neil

Reply all
Reply to author
Forward
0 new messages