1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-21 11:50:42 +03:00

palette: exclude copy mode actions unless copy mode is active

This commit is contained in:
Wez Furlong 2023-03-25 18:10:00 -07:00
parent 1c55ca14b0
commit 500934bc9c
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387

View File

@ -75,9 +75,17 @@ fn save_recent(command: &ExpandedCommand) -> anyhow::Result<()> {
Ok(()) Ok(())
} }
fn build_commands() -> Vec<ExpandedCommand> { fn build_commands(filter_copy_mode: bool) -> Vec<ExpandedCommand> {
let mut commands = CommandDef::actions_for_palette_and_menubar(&config::configuration()); let mut commands = CommandDef::actions_for_palette_and_menubar(&config::configuration());
commands.retain(|cmd| {
if filter_copy_mode {
!matches!(cmd.action, KeyAssignment::CopyMode(_))
} else {
true
}
});
let mut scores: HashMap<&str, f64> = HashMap::new(); let mut scores: HashMap<&str, f64> = HashMap::new();
let recents = load_recents(); let recents = load_recents();
if let Ok(recents) = &recents { if let Ok(recents) = &recents {
@ -156,8 +164,18 @@ fn compute_matches(selection: &str, commands: &[ExpandedCommand]) -> Vec<usize>
} }
impl CommandPalette { impl CommandPalette {
pub fn new(_term_window: &mut TermWindow) -> Self { pub fn new(term_window: &mut TermWindow) -> Self {
let commands = build_commands(); // Showing the CopyMode actions in the palette is useless
// if the CopyOverlay isn't active, so figure out if that
// is the case so that we can filter them out in build_commands.
let filter_copy_mode = term_window
.get_active_pane_or_overlay()
.map(|pane| {
pane.downcast_ref::<crate::termwindow::CopyOverlay>()
.is_none()
})
.unwrap_or(true);
let commands = build_commands(filter_copy_mode);
Self { Self {
element: RefCell::new(None), element: RefCell::new(None),