Skip to content

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

Merged
archseer merged 1 commit into
masterfrom
unknown repository
Nov 9, 2021
Merged

Only align cursor center when it isn't in view.#959
archseer merged 1 commit into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Nov 2, 2021

Copy link
Copy Markdown

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

archseer commented Nov 2, 2021

Copy link
Copy Markdown
Member

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)

@ghost

ghost commented Nov 3, 2021

Copy link
Copy Markdown
Author

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

This way is better. I'll change to it

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

ghost commented Nov 4, 2021

Copy link
Copy Markdown
Author

@archseer

Already.

Comment thread helix-view/src/view.rs Outdated
@ghost
ghost requested a review from archseer November 5, 2021 03:15
@archseer

archseer commented Nov 8, 2021

Copy link
Copy Markdown
Member

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

@ghost

ghost commented Nov 8, 2021

Copy link
Copy Markdown
Author

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

It has rebased master and conflicts are resolved.

Comment thread helix-view/src/view.rs
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
Copy Markdown
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
Copy Markdown
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
@ghost
ghost 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.

2 participants