Fix abbreviation expansion inserting a double trailing space#1111
Merged
Conversation
When an abbreviation was expanded by pressing <space>, the triggering space had already been inserted into the buffer before the expansion ran. The replacement selected only the abbreviation word (word_start..word_end), leaving that space in place, and then inserted the expansion followed by its own suffix space -- producing two trailing spaces (one before the cursor and one after). This broke history-based completion, since e.g. "git switch " is not a prefix of "git switch main". Select through the cursor position instead of the end of the word so the already-inserted triggering space is replaced by the expansion's suffix. The submit (<enter>) path is unaffected: there the cursor sits at the end of the word, so the selection is unchanged. Adds a regression test covering the <space> expansion path, which was previously untested.
Contributor
|
lgtm. what do you think @kronberger-droid ? |
Collaborator
|
Seems fine to me to. |
Collaborator
|
Found some things which are orthogonal to this change. Fine to land. |
Contributor
|
Thanks! |
Contributor
Author
|
@fdncred your welcome, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expanding an abbreviation by pressing
<space>inserted two trailingspaces instead of one — one before the cursor and one after. This breaks
history-based completion: e.g.
git switch(two spaces) is not a prefix ofgit switch main, so the ghost-text completion disappears until the extraspace is deleted manually. Fixes #1108.
Fix
On a
<space>expansion the triggering space has already been inserted intothe buffer before
try_expand_abbreviation_at_cursorruns. The replacementselected only the abbreviation word (
word_start..word_end), leaving thatspace in place, and then inserted the expansion followed by its own suffix
space — yielding two trailing spaces.
The selection now extends through
cursor_position_in_bufferinstead of theend of the word, so the already-inserted triggering space is replaced by the
expansion's suffix. The submit (
<enter>) path is unaffected: there the cursorsits at the end of the word, so the selected range is unchanged.
Test
Adds
abbreviation_expands_on_space_without_double_space, which exercises the<space>expansion path (submitted = false) — previously untested; allexisting abbreviation tests only covered the submit path. It asserts that
expanding
gc→git commitafter the triggering space yields exactlygit commit(one trailing space), and fails against the old behaviour(
git commit).Reference
Reported in #1108. The issue pinpointed
src/engine.rsabbreviation handlingas the cause.