Skip to content

:call phpactor#ChangeVisibility() "bug: leaves cursor down one line in the buffer #770

Closed

Description

@still-dreaming-1

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

Activity

  1. 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
  2. camilledejoye commented on Jun 7, 2019

    @camilledejoye
    Contributor

    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

    Instead of:

    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.

  3. dantleech commented on Jun 8, 2019

    @dantleech
    Collaborator

    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.

  4. camilledejoye commented on Jun 8, 2019

    @camilledejoye
    Contributor

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

  5. dantleech commented on Jun 8, 2019

    @dantleech
    Collaborator

    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.

  6. camilledejoye commented on Jun 8, 2019

    @camilledejoye
    Contributor

    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

  7. dantleech commented on Jun 8, 2019

    @dantleech
    Collaborator

    The problem is that we don't know, when replacing the whole file, if lines were inserted before the cursor or not.

  8. camilledejoye commented on Jun 8, 2019

    @camilledejoye
    Contributor

    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.

  9. camilledejoye commented on Jun 8, 2019

    @camilledejoye
    Contributor

    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 ?

  10. dantleech commented on Jun 8, 2019

    @dantleech
    Collaborator

    Sounds good.

    But we might want to put it in a beta branch

    This is basically what develop is :) master is "stable"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions