-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Auto pair deletions with selections #7269
Open
dead10ck
wants to merge
8
commits into
helix-editor:master
Choose a base branch
from
dead10ck:auto-pair-delete
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
3a4afeb
to
65dd1de
Compare
65dd1de
to
50da07b
Compare
50da07b
to
3c53b35
Compare
3c53b35
to
5c4f5d2
Compare
5c4f5d2
to
32825f0
Compare
32825f0
to
693b508
Compare
693b508
to
3d1948a
Compare
3d1948a
to
c3bbdc1
Compare
c3bbdc1
to
5408d6b
Compare
5408d6b
to
c7d2178
Compare
c7d2178
to
6627bff
Compare
63992e2
to
22fa4d6
Compare
This was rebased. I think the new tests had been failing since the integration test refactor, but I fixed those too. |
cc58787
to
38dee58
Compare
37c68cb
to
ff3ea3d
Compare
a2b9b23
to
d8724fd
Compare
d8724fd
to
4fb0ff0
Compare
4fb0ff0
to
b709488
Compare
b709488
to
030e8fa
Compare
030e8fa
to
9360563
Compare
7e9a1f1
to
c3e372b
Compare
8c42324
to
d6772a6
Compare
d6772a6
to
f6b6678
Compare
Adds `Transaction::change_by_and_with_selection` which centralizes logic for producing change sets with a potentially new selection that is applied incrementally, rather than all at once at the end with `with_selection`. It also centralizes the offset tracking logic so that the caller can construct a new selection with ranges as if they were operating on the text as-is.
Change the auto pair hook to operate on single ranges to allow transactions that mix auto pair changes with other operations, such as inserting or deleting a single char, and denendting.
This completes auto pair deletions. Currently, auto pairs only get deleted when the range is a single grapheme wide, since otherwise, the selection would get computed incorrectly through the normal change mapping process. Now auto pairs get deleted even with larger ranges, and the resulting selection is correct.
f6b6678
to
a0e8cab
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-helix-term
Area: Helix term improvements
C-enhancement
Category: Improvements
E-medium
Call for participation: Experience needed to fix: Medium / intermediate
S-waiting-on-review
Status: Awaiting review from a maintainer.
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.
This PR completes auto pair deletions. Currently, pairs are only deleted on ranges that are a single grapheme in width, since the normal change mapping process results in an incorrect selection on multi-grapheme ranges.
This is achieved with two new functions:
change_by_and_with_selection
delete_by_and_with_selection
They are helpers which take a transformation function that produces individual changes, one range at a time, and can optionally produce a new range that replaces the input range that it took as an argument. When one is not given, the input range is mapped through the change set as normal. This allows the caller to apply changes to the text and incrementally build a new selection as they go, picking and choosing in which cases new ranges are computed explicitly, and in which they are mapped normally.
Concretely, this solves the problem of needing auto pair deletes to work concurrently with dedenting on backspace; the auto pair hooks were changed to operate on individual ranges and return individual changes, rather than producing a whole complete transaction. Then deleting was enabled to compose changes from all 3 possible scenarios at once, i.e. deleting a single grapheme, dedenting, and auto pair deletions.
Additionally, this PR inserts an extra whitespace when the cursor is inside a pair to pad the left and right.