geany-plugins icon indicating copy to clipboard operation
geany-plugins copied to clipboard

Vimode: fix cursor position after using undo

Open scresto09 opened this issue 1 year ago • 4 comments

Trying to get more Vim-like behavior for cursor position after using undo (U key)

scresto09 avatar Apr 16 '24 10:04 scresto09

Seems to make sense, just curious when the problem exactly happens - could you give an example when the output of the plugin differs from vim?

techee avatar Apr 25 '24 15:04 techee

Sure, here's an example:

Open a 5 line file Move the cursor to line 2 press "2dd" to delete 2 lines press "u" to cancel

With a real VIM, the cursor stays on line 2 With Geany Vimode not patched, the cursor goes to the last line

scresto09 avatar Apr 25 '24 17:04 scresto09

But this isn't really what vim does, is it? Try the following with this patch:

  1. Delete a line in the middle of a file.
  2. Scroll to the top of the file so you have the cursor e.g. on the first line
  3. Press u

The undo happens but your cursor is still on the first line instead of being at the position of the change which is very confusing. I think what you want instead is to get the information where the undo happened and move the cursor to the first line of the diff. Maybe you could achieve this using SC_PERFORMED_UNDO (not sure, I haven't studied how exactly this works and if it provides enough information).

techee avatar May 08 '24 15:05 techee

You're right, my previous correction was not correct.

327cdde is a new fix using the SC_MOD_BEFOREINSERT and SC_PERFORMED_UNDO events to save the cursor position.

scresto09 avatar May 13 '24 15:05 scresto09

Looks good, thanks!

One last request - would you squash all the commits into one? I'll merge it afterwards.

techee avatar May 21 '24 21:05 techee

Also prefix the commit message with vimode: so it's clear what plugin the commit modifies.

techee avatar May 21 '24 21:05 techee

OK, I did it, is it okay? Thanks

scresto09 avatar May 22 '24 08:05 scresto09

Looks great, thanks!

techee avatar May 22 '24 15:05 techee