You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
:call phpactor#ChangeVisibility() "bug: leaves cursor down one line in the buffer #770
This bug occurs if the cursor is inside a PHP method or at the signature, and I call that Vim function. It does successfully change the visibility of the method though.
phpactor 0.12.0
NVIM v0.3.1
Ubuntu 16.04.6 LTS
changed the title [-]:call phpactor#ChangeVisibility() "bug: moves to next line in the buffer[/-][+]:call phpactor#ChangeVisibility() "bug: leaves cursor down one line in the buffer[/+]on Jun 2, 2019
I tried to find a solution but I don't see how we can manage some situations.
I think was it's missing right now is that the cursor is move down if lines are added before it, but it's not move up when lines are deleted.
We can fix that easily with:
let postCursorPosition[1] = postCursorPosition[1] + newLines - linesToDelete
let postCursorPosition[1] = postCursorPosition[1] + newLines
But there is still a problem when the cursor is on the function declaration line.
Then the cursor ends up one line above...
For me, as soon as the line where the cursor was positioned is modified then it's impossible to know where to put the cursor after the modifications.
If the line of the cursor is deleted and we move up, then when this "same" line is replaced it's after the cursor, so we don't move it down. We are one line above.
If we don't move the cursor up when it's line is deleted, then the replaced line is inserted before the cursor so it's moved down. We are one line under.
If we were able to do an update operation instead of a delete + create then this problem wouldn't append.
I hope that it will help someone to figure out a solution.
Yes, I struggled to get this to work, I'm sure there must be a better way (somehow). Maybe some inspiration could be taken from other plugins which apply diffs to buffers.
Maybe a few leads with :diffpatch
Or generate a unified diff instead of on array, return this diff and then applying it with patch
But that would require the local system to have patch install...
Or generate a unified diff instead of on array, return this diff and then applying it with patch
That would require reloading the buffer? Originally this is what Phpactor did, but caused very unnecessary cursor movement when f.e. importing classes etc.
Indeed, I got some home with the tests on change visibility because the number of lines didn't change.
So we are back with the actual approach.
I wonder if the main problem isn't that a replace is done in two different operation: delete + create
That's why we loose the correct cursor position, after the delete the line where the cursor was doesn't exist anymore.
For example in the change visibility case we got two edit:
start at line -1, end at line, text empty
start at line, end at line, text with the replacement
What if we got instead:
start at line - 1, end at line, text with the replacement
Another possibility would be to remember the line of the cursor if this line is deleted.
And on the next operation put back the cursor onto this line if it's creating a new one.
But then we are working knowing that we will receive only changes on one line at a time.
Which is an implementation detail that we should not be aware of.
Another possibility would be to remember the line of the cursor if this line is deleted.
And on the next operation put back the cursor onto this line if it's creating a new one.
But then we are working knowing that we will receive only changes on one line at a time.
Which is an implementation detail that we should not be aware of.
That seems to work.
And I was partially wrong when I said that it will make us rely on an implementation detail.
Working with the start and end line as a range fix that.
But we still depends on the fact that the "edits" are sorted from top to bottom, which seems reasonable to me.
I will continue testing it with a few cases, if the solution seems good enough for you I will make a PR.
But we might want to put it in a beta branch of something like that.
So everyone can test it if willing but still enjoy the develop branch without too much risks ?
Activity
[-]:call phpactor#ChangeVisibility() "bug: moves to next line in the buffer[/-][+]:call phpactor#ChangeVisibility() "bug: leaves cursor down one line in the buffer[/+]camilledejoye commentedon Jun 7, 2019
I tried to find a solution but I don't see how we can manage some situations.
I think was it's missing right now is that the cursor is move down if lines are added before it, but it's not move up when lines are deleted.
We can fix that easily with:
Instead of:
phpactor/plugin/phpactor.vim
Line 405 in 2a14f2a
But there is still a problem when the cursor is on the function declaration line.
Then the cursor ends up one line above...
For me, as soon as the line where the cursor was positioned is modified then it's impossible to know where to put the cursor after the modifications.
If the line of the cursor is deleted and we move up, then when this "same" line is replaced it's after the cursor, so we don't move it down. We are one line above.
If we don't move the cursor up when it's line is deleted, then the replaced line is inserted before the cursor so it's moved down. We are one line under.
If we were able to do an update operation instead of a delete + create then this problem wouldn't append.
I hope that it will help someone to figure out a solution.
dantleech commentedon Jun 8, 2019
Yes, I struggled to get this to work, I'm sure there must be a better way (somehow). Maybe some inspiration could be taken from other plugins which apply diffs to buffers.
camilledejoye commentedon Jun 8, 2019
Maybe a few leads with
:diffpatchOr generate a unified diff instead of on array, return this diff and then applying it with
patchBut that would require the local system to have
patchinstall...dantleech commentedon Jun 8, 2019
That would require reloading the buffer? Originally this is what Phpactor did, but caused very unnecessary cursor movement when f.e. importing classes etc.
camilledejoye commentedon Jun 8, 2019
Using vim filters it seems to work but I only tried on really simple cases.
:keepmarks !patch % <patch_file>The cursor doesn't appear to be moved.
But again, try only for the change visibility case, what if we add/delete lines ?
Will keep searching, just wanted to gave an update
dantleech commentedon Jun 8, 2019
The problem is that we don't know, when replacing the whole file, if lines were inserted before the cursor or not.
camilledejoye commentedon Jun 8, 2019
Indeed, I got some home with the tests on change visibility because the number of lines didn't change.
So we are back with the actual approach.
I wonder if the main problem isn't that a replace is done in two different operation: delete + create
That's why we loose the correct cursor position, after the delete the line where the cursor was doesn't exist anymore.
For example in the change visibility case we got two
edit:startat line -1,endat line,textemptystartat line,endat line,textwith the replacementWhat if we got instead:
startat line - 1,endat line,textwith the replacementAnother possibility would be to remember the line of the cursor if this line is deleted.
And on the next operation put back the cursor onto this line if it's creating a new one.
But then we are working knowing that we will receive only changes on one line at a time.
Which is an implementation detail that we should not be aware of.
camilledejoye commentedon Jun 8, 2019
That seems to work.
And I was partially wrong when I said that it will make us rely on an implementation detail.
Working with the
startandendline as a range fix that.But we still depends on the fact that the "edits" are sorted from top to bottom, which seems reasonable to me.
I will continue testing it with a few cases, if the solution seems good enough for you I will make a PR.
But we might want to put it in a
betabranch of something like that.So everyone can test it if willing but still enjoy the
developbranch without too much risks ?dantleech commentedon Jun 8, 2019
Sounds good.
This is basically what develop is :) master is "stable"