diff --git a/src/main.rs b/src/main.rs index 0946488..1b1aabf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -309,6 +309,7 @@ struct State { current_source_file: Option, current_source_line: Option, source_lines: Vec, + source_scroll: Scroll, /// Current source language detected by GDB source_language: Option, /// Symbol browser @@ -365,6 +366,7 @@ impl State { current_source_file: None, current_source_line: None, source_lines: Vec::new(), + source_scroll: Scroll::default(), source_language: None, symbols: Vec::new(), symbols_scroll: Scroll::default(), @@ -1192,6 +1194,34 @@ fn run_app( state.symbols_scroll.reset(); } } + // source scrolling + (InputMode::Normal, KeyCode::Char('g'), Mode::OnlySource) => { + let mut state = state_share.state.lock().unwrap(); + state.source_scroll.reset(); + } + (InputMode::Normal, KeyCode::Char('G'), Mode::OnlySource) => { + let mut state = state_share.state.lock().unwrap(); + let len = state.source_lines.len(); + state.source_scroll.end(len); + } + (InputMode::Normal, KeyCode::Char('j'), Mode::OnlySource) => { + let mut state = state_share.state.lock().unwrap(); + let len = state.source_lines.len(); + state.source_scroll.down(1, len); + } + (InputMode::Normal, KeyCode::Char('k'), Mode::OnlySource) => { + let mut state = state_share.state.lock().unwrap(); + state.source_scroll.up(1); + } + (InputMode::Normal, KeyCode::Char('J'), Mode::OnlySource) => { + let mut state = state_share.state.lock().unwrap(); + let len = state.source_lines.len(); + state.source_scroll.down(50, len); + } + (InputMode::Normal, KeyCode::Char('K'), Mode::OnlySource) => { + let mut state = state_share.state.lock().unwrap(); + state.source_scroll.up(50); + } (_, KeyCode::Tab, _) => { let mut state = state_share.state.lock().unwrap(); completion(app, &mut state)?; diff --git a/src/ui/source.rs b/src/ui/source.rs index d2d0c1b..2311958 100644 --- a/src/ui/source.rs +++ b/src/ui/source.rs @@ -33,14 +33,10 @@ pub fn draw_source(state: &mut State, f: &mut Frame, area: Rect) { let current_line = state.current_source_line.unwrap() as usize; let total_lines = state.source_lines.len(); - // Calculate which lines to show (center the current line in the view) + // Calculate which lines to show based on scroll position // Account for borders and title let lines_to_show = (area.height as usize).saturating_sub(3); - let start_line = if current_line > lines_to_show / 2 { - (current_line.saturating_sub(lines_to_show / 2)).saturating_sub(1) - } else { - 0 - }; + let start_line = state.source_scroll.scroll.min(total_lines.saturating_sub(1)); let end_line = (start_line + lines_to_show).min(total_lines); let theme = arborium::theme::builtin::ayu_dark();