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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

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
since we sorted out the borrow checker issues using partial borrows,
there's nothing stopping us from going back to the simpler implementation
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

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

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
4 participants