Skip to content
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

Keep ViewPosition consistent when a Document is edited from different Views, and on buffer switching #10559

Merged
merged 7 commits into from
Jul 23, 2024

Conversation

intarga
Copy link
Contributor

@intarga intarga commented Apr 22, 2024

Supersedes #7568, fixes #7355.

Since view offsets can no longer be initialised in View::new(), I moved them next to selection initialisation in doc.ensure_view_init(view_id). I was a little concerned about all those unwraps on doc.view_data(view_id) (those functions are infallible and don't have a mutable reference to doc, so there's no way to ensure view_data is initialised in there), but in theory it should be panic-safe, as long as doc.ensure_view_init(view_id) is called for every new view, which it is. It was missing from some test cases, since they didn't seem to need selections, but it's added even to those now.

@intarga
Copy link
Contributor Author

intarga commented Apr 22, 2024

Can we get a retry on this test failure? It looks unrelated to my changes, and I can't reproduce it.

Ran the same commit through CI on my fork and got a pass
https://github.com/intarga/helix/actions/runs/8790787504?pr=1

@archseer
Copy link
Member

Something must have changed on the Github Actions runner, I'm seeing the same failure in other PRs.

@the-mikedavis
Copy link
Member

Looks like macos runners switched from x86 to arm. Clearing the tree-stter-grammars cache for macos seems to have fixed it

helix-view/src/document.rs Outdated Show resolved Hide resolved
helix-view/src/document.rs Outdated Show resolved Hide resolved
helix-view/src/document.rs Outdated Show resolved Hide resolved
helix-view/src/editor.rs Outdated Show resolved Hide resolved
helix-view/src/view.rs Outdated Show resolved Hide resolved
helix-term/src/application.rs Outdated Show resolved Hide resolved
helix-term/src/application.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-term/src/commands.rs Outdated Show resolved Hide resolved
helix-view/src/view.rs Outdated Show resolved Hide resolved
helix-view/src/document.rs Outdated Show resolved Hide resolved
@pascalkuthe
Copy link
Member

this lgtm now and was a smaller change than I expected. I will test this out locally a bit

for view_data in self.view_data.values_mut() {
view_data.view_position.anchor = transaction
.changes()
.map_pos(view_data.view_position.anchor, Assoc::Before);
Copy link
Member

@pascalkuthe pascalkuthe Apr 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder if we should be using Assoc::After here instead. I don't have any opinion here. I will try with before and see if it annoys me. It sprobably doesn't make too much difference due to ensure_cursor_in_view keeping the view position somewhat fixed in extreme cases. In thsose cases it probably makes more sense to keep the cursor at the top so before is probably right

@intarga
Copy link
Contributor Author

intarga commented Jul 8, 2024

@pascalkuthe Did you get a chance to try this?

@intarga
Copy link
Contributor Author

intarga commented Jul 23, 2024

@the-mikedavis Is there anything we can do to move this forward? It's been sitting here a long time now

@the-mikedavis
Copy link
Member

I've been running this for a while (I think Pascal has too although he's quite busy lately). It's hard to tell whether it should be Assoc::Before or Assoc::After, I also don't have an opinion so I think we can just roll with Assoc::Before for now.

After a rebase or master merge I think this is good to go. WDYT @pascalkuthe?

@pascalkuthe
Copy link
Member

from my side this is good to go. I think the Assoc is fine. I remember you having some concerns related to this PR where you preferred keeping the current behaviour where we center the view in some instances @the-mikedavis. I dont' quite remember the details though. I guess you may know better.

@intarga
Copy link
Contributor Author

intarga commented Jul 23, 2024

@the-mikedavis The branch is up to date now

@the-mikedavis
Copy link
Member

I thought I noticed an undesirable change with the jumplist or LSP goto-definition but I tried a bunch of different workflows with this branch vs master and couldn't tell the difference, so I must've been mistaken

doc.ensure_view_init(view.id);
view.sync_changes(doc);
doc.mark_as_focused();

align_view(doc, view, Align::Center);
view.ensure_cursor_in_view(doc, scrolloff)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change may be where Mikes comments are coming from. However, it seems that we are manually centering the view for LSP jumps. I do definitely perefr centering the view when jumping with gd. If we notice commands that relied on the editor implicitly centering here we can add that back to the command definition. I think if we want to change the view position we should do it explicitly instead of implicitly.

@pascalkuthe pascalkuthe merged commit 1d0a3d4 into helix-editor:master Jul 23, 2024
6 checks passed
@x10an14
Copy link

x10an14 commented Jul 23, 2024

Thanks for the awesome effort all, not to mention your patience/persistence @intarga! =D

SofusA pushed a commit to SofusA/helix-pull-diagnostics that referenced this pull request Aug 4, 2024
* replicate t-monaghan's changes

* remove View.offset in favour of Document.view_data.view_position

* improve access patterns for Document.view_data

* better borrow checker wrangling with doc_mut!()

* reintroduce ensure_cursor_in_view in handle_config_events

since we sorted out the borrow checker issues using partial borrows,
there's nothing stopping us from going back to the simpler implementation

* introduce helper functions on Document .view_offset, set_view_offset

* fix rebase breakage
mxxntype pushed a commit to mxxntype/helix that referenced this pull request Aug 14, 2024
* replicate t-monaghan's changes

* remove View.offset in favour of Document.view_data.view_position

* improve access patterns for Document.view_data

* better borrow checker wrangling with doc_mut!()

* reintroduce ensure_cursor_in_view in handle_config_events

since we sorted out the borrow checker issues using partial borrows,
there's nothing stopping us from going back to the simpler implementation

* introduce helper functions on Document .view_offset, set_view_offset

* fix rebase breakage
stackotter pushed a commit to stackotter/helix that referenced this pull request Aug 28, 2024
* replicate t-monaghan's changes

* remove View.offset in favour of Document.view_data.view_position

* improve access patterns for Document.view_data

* better borrow checker wrangling with doc_mut!()

* reintroduce ensure_cursor_in_view in handle_config_events

since we sorted out the borrow checker issues using partial borrows,
there's nothing stopping us from going back to the simpler implementation

* introduce helper functions on Document .view_offset, set_view_offset

* fix rebase breakage
kyruzic pushed a commit to kyruzic/helix that referenced this pull request Sep 27, 2024
* replicate t-monaghan's changes

* remove View.offset in favour of Document.view_data.view_position

* improve access patterns for Document.view_data

* better borrow checker wrangling with doc_mut!()

* reintroduce ensure_cursor_in_view in handle_config_events

since we sorted out the borrow checker issues using partial borrows,
there's nothing stopping us from going back to the simpler implementation

* introduce helper functions on Document .view_offset, set_view_offset

* fix rebase breakage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to not centre the cursor when switching between buffers
5 participants