helix-mirror/helix-core
Pascal Kuthe e604d9f8e0
keep (cursor) position when exactly replacing text (#5930)
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.
2024-08-10 00:40:34 +09:00
..
src keep (cursor) position when exactly replacing text (#5930) 2024-08-10 00:40:34 +09:00
tests Resolve new Clippy lints 2024-05-07 15:15:52 -04:00
.gitignore Initial import. 2020-05-20 18:14:51 +09:00
Cargo.toml build(deps): bump the rust-dependencies group with 6 updates (#11371) 2024-07-29 21:10:47 -05:00