Skip to content

Commit 93a0c63

Browse files
committed
feat: scrollable file preview in Files
1 parent 64a1e38 commit 93a0c63

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

src/components/revision_files.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
queue::{InternalEvent, Queue, StackablePopupOpen},
1111
strings::{self, order, symbol},
1212
try_or_popup,
13-
ui::{self, common_nav, style::SharedTheme},
13+
ui::{self, common_nav, key2seek, style::SharedTheme},
1414
AsyncNotification,
1515
};
1616
use anyhow::Result;
@@ -444,6 +444,11 @@ impl Component for RevisionFilesComponent {
444444
)
445445
.order(order::RARE_ACTION),
446446
);
447+
out.push(CommandInfo::new(
448+
strings::commands::seek(&self.key_config),
449+
self.tree.selected_file().is_some(),
450+
true,
451+
));
447452
tree_nav_cmds(&self.tree, &self.key_config, out);
448453
} else {
449454
self.current_file.commands(out, force_all);
@@ -480,6 +485,21 @@ impl Component for RevisionFilesComponent {
480485
self.hide();
481486
return Ok(EventState::Consumed);
482487
}
488+
} else if key_match(key, self.key_config.keys.seek_up)
489+
|| key_match(key, self.key_config.keys.seek_down)
490+
{
491+
if is_tree_focused {
492+
if let Some(nav) = key2seek(key, &self.key_config)
493+
{
494+
return Ok(
495+
if self.current_file.scroll(nav) {
496+
EventState::Consumed
497+
} else {
498+
EventState::NotConsumed
499+
},
500+
);
501+
}
502+
}
483503
} else if key_match(key, self.key_config.keys.move_right)
484504
{
485505
if is_tree_focused {

src/components/syntax_text.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl SyntaxTextComponent {
135135
}
136136
}
137137

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

141141
let new_scroll_pos = match nav {

src/keys/key_list.rs

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub struct KeysList {
5656
pub move_right: GituiKeyEvent,
5757
pub move_up: GituiKeyEvent,
5858
pub move_down: GituiKeyEvent,
59+
pub seek_up: GituiKeyEvent,
60+
pub seek_down: GituiKeyEvent,
5961
pub tree_collapse_recursive: GituiKeyEvent,
6062
pub tree_expand_recursive: GituiKeyEvent,
6163
pub home: GituiKeyEvent,
@@ -152,6 +154,8 @@ impl Default for KeysList {
152154
end: GituiKeyEvent::new(KeyCode::End, KeyModifiers::empty()),
153155
move_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::empty()),
154156
move_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::empty()),
157+
seek_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::ALT),
158+
seek_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::ALT),
155159
popup_up: GituiKeyEvent::new(KeyCode::Up, KeyModifiers::empty()),
156160
popup_down: GituiKeyEvent::new(KeyCode::Down, KeyModifiers::empty()),
157161
page_down: GituiKeyEvent::new(KeyCode::PageDown, KeyModifiers::empty()),

src/strings.rs

+11
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,17 @@ pub mod commands {
546546
CMD_GROUP_GENERAL,
547547
)
548548
}
549+
pub fn seek(key_config: &SharedKeyConfig) -> CommandText {
550+
CommandText::new(
551+
format!(
552+
"Seek [{}{}]",
553+
key_config.get_hint(key_config.keys.seek_up),
554+
key_config.get_hint(key_config.keys.seek_down)
555+
),
556+
"Seek up or down in selected file",
557+
CMD_GROUP_GENERAL,
558+
)
559+
}
549560
pub fn commit_list_mark(
550561
key_config: &SharedKeyConfig,
551562
marked: bool,

src/ui/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ pub fn common_nav(
153153
}
154154
}
155155

156+
pub fn key2seek(
157+
key: &crossterm::event::KeyEvent,
158+
key_config: &SharedKeyConfig,
159+
) -> Option<MoveSelection> {
160+
if key_match(key, key_config.keys.seek_up) {
161+
Some(MoveSelection::Up)
162+
} else if key_match(key, key_config.keys.seek_down) {
163+
Some(MoveSelection::Down)
164+
} else {
165+
None
166+
}
167+
}
168+
156169
#[cfg(test)]
157170
mod test {
158171
use super::{rect_inside, Size};

0 commit comments

Comments
 (0)