micro icon indicating copy to clipboard operation
micro copied to clipboard

adjust selection after `replaceall`

Open matthias314 opened this issue 11 months ago • 2 comments

When doing replaceall, selections are preserved. Currently they are left untouched even if the boundaries have shifted as a result of the replacement. This PR adjusts the beginning or end of a selection according to the number of characters added or deleted in the last line of the selection.

matthias314 avatar Jan 21 '25 17:01 matthias314

I made this a draft some time ago because I've been wondering if this is the right approach. Cursor positions and selections are automatically adjusted when inserting or deleting text. This is done in DoTextEvent. I think the right thing to do would be to treat replacements there, too. This way we would cover also replacements initiated by Lua scripts, not just those from ReplaceCmd. This is tricky to achieve at present because lines with matches are replaced entirely. With #3658 it will be much easier because the corresponding TextEvent will list every single replacement. What do you think about waiting and seeing if we can get a better solution with #3658?

matthias314 avatar Mar 09 '25 16:03 matthias314

Yeah, makes sense.

dmaluka avatar Mar 09 '25 16:03 dmaluka