geany / geany-plugins

The combined Geany Plugins collection
http://plugins.geany.org/
590 stars 264 forks source link

Vimode: fix cursor position after using undo #1328

Closed scresto09 closed 4 months ago

scresto09 commented 5 months ago

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

techee commented 5 months ago

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?

scresto09 commented 5 months ago

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

techee commented 4 months ago

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).

scresto09 commented 4 months ago

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.

techee commented 4 months ago

Looks good, thanks!

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

techee commented 4 months ago

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

scresto09 commented 4 months ago

OK, I did it, is it okay? Thanks

techee commented 4 months ago

Looks great, thanks!