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

Add support for page up and page down #76

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/command_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,14 @@ impl CommandBar {
self.update_command_list();
self.history_index = None;
}
KeyCode::PageUp if key.modifiers == KeyModifiers::CONTROL => {
self.text_view.lock().await.scroll_to_start();
}
KeyCode::PageUp => self.text_view.lock().await.page_up(),
KeyCode::PageDown if key.modifiers == KeyModifiers::CONTROL => {
self.text_view.lock().await.scroll_to_end();
}
KeyCode::PageDown => self.text_view.lock().await.page_down(),
KeyCode::Backspace => {
if self.command_line.chars().count() == 1 {
self.show_hint();
Expand Down
41 changes: 41 additions & 0 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,47 @@ impl TextView {
}
}

pub fn page_up(&mut self) {
if self.max_main_axis() > 0 {
self.auto_scroll = false;
}

let page_height = self.frame_height - 5;

if self.scroll.0 < page_height {
self.scroll.0 = 0;
} else {
self.scroll.0 -= page_height;
}
}

pub fn page_down(&mut self) {
let max_main_axis = self.max_main_axis();
let page_height = self.frame_height - 5;

self.scroll.0 += page_height;
self.scroll.0 = self.scroll.0.clamp(0, max_main_axis);

if self.scroll.0 == max_main_axis {
self.auto_scroll = true;
}
}

pub fn scroll_to_start(&mut self) {
if self.max_main_axis() > 0 {
self.auto_scroll = false;
}

self.scroll.0 = 0;
}

pub fn scroll_to_end(&mut self) {
let max_main_axis = self.max_main_axis();

self.scroll.0 = max_main_axis;
self.auto_scroll = true;
}

pub fn left_scroll(&mut self) {
if self.scroll.1 < 3 {
self.scroll.1 = 0;
Expand Down
Loading