Merge pull request #626 from sagittarius-a/feature/scroll-mode-restore-on-sigint

feat(scroll): Restore scroll position on SIGINT
This commit is contained in:
a-kenji 2021-07-25 20:32:31 +02:00 committed by GitHub
commit 21f8d6e915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 0 deletions

View File

@ -127,6 +127,12 @@ fn route_action(
.send_to_screen(ScreenInstruction::ScrollDownAt(point))
.unwrap();
}
Action::ScrollToBottom => {
session
.senders
.send_to_screen(ScreenInstruction::ScrollToBottom)
.unwrap();
}
Action::PageScrollUp => {
session
.senders

View File

@ -50,6 +50,7 @@ pub(crate) enum ScreenInstruction {
ScrollUpAt(Position),
ScrollDown,
ScrollDownAt(Position),
ScrollToBottom,
PageScrollUp,
PageScrollDown,
ClearScroll,
@ -103,6 +104,7 @@ impl From<&ScreenInstruction> for ScreenContext {
ScreenInstruction::Exit => ScreenContext::Exit,
ScreenInstruction::ScrollUp => ScreenContext::ScrollUp,
ScreenInstruction::ScrollDown => ScreenContext::ScrollDown,
ScreenInstruction::ScrollToBottom => ScreenContext::ScrollToBottom,
ScreenInstruction::PageScrollUp => ScreenContext::PageScrollUp,
ScreenInstruction::PageScrollDown => ScreenContext::PageScrollDown,
ScreenInstruction::ClearScroll => ScreenContext::ClearScroll,
@ -569,6 +571,12 @@ pub(crate) fn screen_thread_main(
.unwrap()
.scroll_terminal_down(&point, 3);
}
ScreenInstruction::ScrollToBottom => {
screen
.get_active_tab_mut()
.unwrap()
.scroll_active_terminal_to_bottom();
}
ScreenInstruction::PageScrollUp => {
screen
.get_active_tab_mut()

View File

@ -2280,6 +2280,16 @@ impl Tab {
self.render();
}
}
pub fn scroll_active_terminal_to_bottom(&mut self) {
if let Some(active_terminal_id) = self.get_active_terminal_id() {
let active_terminal = self
.panes
.get_mut(&PaneId::Terminal(active_terminal_id))
.unwrap();
active_terminal.clear_scroll();
self.render();
}
}
pub fn clear_active_terminal_scroll(&mut self) {
if let Some(active_terminal_id) = self.get_active_terminal_id() {
let active_terminal = self

View File

@ -178,6 +178,8 @@ keybinds:
key: [Ctrl: 'p',]
- action: [SwitchToMode: Session,]
key: [Ctrl: 'o',]
- action: [ScrollToBottom, SwitchToMode: Normal,]
key: [Ctrl: 'c',]
- action: [Quit,]
key: [Ctrl: 'q',]
- action: [ScrollDown,]

View File

@ -202,6 +202,7 @@ pub enum ScreenContext {
ScrollUpAt,
ScrollDown,
ScrollDownAt,
ScrollToBottom,
PageScrollUp,
PageScrollDown,
ClearScroll,

View File

@ -48,6 +48,8 @@ pub enum Action {
ScrollDown,
/// Scroll down at point
ScrollDownAt(Position),
/// Scroll down to bottom in focus pane.
ScrollToBottom,
/// Scroll up one page in focus pane.
PageScrollUp,
/// Scroll down one page in focus pane.