Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep (cursor) position when exactly replacing text #5930

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Apr 2, 2024

  1. keep (cursor) position when exactly replacing text

    Whenever a document is changed helix maps various positions like the
    cursor or diagnostics through the `ChangeSet` applied to the document.
    
    Currently, this mapping handles replacements as follows:
    
    * Move position to the left for `Assoc::Before` (start of selection)
    * Move position to the right for `Assoc::After` (end of selection)
    
    However, when text is exactly replaced this can produce weird results
    where the cursor is moved when it shouldn't. For example if `foo` is
    selected and a separate cursor is placed on each character (`s.<ret>`)
    and the text is replaced (for example `rx`) then the cursors are moved
    to the side instead of remaining in place.
    
    This change adds a special case to the mapping code of replacements:
    If the deleted and inserted text have the same (char) length then
    the position is returned as if the replacement doesn't exist.
    
    only keep selections invariant under replacement
    
    Keeping selections unchanged if they are inside an exact replacement
    is intuitive. However, for diagnostics this is not desirable as
    helix would otherwise fail to remove diagnostics if replacing parts
    of the document.
    pascalkuthe committed Apr 2, 2024
    Configuration menu
    Copy the full SHA
    cea759f View commit details
    Browse the repository at this point in the history