editor: Fix the merging of adjacent selection edits#45363
editor: Fix the merging of adjacent selection edits#45363Veykril merged 16 commits intozed-industries:mainfrom
Conversation
|
Hmm, could we just have a buffer edit variant here that disallows merging the passed in edits for this case? |
|
@Veykril I also tried disabling the merge in the edit method to see if that would solve the issue, but it didn’t. The fragments still ended up being merged into a single one. I’d actually prefer this solution as well, so I’ll take another look and see if I can get it to work |
6f6e363 to
da64585
Compare
| self.buffers.is_empty() | ||
| } | ||
|
|
||
| pub fn edit<I, S, T>( |
There was a problem hiding this comment.
Okay thats a lot of call sites, lets change plans slightly here. Let's make this function (with the arg) private and rename it something else. Then have two methods edit and edit_non_coalesce that just calls out to the private one but the bool parameter being different. That way we will only need to touch that one (or maybe couple) callsite(s). That way we also dont obscure this behavior too much behind a random non-descriptive bool
There was a problem hiding this comment.
Yes, this makes a lot of sense. I didn't realize how many there were until I checked the changes on the PR
There was a problem hiding this comment.
Should be done
|
needs a rebase |
|
@Veykril thank you. I will rebase later. |
82f20ec to
8e85cb6
Compare
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
This reverts commit 48770ac.
This reverts commit 70b439d.
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
8e85cb6 to
42236e2
Compare
Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com>
|
@Veykril I've rebased 🙂 |
Closes #45046 The root of the issue is anchor resolution. When we apply adjacent edits, they get merged into a single edit. In the scenario described in the issue, this is what happens: 1. We create an anchor at the end of each selection (bias::right) on the snapshot before the edits. 2. We collect the edits and apply them to the buffer. 3. Since the edits are adjacent (>=), the buffer merges them into a single edit. 4. As a result, we apply one edit to the text buffer, creating a single visible fragment with length = 3. 5. The buffer ends up with fragments like: [F(len = 3, visible = true), F(len = 1, visible = false), ...] 6. After the edits, we resolve the previously created anchors to produce zero-width selections (cursors). 7. All anchors resolve into deleted fragments, so their resolved offset equals the cumulative visible offset, which is 3. 8. We now have 3 cursors with identical coordinates (0;3). 9. These cursors get merged into a single cursor. I tried several approaches, but they either felt wrong or didn’t work. In particular, I tried adjusting anchor resolution using the delta stored in handle_input, but this doesn’t help because selections are merged immediately after anchor resolution. The only workable solution I found is to avoid anchors entirely for the adjacent-edit case. Instead, we can compute the final cursor positions directly from the edits and create the selections based on that information. Release Notes: - Fixed an issue where adjacent selection insert would merge cursors --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
…5363) Closes zed-industries#45046 The root of the issue is anchor resolution. When we apply adjacent edits, they get merged into a single edit. In the scenario described in the issue, this is what happens: 1. We create an anchor at the end of each selection (bias::right) on the snapshot before the edits. 2. We collect the edits and apply them to the buffer. 3. Since the edits are adjacent (>=), the buffer merges them into a single edit. 4. As a result, we apply one edit to the text buffer, creating a single visible fragment with length = 3. 5. The buffer ends up with fragments like: [F(len = 3, visible = true), F(len = 1, visible = false), ...] 6. After the edits, we resolve the previously created anchors to produce zero-width selections (cursors). 7. All anchors resolve into deleted fragments, so their resolved offset equals the cumulative visible offset, which is 3. 8. We now have 3 cursors with identical coordinates (0;3). 9. These cursors get merged into a single cursor. I tried several approaches, but they either felt wrong or didn’t work. In particular, I tried adjusting anchor resolution using the delta stored in handle_input, but this doesn’t help because selections are merged immediately after anchor resolution. The only workable solution I found is to avoid anchors entirely for the adjacent-edit case. Instead, we can compute the final cursor positions directly from the edits and create the selections based on that information. Release Notes: - Fixed an issue where adjacent selection insert would merge cursors --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
…5363) Closes zed-industries#45046 The root of the issue is anchor resolution. When we apply adjacent edits, they get merged into a single edit. In the scenario described in the issue, this is what happens: 1. We create an anchor at the end of each selection (bias::right) on the snapshot before the edits. 2. We collect the edits and apply them to the buffer. 3. Since the edits are adjacent (>=), the buffer merges them into a single edit. 4. As a result, we apply one edit to the text buffer, creating a single visible fragment with length = 3. 5. The buffer ends up with fragments like: [F(len = 3, visible = true), F(len = 1, visible = false), ...] 6. After the edits, we resolve the previously created anchors to produce zero-width selections (cursors). 7. All anchors resolve into deleted fragments, so their resolved offset equals the cumulative visible offset, which is 3. 8. We now have 3 cursors with identical coordinates (0;3). 9. These cursors get merged into a single cursor. I tried several approaches, but they either felt wrong or didn’t work. In particular, I tried adjusting anchor resolution using the delta stored in handle_input, but this doesn’t help because selections are merged immediately after anchor resolution. The only workable solution I found is to avoid anchors entirely for the adjacent-edit case. Instead, we can compute the final cursor positions directly from the edits and create the selections based on that information. Release Notes: - Fixed an issue where adjacent selection insert would merge cursors --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
…5363) Closes zed-industries#45046 The root of the issue is anchor resolution. When we apply adjacent edits, they get merged into a single edit. In the scenario described in the issue, this is what happens: 1. We create an anchor at the end of each selection (bias::right) on the snapshot before the edits. 2. We collect the edits and apply them to the buffer. 3. Since the edits are adjacent (>=), the buffer merges them into a single edit. 4. As a result, we apply one edit to the text buffer, creating a single visible fragment with length = 3. 5. The buffer ends up with fragments like: [F(len = 3, visible = true), F(len = 1, visible = false), ...] 6. After the edits, we resolve the previously created anchors to produce zero-width selections (cursors). 7. All anchors resolve into deleted fragments, so their resolved offset equals the cumulative visible offset, which is 3. 8. We now have 3 cursors with identical coordinates (0;3). 9. These cursors get merged into a single cursor. I tried several approaches, but they either felt wrong or didn’t work. In particular, I tried adjusting anchor resolution using the delta stored in handle_input, but this doesn’t help because selections are merged immediately after anchor resolution. The only workable solution I found is to avoid anchors entirely for the adjacent-edit case. Instead, we can compute the final cursor positions directly from the edits and create the selections based on that information. Release Notes: - Fixed an issue where adjacent selection insert would merge cursors --------- Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Co-authored-by: Lukas Wirth <me@lukaswirth.dev>
Closes #45046
The root of the issue is anchor resolution. When we apply adjacent edits, they get merged into a single edit. In the scenario described in the issue, this is what happens:
I tried several approaches, but they either felt wrong or didn’t work. In particular, I tried adjusting anchor resolution using the delta stored in handle_input, but this doesn’t help because selections are merged immediately after anchor resolution.
The only workable solution I found is to avoid anchors entirely for the adjacent-edit case. Instead, we can compute the final cursor positions directly from the edits and create the selections based on that information.
Release Notes: