Skip to content
Open
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
30 changes: 30 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ struct State {
current_source_file: Option<String>,
current_source_line: Option<u32>,
source_lines: Vec<String>,
source_scroll: Scroll,
/// Current source language detected by GDB
source_language: Option<String>,
/// Symbol browser
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -1192,6 +1194,34 @@ fn run_app<B: Backend>(
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)?;
Expand Down
8 changes: 2 additions & 6 deletions src/ui/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down