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 Page Up and Page Down #1114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions rust/core-lib/src/edit_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub(crate) enum ViewEvent {
SelectionForReplace,
SelectionIntoLines,
CollapseSelections,
PageUpDown(Movement),
}

/// Events that modify the buffer
Expand Down Expand Up @@ -264,6 +265,8 @@ impl From<EditNotification> for EventDomain {
PlayRecording { recording_name } => SpecialEvent::PlayRecording(recording_name).into(),
ClearRecording { recording_name } => SpecialEvent::ClearRecording(recording_name).into(),
CollapseSelections => ViewEvent::CollapseSelections.into(),
PageUp => ViewEvent::PageUpDown(Movement::UpPage).into(),
PageDown => ViewEvent::PageUpDown(Movement::DownPage).into(),
}
}
}
2 changes: 2 additions & 0 deletions rust/core-lib/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ pub enum EditNotification {
recording_name: String,
},
CollapseSelections,
PageUp,
PageDown,
}

/// The edit related requests.
Expand Down
15 changes: 15 additions & 0 deletions rust/core-lib/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl View {
Replace { chars, preserve_case } => self.do_set_replace(chars, preserve_case),
SelectionForReplace => self.do_selection_for_replace(text),
SelectionIntoLines => self.do_split_selection_into_lines(text),
PageUpDown(movement) => self.page_up_down(movement),
}
}

Expand Down Expand Up @@ -351,6 +352,20 @@ impl View {
self.set_selection(text, new_sel);
}

pub fn page_up_down(&mut self, movement: Movement) {
let first_line: i64 = self.first_line as i64;
let scroll_height: i64 = self.scroll_height() as i64;
match movement {
Movement::DownPage => {
self.set_scroll(first_line - scroll_height, first_line);
Copy link
Member

Choose a reason for hiding this comment

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

Right now this only updates first_line and height in View but does not tell the frontend to actually scroll to that position. So for now nothing happens.
To make it scroll you have to set self.scroll_to = Some(<position>);
There are some functions in View where this is already used, for example in scroll_to_cursor, which might be helpful.

}
Movement::UpPage => {
self.set_scroll(first_line + scroll_height, first_line + 2 * scroll_height);
}
_ => (),
}
}

/// Set the selection to a new value.
pub fn set_selection<S: Into<Selection>>(&mut self, text: &Rope, sel: S) {
self.set_selection_raw(text, sel.into());
Expand Down