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

Only align cursor center when it isn't in view. #959

Merged
merged 1 commit into from
Nov 9, 2021

Conversation

cossonleo
Copy link
Contributor

@cossonleo cossonleo commented Nov 2, 2021

I often use search to move cursor to pos I aready know and keep my eyes on it.
Currenly helix always align cursor to center that cause Eyes lost the pos.
This PR will only align cursor center when it isn't in view.

Previous:

hx_sl1

After:

hx_s4

@archseer
Copy link
Member

archseer commented Nov 2, 2021

This was the original behavior, but it's annoying when you're searching for something offscreen: if I search for a method via fn foo it will only show me the start of the method and I need to re-center it manually.

Maybe some type of smart behavior would be nice? (center if next match is offscreen, otherwise don't move the screen)

@cossonleo
Copy link
Contributor Author

cossonleo commented Nov 3, 2021

center if next match is offscreen, otherwise don't move the screen

This way is better. I'll change to it

@cossonleo cossonleo changed the title view scroll more smaller when search match Only align cursor center when it isn't in view. Nov 4, 2021
@cossonleo
Copy link
Contributor Author

cossonleo commented Nov 4, 2021

@archseer

Already.

helix-view/src/view.rs Outdated Show resolved Hide resolved
@archseer
Copy link
Member

archseer commented Nov 8, 2021

Looks good 👍🏻 Can you update the PR, looks like there's a merge conflict?

@cossonleo
Copy link
Contributor Author

Looks good 👍🏻 Can you update the PR, looks like there's a merge conflict?

It has rebased master and conflicts are resolved.

Comment on lines +138 to +147
pub fn ensure_cursor_in_view(&mut self, doc: &Document, scrolloff: usize) {
if let Some((row, col)) = self.offset_coords_to_in_view(doc, scrolloff) {
self.offset.row = row;
self.offset.col = col;
}
}

pub fn is_cursor_in_view(&mut self, doc: &Document, scrolloff: usize) -> bool {
self.offset_coords_to_in_view(doc, scrolloff).is_none()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need to call offset_coords_to_in_view twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Scrolloff is different between two calls.
I don't have idea to merge two calls.

@archseer archseer merged commit a69caff into helix-editor:master Nov 9, 2021
@cossonleo cossonleo deleted the search_view_opt branch November 9, 2021 02:18
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.

3 participants