-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Goto mode implementation #3
Conversation
helix-view/src/commands.rs
Outdated
pub fn move_file_end(view: &mut View, _count: usize) { | ||
// TODO: use a transaction | ||
let text = &view.state.doc; | ||
let last_line = text.line_to_char(text.len_lines().checked_sub(2).unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use saturating_sub
helix-view/src/commands.rs
Outdated
pub fn check_cursor_in_view(view: &mut View) -> bool { | ||
let cursor = view.state.selection().cursor(); | ||
let line = view.state.doc().char_to_line(cursor) as u16; | ||
let document_end = view.first_line + view.size.1.saturating_sub(1) - 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saturating_sub(2)
helix-view/src/commands.rs
Outdated
view.first_line = view.first_line.saturating_sub(view.size.1); | ||
|
||
view.state.selection = Selection::single( | ||
text.line_to_char(view.first_line as usize), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculate line_to_char
in all of these methods once by assigning it to let pos
helix-view/src/commands.rs
Outdated
} | ||
|
||
pub fn half_page_down(view: &mut View, _count: usize) { | ||
view.first_line += view.size.1 / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to make sure first_line < text.len_lines()
, pressing half_page_down/page_down at document end will crash. Use a similar approach last_line()
uses to clamp the value.
helix-view/src/commands.rs
Outdated
if !check_cursor_in_view(view) { | ||
let text = &view.state.doc; | ||
view.state.selection = Selection::single( | ||
text.line_to_char(view.first_line as usize), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When scrolling down, you want the cursor to stick to the top edge (first_line + padding), when scrolling up you want it to be at the bottom of the screen last_line() - padding
.
Make padding a const PADDING: u16 = 5
for now
add python context queries
No description provided.