vim-signature icon indicating copy to clipboard operation
vim-signature copied to clipboard

[bug] When adding or removing lines, the mark positions are not updated.

Open trusktr opened this issue 7 years ago • 8 comments

I love this plugin!

But there's only one thing that prevents proper usage for me: if I paste code (for example) the marks don't move to their new line numbers. The marks in the gutter move, as expected, but the actual marks don't, they stay on the same line.

For example, suppose we have this code and add a mark:

  1 one
# 2 two|
  3 three

right now it works, navigating to the mark will take me to line 2 (the | shows where navigation takes me).

if I add some lines, I get something that looks like this:

  1 one
  2 one-a|
  3 one-b
  4 one-c
# 5 two
  6 three

so it looks like the mark moved down to line 5, but when I try to navigate to the mark, my cursor moves to line 2

trusktr avatar Apr 21 '17 18:04 trusktr

@trusktr Sorry for the late response.

For most things, marks and signs behave similarly such as moving when you add/remove lines around the line with the mark/sign. However, when it comes deleting a line, vim treats the two differently; marks get removed while the sign persists. I don't know why vim chooses to do it this way.

To fix this, I ended up periodically comparing the line number of the mark and the sign and correcting it when a line gets moved.

Currently, there isn't a good API to figure out the line number a sign is located on (feel free to correct me in case this is no longer true) and hence I'm a little worried that my code might be a little resource-intensive. Please try it out and let me know in case of any issues.

kshenoy avatar Aug 16 '17 04:08 kshenoy

Had to retract the fix. Will try to figure out a better solution.

kshenoy avatar Aug 17 '17 23:08 kshenoy

No prob, looking forward to it! This is one of my favorite plugins!

On Aug 17, 2017 4:48 PM, "Kartik Shenoy" [email protected] wrote:

Had to retract the fix. Will try to figure out a better solution.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kshenoy/vim-signature/issues/140#issuecomment-323223629, or mute the thread https://github.com/notifications/unsubscribe-auth/AASKzmhSEwOfshWi_wsri6GiWYbh285Fks5sZNFggaJpZM4NEp9O .

trusktr avatar Aug 18 '17 00:08 trusktr

After this retracting, when adding or removing lines, vim keeps displaying anonying information as below in command window.

Error detected while processing function signature#sign#Refresh..signature#sign#Remove:       
line   32:                                                                                    
E117: Unknown function: assert_true

I figured out it is due to the following change. Guess this is for debugging purpose? + call assert_true(len(l:arr) == 1, "Multiple marks found where one was expected")

pright avatar Nov 22 '17 08:11 pright

Still looking forward to the fi for this, it's quite annoying. Most of the time, the marks only move a little ways off, so I can usually find my way. Only sometimes with large modifications do the marks become way off. So most of the time I can live with the mark being a few lines off, then navigating my way to the correct line.

trusktr avatar Feb 20 '18 18:02 trusktr

This works fine in vim-bookmarks. Maybe you can look at how vim-bookmarks does it. Works perfectly there (add/remove lines, undo/redo, etc, anything you do, the marks move in the gutter and in the code).

trusktr avatar Feb 20 '18 19:02 trusktr

Will do. Thanks :)

kshenoy avatar Feb 21 '18 00:02 kshenoy

I thought I had somehow broken the plugin somewhere in my 1000-line vimrc - good to know I won't have to binary search to find the problem, haha

Anywho, this should be easily fixable with the TextChanged and TextChangedI events. Comparing the mark and sign positions for every pair on every edit isn't great, especially if it isn't straightforward to get sign positions (if it was, I assume this plugin would just use signs on the backend). . . If I get the time I'll look through the source and see if there's a way to get a list of marks below the changes.

IsaacElenbaas avatar Jun 12 '21 15:06 IsaacElenbaas