vim: Add gt and gT bindings for Markdown preview mode (#39854)
### What does this PR do? - Adds default keybindings `gt` for navigating to the next tab and `gT` for navigating to the previous tab in markdown viewer mode ### Why do we need this change? - While previewing markdown files, the default vim bindings (`gt` and `gT`) do not work for navigating between tabs. These bindings work everywhere else, which provides a non-consistent experience for the user. ### How do we do this change? - Update the vim mode bindings to explicitly add handling for this mode --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
co-authored by
Conrad Irwin
parent
5939cae6fa
commit
35f5eb1fe7
+44
-1
@@ -51,7 +51,10 @@ use vim_mode_setting::HelixModeSetting;
|
||||
use vim_mode_setting::VimModeSetting;
|
||||
use workspace::{self, Pane, Workspace};
|
||||
|
||||
use crate::state::ReplayableAction;
|
||||
use crate::{
|
||||
normal::{GoToPreviousTab, GoToTab},
|
||||
state::ReplayableAction,
|
||||
};
|
||||
|
||||
/// Number is used to manage vim's count. Pushing a digit
|
||||
/// multiplies the current value by 10 and adds the digit.
|
||||
@@ -409,6 +412,46 @@ pub fn init(cx: &mut App) {
|
||||
cx.defer_in(window, |vim, window, cx| vim.search_submit(window, cx))
|
||||
})
|
||||
});
|
||||
workspace.register_action(|_, _: &GoToTab, window, cx| {
|
||||
let count = Vim::take_count(cx);
|
||||
Vim::take_forced_motion(cx);
|
||||
|
||||
if let Some(tab_index) = count {
|
||||
// <count>gt goes to tab <count> (1-based).
|
||||
let zero_based_index = tab_index.saturating_sub(1);
|
||||
window.dispatch_action(
|
||||
workspace::pane::ActivateItem(zero_based_index).boxed_clone(),
|
||||
cx,
|
||||
);
|
||||
} else {
|
||||
// If no count is provided, go to the next tab.
|
||||
window.dispatch_action(workspace::pane::ActivateNextItem.boxed_clone(), cx);
|
||||
}
|
||||
});
|
||||
|
||||
workspace.register_action(|workspace, _: &GoToPreviousTab, window, cx| {
|
||||
let count = Vim::take_count(cx);
|
||||
Vim::take_forced_motion(cx);
|
||||
|
||||
if let Some(count) = count {
|
||||
// gT with count goes back that many tabs with wraparound (not the same as gt!).
|
||||
let pane = workspace.active_pane().read(cx);
|
||||
let item_count = pane.items().count();
|
||||
if item_count > 0 {
|
||||
let current_index = pane.active_item_index();
|
||||
let target_index = (current_index as isize - count as isize)
|
||||
.rem_euclid(item_count as isize)
|
||||
as usize;
|
||||
window.dispatch_action(
|
||||
workspace::pane::ActivateItem(target_index).boxed_clone(),
|
||||
cx,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// No count provided, go to the previous tab.
|
||||
window.dispatch_action(workspace::pane::ActivatePreviousItem.boxed_clone(), cx);
|
||||
}
|
||||
});
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user