Skip to content

Commit

Permalink
(WIP) feat: scrollable file preview
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-Sky committed Apr 27, 2024
1 parent 64a1e38 commit 9128f1c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/components/revision_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ impl Component for RevisionFilesComponent {
)
.order(order::RARE_ACTION),
);
out.push(CommandInfo::new(
strings::commands::seek(&self.key_config),
self.tree.selected_file().is_some(),
true,
));
tree_nav_cmds(&self.tree, &self.key_config, out);
} else {
self.current_file.commands(out, force_all);
Expand Down Expand Up @@ -495,6 +500,22 @@ impl Component for RevisionFilesComponent {
self.focus(false);
return Ok(EventState::Consumed);
}
} else if key_match(key, self.key_config.keys.seek_up)
|| key_match(key, self.key_config.keys.seek_down)
{
if is_tree_focused {
if let Some(nav) =
common_nav(key, &self.key_config)
{
return Ok(
if self.current_file.scroll(nav) {
EventState::Consumed
} else {
EventState::NotConsumed
},
);
}
}
} else if key_match(key, self.key_config.keys.file_find) {
if is_tree_focused {
self.open_finder();
Expand Down
2 changes: 1 addition & 1 deletion src/components/syntax_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl SyntaxTextComponent {
}
}

fn scroll(&self, nav: MoveSelection) -> bool {
pub(in crate::components) fn scroll(&self, nav: MoveSelection) -> bool {
let state = self.paragraph_state.get();

let new_scroll_pos = match nav {
Expand Down
4 changes: 4 additions & 0 deletions src/keys/key_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub struct KeysList {
pub move_right: GituiKeyEvent,
pub move_up: GituiKeyEvent,
pub move_down: GituiKeyEvent,
pub seek_up: GituiKeyEvent,
pub seek_down: GituiKeyEvent,
pub tree_collapse_recursive: GituiKeyEvent,
pub tree_expand_recursive: GituiKeyEvent,
pub home: GituiKeyEvent,
Expand Down Expand Up @@ -152,6 +154,8 @@ impl Default for KeysList {
end: GituiKeyEvent::new(KeyCode::End, KeyModifiers::empty()),
move_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::empty()),
move_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::empty()),
seek_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::ALT),
seek_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::ALT),
popup_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::empty()),
popup_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::empty()),
page_down: GituiKeyEvent::new(KeyCode::PageDown, KeyModifiers::empty()),
Expand Down
11 changes: 11 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,17 @@ pub mod commands {
CMD_GROUP_GENERAL,
)
}
pub fn seek(key_config: &SharedKeyConfig) -> CommandText {
CommandText::new(
format!(
"Seek [{}{}]",
key_config.get_hint(key_config.keys.seek_up),
key_config.get_hint(key_config.keys.seek_down)
),
"Seek up or down in selected file",
CMD_GROUP_GENERAL,
)
}
pub fn commit_list_mark(
key_config: &SharedKeyConfig,
marked: bool,
Expand Down
4 changes: 4 additions & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ pub fn common_nav(
Some(MoveSelection::Down)
} else if key_match(key, key_config.keys.move_up) {
Some(MoveSelection::Up)
} else if key_match(key, key_config.keys.seek_up) {
Some(MoveSelection::Up)
} else if key_match(key, key_config.keys.seek_down) {
Some(MoveSelection::Down)
} else if key_match(key, key_config.keys.page_up) {
Some(MoveSelection::PageUp)
} else if key_match(key, key_config.keys.page_down) {
Expand Down

0 comments on commit 9128f1c

Please sign in to comment.