Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add closing all left tabs (normal mode - tXh) #104

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
6 changes: 5 additions & 1 deletion core/src/state/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ impl NotebookState {
]
}
EditingNormalMode(VimNormalState::ToggleTabClose) => {
vec!["[l] Close right tabs".to_owned(), "[Esc] Cancel".to_owned()]
vec![
"[h] Close left tabs".to_owned(),
"[l] Close right tabs".to_owned(),
"[Esc] Cancel".to_owned(),
]
}
EditingNormalMode(VimNormalState::Numbering(n)) => {
// h j k l [0-9] s S x y d w e b G
Expand Down
18 changes: 14 additions & 4 deletions core/src/state/notebook/inner_state/editing_normal_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,26 @@ async fn consume_toggle_tab_close(

match event {
Key(KeyEvent::L) => {
let i = state
.tab_index
.ok_or(Error::Wip("todo: tab index must exist".to_owned()))?
+ 1;
let i = state.tab_index.ok_or(Error::Wip(
"[ToggleTabClose::L] tab index must exist".to_owned(),
))? + 1;

state.tabs.splice(i.., []);
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);

CloseRightTabs(i).into()
}
Key(KeyEvent::H) => {
let i = state.tab_index.ok_or(Error::Wip(
"[ToggleTabClose::H] tab index must exist".to_owned(),
))?;

state.tab_index = Some(0);
state.tabs.splice(..i, []);
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);

CloseLeftTabs(i).into()
}
event @ Key(_) => {
state.inner_state = InnerState::EditingNormalMode(VimNormalState::Idle);

Expand Down
1 change: 1 addition & 0 deletions core/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub enum NormalModeTransition {

// toggle tab close mode
CloseRightTabs(usize),
CloseLeftTabs(usize),

MoveCursorDown(usize),
MoveCursorUp(usize),
Expand Down
3 changes: 3 additions & 0 deletions tui/src/transitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ impl App {
CloseRightTabs(index) => {
self.context.notebook.tabs.splice(index.., []);
}
CloseLeftTabs(index) => {
self.context.notebook.tabs.splice(..index, []);
}
ToggleLineNumbers => {
self.context.notebook.show_line_number = !self.context.notebook.show_line_number;
}
Expand Down
Loading