Skip to content

Commit

Permalink
Merge branch 'main' into multi-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 authored Sep 19, 2024
2 parents ce41fe3 + 197f359 commit 1c932fa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
4 changes: 2 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license.workspace = true
[dependencies]
include_dir = "0.7.4"
tempdir = "0.3.7"
serde = { version = "1.0.205", features = ["derive"] }
toml = "0.8.19"
serde = { version = "1.0.205", features = ["derive"], default-features = false }
toml = { version = "0.8.19", features = ["parse"], default-features = false }
which = "6.0.3"
ego-tree = { workspace = true }
9 changes: 6 additions & 3 deletions tui/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
hints.push(Shortcut::new(vec!["q", "CTRL-c"], "Exit linutil"));

if state.at_root() {
hints.push(Shortcut::new(vec!["h", "Left", "Tab"], "Focus tab list"));
hints.push(Shortcut::new(vec!["h", "Left"], "Focus tab list"));
hints.push(get_list_item_shortcut(state));
} else {
if state.selected_item_is_up_dir() {
Expand All @@ -136,7 +136,6 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
hints.push(Shortcut::new(vec!["d"], "Command Description"));
}
}
hints.push(Shortcut::new(vec!["Tab"], "Focus tab list"));
};

hints.push(Shortcut::new(vec!["k", "Up"], "Select item above"));
Expand All @@ -147,6 +146,8 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
hints.push(Shortcut::new(vec!["v"], "Toggle multi-selection mode"));
hints.push(Shortcut::new(vec!["Space"], "Select multiple commands"));
}
hints.push(Shortcut::new(vec!["Tab"], "Next tab"));
hints.push(Shortcut::new(vec!["Shift-Tab"], "Previous tab"));
ShortcutList {
scope_name: "Item list",
hints,
Expand All @@ -157,11 +158,13 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) {
scope_name: "Tab list",
hints: vec![
Shortcut::new(vec!["q", "CTRL-c"], "Exit linutil"),
Shortcut::new(vec!["l", "Right", "Tab", "Enter"], "Focus action list"),
Shortcut::new(vec!["l", "Right", "Enter"], "Focus action list"),
Shortcut::new(vec!["k", "Up"], "Select item above"),
Shortcut::new(vec!["j", "Down"], "Select item below"),
Shortcut::new(vec!["t"], "Next theme"),
Shortcut::new(vec!["T"], "Previous theme"),
Shortcut::new(vec!["Tab"], "Next tab"),
Shortcut::new(vec!["Shift-Tab"], "Previous tab"),
],
},

Expand Down
30 changes: 26 additions & 4 deletions tui/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,31 @@ impl AppState {
return true;
}

// Handle key only when Tablist or List is focused
// Prevents exiting the application even when a command is running
// Add keys here which should work on both TabList and List
if matches!(self.focus, Focus::TabList | Focus::List) {
match key.code {
KeyCode::Tab => {
if self.current_tab.selected().unwrap() == self.tabs.len() - 1 {
self.current_tab.select_first(); // Select first tab when it is at last
} else {
self.current_tab.select_next();
}
self.refresh_tab();
}
KeyCode::BackTab => {
if self.current_tab.selected().unwrap() == 0 {
self.current_tab.select(Some(self.tabs.len() - 1)); // Select last tab when it is at first
} else {
self.current_tab.select_previous();
}
self.refresh_tab();
}
_ => {}
}
}

match &mut self.focus {
Focus::FloatingWindow(command) => {
if command.handle_key_event(key) {
Expand All @@ -293,9 +318,7 @@ impl AppState {
}

Focus::TabList => match key.code {
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right | KeyCode::Tab => {
self.focus = Focus::List
}
KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => self.focus = Focus::List,

KeyCode::Char('j') | KeyCode::Down
if self.current_tab.selected().unwrap() + 1 < self.tabs.len() =>
Expand Down Expand Up @@ -329,7 +352,6 @@ impl AppState {
}
}
KeyCode::Char('/') => self.enter_search(),
KeyCode::Tab => self.focus = Focus::TabList,
KeyCode::Char('t') => self.theme.next(),
KeyCode::Char('T') => self.theme.prev(),
KeyCode::Char('v') | KeyCode::Char('V') => self.toggle_multi_select(),
Expand Down

0 comments on commit 1c932fa

Please sign in to comment.