helix-mods/helix-core/src
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
..
doc_formatter correctly wrap at text-width 2024-07-15 16:34:14 +02:00
increment Use non-deprecated chrono Duration functions 2024-03-14 14:13:56 +09:00
syntax Fix finding injection layer in tree cursor with nested layers (#11365) 2024-07-31 05:29:31 +09:00
auto_pairs.rs chore: clean up clippy lints (#11377) 2024-08-01 06:39:46 +09:00
chars.rs Revert "Replace unicode-general-category with icu-properties (#10989)" (#11006) 2024-06-23 10:05:53 +09:00
comment.rs toggling of block comments (#4718) 2024-02-27 22:36:25 +09:00
config.rs Add glob file type support (#8006) 2024-02-11 18:24:20 +01:00
diagnostic.rs render diagnostic inline 2024-07-15 16:35:30 +02:00
diff.rs delete outdated reference to cessen/ropey#25 (#4928) 2022-11-28 19:07:47 -06:00
doc_formatter.rs fix typo in doc_formatter.rs 2024-07-15 16:35:30 +02:00
fuzzy.rs Bump nucleo to v0.4.1 2024-07-15 09:31:32 -04:00
graphemes.rs render diagnostic inline 2024-07-15 16:35:30 +02:00
history.rs Prefer RopeSlice to &Rope in helix_core::syntax 2023-07-27 11:50:19 +09:00
indent.rs chore: clean up clippy lints (#11377) 2024-08-01 06:39:46 +09:00
lib.rs render diagnostic inline 2024-07-15 16:35:30 +02:00
line_ending.rs Add config for default line ending (#5621) 2023-06-16 12:02:15 -05:00
macros.rs Split parts of helix-term into helix-view. 2020-09-21 18:24:16 +09:00
match_brackets.rs Add curly single and double quotes to BRACKETS (#10971) 2024-06-18 10:40:19 +02:00
movement.rs Add commands for movement by subwords (#8147) 2024-08-08 13:57:59 -05:00
object.rs specify direction for select_prev_sibling and select_next_sibling (#10542) 2024-04-23 08:41:03 -05:00
position.rs fix scrolling/movement for multiline virtual text 2024-07-15 16:35:31 +02:00
rope_reader.rs search buffer contents during global search (#5652) 2023-07-11 21:26:11 +09:00
search.rs Jump to the next number on the line before incrementing (#1778) 2022-04-01 22:14:37 +09:00
selection.rs keep (cursor) position when exactly replacing text (#5930) 2024-08-10 00:40:34 +09:00
shellwords.rs Fix typos (#6643) 2023-04-07 23:10:38 +08:00
surround.rs test: match around closest pair tree-sitter version 2024-04-24 16:36:13 -04:00
syntax.rs chore: clean up clippy lints (#11377) 2024-08-01 06:39:46 +09:00
test.rs fix test::plain 2023-03-20 18:34:40 -05:00
text_annotations.rs ignore empty virtual text layers 2024-07-15 16:35:31 +02:00
textobject.rs test: match around closest pair tree-sitter version 2024-04-24 16:36:13 -04:00
transaction.rs keep (cursor) position when exactly replacing text (#5930) 2024-08-10 00:40:34 +09:00
uri.rs Convert LSP URIs into custom URIs 2024-07-15 09:31:33 -04:00
wrap.rs don't break on hyphen with :reflow (#8569) 2023-10-21 07:58:36 -05:00