A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
fix(keymap): address review findings in Settings → Keymap
RoversX654ec6f92cda
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftlindex d4d9dae0..6eda6e0c 100644--- a/thinkterm-i18n/i18n/de-DE.ftl+++ b/thinkterm-i18n/i18n/de-DE.ftl@@ -51,7 +51,6 @@ settings-section-developer = Entwicklersettings-section-about = Übersettings-search-placeholder = Suchensettings-search-no-results = Keine Einstellungen gefunden-settings-keymap-description = Tastenkürzel und Aktionen der Befehlspalette.settings-keymap-search-placeholder = Aktionen suchensettings-keymap-cap-system = Systemsettings-keymap-cap-programs = Shell@@ -85,6 +84,7 @@ settings-keymap-cap-removed = Entferntsettings-keymap-removed = Das Tastenkürzel auf dieser Taste wurde entferntsettings-keymap-taken-programs = Die Shell und Programme im Terminal verwenden { $chord }.settings-keymap-use-anyway = Trotzdem verwenden+settings-keymap-lua-callback = Dieses Tastenkürzel führt eine Funktion aus thinkterm.lua aus, die nur thinkterm.lua festhalten kann; ändern Sie es dort.settings-about-description = ThinkTerm-Version, Build-Details, Projektlinks und Speicherorte der Dateien.settings-general-heading = Konfigurationsettings-general-session-heading = Sitzungsserverdiff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftlindex d0940e0d..e4deaab8 100644--- a/thinkterm-i18n/i18n/en-US.ftl+++ b/thinkterm-i18n/i18n/en-US.ftl@@ -51,7 +51,6 @@ settings-section-developer = Developersettings-section-about = Aboutsettings-search-placeholder = Searchsettings-search-no-results = No settings found-settings-keymap-description = Keyboard shortcuts and command palette actions.settings-keymap-search-placeholder = Search actionssettings-keymap-cap-system = Systemsettings-keymap-cap-programs = Shell@@ -85,6 +84,7 @@ settings-keymap-cap-removed = Removedsettings-keymap-removed = Its shortcut was removedsettings-keymap-taken-programs = The shell and programs in the terminal use { $chord }.settings-keymap-use-anyway = Use Anyway+settings-keymap-lua-callback = This shortcut runs a function from thinkterm.lua, which only thinkterm.lua can keep; change it there.settings-about-description = ThinkTerm version, build details, project links, and where its files live.settings-general-heading = Configurationsettings-general-session-heading = Session serverdiff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftlindex a864862e..74b7a713 100644--- a/thinkterm-i18n/i18n/fr-FR.ftl+++ b/thinkterm-i18n/i18n/fr-FR.ftl@@ -51,7 +51,6 @@ settings-section-developer = Développeursettings-section-about = À propossettings-search-placeholder = Recherchersettings-search-no-results = Aucun réglage trouvé-settings-keymap-description = Raccourcis clavier et actions de la palette de commandes.settings-keymap-search-placeholder = Rechercher une actionsettings-keymap-cap-system = Systèmesettings-keymap-cap-programs = Shell@@ -85,6 +84,7 @@ settings-keymap-cap-removed = Supprimésettings-keymap-removed = Le raccourci de cette touche a été supprimésettings-keymap-taken-programs = Le shell et les programmes du terminal utilisent { $chord }.settings-keymap-use-anyway = Utiliser quand même+settings-keymap-lua-callback = Ce raccourci exécute une fonction de thinkterm.lua, que seul thinkterm.lua peut conserver ; modifiez-le là-bas.settings-about-description = Version de ThinkTerm, détails de compilation, liens du projet et emplacement de ses fichiers.settings-general-heading = Configurationsettings-general-session-heading = Serveur de sessionsdiff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftlindex 1eccdada..2989f91e 100644--- a/thinkterm-i18n/i18n/ja-JP.ftl+++ b/thinkterm-i18n/i18n/ja-JP.ftl@@ -48,7 +48,6 @@ settings-section-developer = 開発者settings-section-about = 情報settings-search-placeholder = 検索settings-search-no-results = 設定が見つかりません-settings-keymap-description = キーボードショートカットとコマンドパレットのアクションです。settings-keymap-search-placeholder = アクションを検索settings-keymap-cap-system = システムsettings-keymap-cap-programs = シェル@@ -82,6 +81,7 @@ settings-keymap-cap-removed = 削除済みsettings-keymap-removed = このキーのショートカットは削除されていますsettings-keymap-taken-programs = { $chord } はシェルやターミナル内のプログラムが使います。settings-keymap-use-anyway = それでも使う+settings-keymap-lua-callback = このショートカットは thinkterm.lua の関数を実行します。関数は thinkterm.lua にしか保存できないため、そちらで変更してください。settings-about-description = ThinkTerm のバージョン、ビルド情報、プロジェクトのリンク、ファイルの場所です。settings-general-heading = 構成settings-general-session-heading = セッションサーバーdiff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftlindex dea261c2..c27fcbc2 100644--- a/thinkterm-i18n/i18n/zh-CN.ftl+++ b/thinkterm-i18n/i18n/zh-CN.ftl@@ -48,7 +48,6 @@ settings-section-developer = 开发者settings-section-about = 关于settings-search-placeholder = 搜索settings-search-no-results = 未找到设置-settings-keymap-description = 键盘快捷键和命令面板操作。settings-keymap-search-placeholder = 搜索动作settings-keymap-cap-system = 系统settings-keymap-cap-programs = Shell@@ -82,6 +81,7 @@ settings-keymap-cap-removed = 已删除settings-keymap-removed = 这个键上的快捷键已删除settings-keymap-taken-programs = Shell 和终端里的程序会用到 { $chord }。settings-keymap-use-anyway = 仍然使用+settings-keymap-lua-callback = 这个快捷键运行的是 thinkterm.lua 里的函数,函数只能保存在 thinkterm.lua 里,请在那里修改。settings-about-description = ThinkTerm 的版本、构建信息、项目链接,以及文件所在位置。settings-general-heading = 配置settings-general-session-heading = 后台会话diff --git a/wezterm-gui/src/inputmap.rs b/wezterm-gui/src/inputmap.rsindex faa9802f..d945060a 100644--- a/wezterm-gui/src/inputmap.rs+++ b/wezterm-gui/src/inputmap.rs@@ -110,25 +110,23 @@ impl InputMap {// Every ThinkTerm action can be reached from the palette, so with// the defaults disabled it keeps its own chords -- unless another- // chord opens it, or one of those was bound or freed on purpose.+ // chord opens it. Each is kept unless it was bound or freed on+ // purpose: one taken leaves the other.if config.disable_default_key_bindings&& !keys.default.values().any(|entry| entry.action == KeyAssignment::ActivateCommandPalette){- let chords = default_chords(&KeyAssignment::ActivateCommandPalette);- let taken = chords.iter().any(|(code, mods)| {- chord_forms(code, *mods)+ for (code, mods) in default_chords(&KeyAssignment::ActivateCommandPalette) {+ let taken = chord_forms(&code, mods).iter()- .any(|form| keys.default.contains_key(form))- });- if !taken {- for (code, mods) in &chords {+ .any(|form| keys.default.contains_key(form));+ if !taken {insert_in_every_form(&mut keys.default,- code,- *mods,+ &code,+ mods,&KeyAssignment::ActivateCommandPalette,config.key_map_preference,);@@ -673,6 +671,32 @@ pub(crate) fn canonical_chord(key: &KeyCode, mods: Modifiers) -> (KeyCode, Modifkey.normalize_shift(mods)}+/// The chord a key press records in Settings → Keymap: `canonical_chord`,+/// which names a symbol by the key that types it on a US layout, as the+/// drawn keyboard and the defaults name it -- unless the keyboard pressed+/// types some other symbol on that key. Then the US name would be another+/// key's: ⇧7 types "/" on a German layout and ⇧ß types "?", which a US+/// layout types with ⇧/, so the two keys would be one shortcut, and each+/// would take the other's spellings. Such a chord is kept as the physical+/// key pressed, which no other key shares and which is looked up first.+pub(crate) fn recorded_chord(+ phys: Option<PhysKeyCode>,+ key: &KeyCode,+ mods: Modifiers,+) -> (KeyCode, Modifiers) {+ if let (Some(phys), KeyCode::Char(c)) = (phys, key) {+ let symbol = !c.is_ascii_alphanumeric() && !c.is_control() && *c != ' ';+ if symbol {+ if let KeyCode::Char(base) = phys.to_key_code() {+ if *c != base && us_shifted(base) != Some(*c) {+ return (KeyCode::Physical(phys), mods.remove_positional_mods());+ }+ }+ }+ }+ canonical_chord(key, mods)+}+/// The key that types `c` with Shift on a US layout: "!" for "1".pub(crate) fn us_shifted(c: char) -> Option<char> {US_SHIFTED@@ -681,14 +705,21 @@ pub(crate) fn us_shifted(c: char) -> Option<char> {.map(|(_, shifted)| *shifted)}-/// Every form the key table may be asked for a chord in: the canonical one;-/// for a shifted symbol, the symbol with and without Shift, as platforms-/// report it either way; and the physical key, whose bindings are looked up-/// before the typed ones.+/// Every form the key table may be asked for a chord in, in the order a key+/// press looks them up: the physical key, whose bindings are tried first;+/// the canonical one; and for a shifted symbol, the symbol with and without+/// Shift, as platforms report it either way.pub(crate) fn chord_forms(key: &KeyCode, mods: Modifiers) -> Vec<(KeyCode, Modifiers)> {let canonical = canonical_chord(key, mods);let (typed_key, typed_mods) = typed_chord(&canonical.0, canonical.1);- let mut forms = vec![canonical];+ let mut forms = vec![];+ if let Some(phys) = typed_key.to_phys() {+ let physical = (KeyCode::Physical(phys), typed_mods);+ if physical != canonical {+ forms.push(physical);+ }+ }+ forms.push(canonical);if let KeyCode::Char(c) = typed_key {if typed_mods.contains(Modifiers::SHIFT) {if let Some(shifted) = us_shifted(c) {@@ -697,18 +728,16 @@ pub(crate) fn chord_forms(key: &KeyCode, mods: Modifiers) -> Vec<(KeyCode, Modif}}}- if let Some(phys) = typed_key.to_phys() {- forms.push((KeyCode::Physical(phys), typed_mods));- }forms}/// Bind `action` in `table` in every form a key event for the chord may be/// looked up in, so it wins over the shifted-symbol spellings of the same-/// keys. The physical form is taken only where a physical binding would-/// otherwise win: under `key_map_preference = "Physical"`, or where the-/// table already binds it. Elsewhere it would take a key by its US position-/// on a layout that types something else there.+/// keys. The physical form of a typed chord is taken only where a physical+/// binding would otherwise win: under `key_map_preference = "Physical"`, or+/// where the table already binds it. Elsewhere it would take a key by its+/// US position on a layout that types something else there. A chord that+/// is a physical key (`recorded_chord`) is bound as one.fn insert_in_every_form(table: &mut config::keyassignment::KeyTable,key: &KeyCode,@@ -716,9 +745,11 @@ fn insert_in_every_form(action: &KeyAssignment,preference: config::KeyMapPreference,) {+ let chord_is_physical = matches!(key, KeyCode::Physical(_));for form in chord_forms(key, mods) {let physical = matches!(form.0, KeyCode::Physical(_));if physical+ && !chord_is_physical&& preference != config::KeyMapPreference::Physical&& !table.contains_key(&form){@@ -1272,6 +1303,81 @@ mod tests {);}+ #[test]+ fn another_layouts_symbol_is_kept_as_the_key_pressed() {+ let shift_cmd = Modifiers::SUPER | Modifiers::SHIFT;+ // A US layout: the symbol is named by the key that types it.+ for typed in ['?', '/'] {+ assert_eq!(+ recorded_chord(Some(PhysKeyCode::Slash), &KeyCode::Char(typed), shift_cmd),+ canonical_chord(&KeyCode::Char(typed), shift_cmd)+ );+ }+ // German: ⇧7 types "/" and ⇧ß types "?". Two keys, two shortcuts,+ // neither of them ⇧/.+ let seven = recorded_chord(Some(PhysKeyCode::K7), &KeyCode::Char('/'), shift_cmd);+ let eszett = recorded_chord(Some(PhysKeyCode::Minus), &KeyCode::Char('?'), shift_cmd);+ assert_eq!(seven, (KeyCode::Physical(PhysKeyCode::K7), shift_cmd));+ assert_eq!(eszett, (KeyCode::Physical(PhysKeyCode::Minus), shift_cmd));+ assert_ne!(seven, canonical_chord(&KeyCode::Char('?'), shift_cmd));+ // Letters and digits keep their names, as the drawn keyboard has them.+ assert_eq!(+ recorded_chord(Some(PhysKeyCode::Q), &KeyCode::Char('a'), Modifiers::SUPER),+ canonical_chord(&KeyCode::Char('a'), Modifiers::SUPER)+ );+ // Without a physical key, as before.+ assert_eq!(+ recorded_chord(None, &KeyCode::Char('?'), shift_cmd),+ canonical_chord(&KeyCode::Char('?'), shift_cmd)+ );++ // Bound as the physical key, and only as it.+ let map = InputMap::with_keymap(+ &ConfigHandle::default_config(),+ &[KeymapEntry {+ key: seven.0.clone(),+ mods: seven.1,+ action: KeyAssignment::OpenThreadSearch,+ }],+ );+ assert_eq!(+ map.lookup_key(&seven.0, seven.1, None).map(|entry| entry.action),+ Some(KeyAssignment::OpenThreadSearch)+ );+ assert_ne!(+ map.lookup_key(&KeyCode::Char('?'), shift_cmd, None)+ .map(|entry| entry.action),+ Some(KeyAssignment::OpenThreadSearch)+ );+ }++ #[test]+ fn a_default_palette_chord_taken_leaves_the_other() {+ let config = ConfigHandle::default_config()+ .adjusted(|config| config.disable_default_key_bindings = true);+ let chords = default_chords(&KeyAssignment::ActivateCommandPalette);+ if chords.len() < 2 {+ return;+ }+ let (taken, kept) = (&chords[0], &chords[1]);+ let map = InputMap::with_keymap(+ &config,+ &[KeymapEntry {+ key: taken.0.clone(),+ mods: taken.1,+ action: KeyAssignment::OpenThreadSearch,+ }],+ );+ assert_eq!(+ map.lookup_key(&kept.0, kept.1, None).map(|entry| entry.action),+ Some(KeyAssignment::ActivateCommandPalette)+ );+ assert_eq!(+ map.lookup_key(&taken.0, taken.1, None).map(|entry| entry.action),+ Some(KeyAssignment::OpenThreadSearch)+ );+ }+#[test]fn config_key_names_parse_back_to_their_key() {use std::convert::TryFrom;@@ -1290,7 +1396,13 @@ mod tests {KeyCode::LeftArrow,KeyCode::PageUp,KeyCode::Home,+ KeyCode::KeyPadHome,+ KeyCode::KeyPadEnd,+ KeyCode::KeyPadPageUp,+ KeyCode::KeyPadPageDown,+ KeyCode::KeyPadBegin,KeyCode::Physical(PhysKeyCode::A),+ KeyCode::Physical(PhysKeyCode::K7),] {let name = config_key_name(&key);let parsed = config::DeferredKeyCode::try_from(name.as_str())diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rsindex d0a83d3c..431aaf69 100644--- a/wezterm-gui/src/native_settings.rs+++ b/wezterm-gui/src/native_settings.rs@@ -1072,18 +1072,26 @@ pub(crate) fn reset_keymap() -> anyhow::Result<()> {})}+/// The modifier the platform's own shortcuts start on: ⌘ on a Mac, Ctrl+/// elsewhere. The Shortcut menu's default item is the default chord on it.+fn platform_primary() -> window::Modifiers {+ if cfg!(target_os = "macos") {+ window::Modifiers::SUPER+ } else {+ window::Modifiers::CTRL+ }+}+/// The Command Palette page's pick, which gives the palette that chord-/// outright: whatever Keymap set on it gives way -- on the default chords,-/// when the pick is the default.+/// outright: whatever Keymap set on it gives way. The default item names+/// one chord, the default on the platform's own modifier: what Keymap set+/// on the palette's other default chord (⌃⇧P on a Mac), which the menu+/// never shows, stays. The item already on show changes nothing.pub(crate) fn set_palette_hotkey(hotkey: NativeCommandPaletteHotkey) -> anyhow::Result<()> {- use config::keyassignment::KeyAssignment;- let cleared = match hotkey.picked_chord() {- Some((mods, ch)) => vec![crate::inputmap::canonical_chord(- &window::KeyCode::Char(ch),- mods,- )],- None => crate::inputmap::default_chords(&KeyAssignment::ActivateCommandPalette),- };+ if palette_hotkey_choice(&load()) == Some(hotkey) {+ return Ok(());+ }+ let cleared = cleared_by_pick(hotkey);update_keymap(|settings| {settings.keymap.keys.retain(|json| {parse_keymap_json(json)@@ -1093,6 +1101,24 @@ pub(crate) fn set_palette_hotkey(hotkey: NativeCommandPaletteHotkey) -> anyhow::})}+/// The chords picking `hotkey` takes back from what Keymap set: the one it+/// names.+fn cleared_by_pick(+ hotkey: NativeCommandPaletteHotkey,+) -> Vec<(window::KeyCode, window::Modifiers)> {+ use config::keyassignment::KeyAssignment;+ match hotkey.picked_chord() {+ Some((mods, ch)) => vec![crate::inputmap::canonical_chord(+ &window::KeyCode::Char(ch),+ mods,+ )],+ None => crate::inputmap::default_chords(&KeyAssignment::ActivateCommandPalette)+ .into_iter()+ .filter(|(_, mods)| mods.contains(platform_primary()))+ .collect(),+ }+}+/// What the Command Palette page's Shortcut menu shows as picked: the chord/// of its menu that opens the palette -- the pick, unless Keymap took its/// chord; else one Keymap gave the palette; else the platform's default,@@ -1137,14 +1163,9 @@ pub(crate) fn palette_hotkey_choice(if set_here.is_some() {return set_here;}- let primary = if cfg!(target_os = "macos") {- window::Modifiers::SUPER- } else {- window::Modifiers::CTRL- };let default_free = crate::inputmap::default_chords(&KeyAssignment::ActivateCommandPalette).iter()- .filter(|(_, mods)| mods.contains(primary))+ .filter(|(_, mods)| mods.contains(platform_primary())).any(|chord| !taken(chord));default_free.then_some(Hotkey::CmdShiftP)}@@ -2435,6 +2456,23 @@ mod tests {assert_eq!(palette_hotkey_choice(&settings), None);}+ #[test]+ fn picking_the_default_palette_shortcut_takes_back_only_its_chord() {+ let cleared = cleared_by_pick(NativeCommandPaletteHotkey::CmdShiftP);+ assert_eq!(cleared.len(), 1);+ assert!(cleared[0].1.contains(platform_primary()));+ // ⌃⇧P, the palette's other default on a Mac, is not on the menu.+ let ctrl_shift_p =+ crate::inputmap::canonical_chord(&window::KeyCode::Char('p'), window::Modifiers::CTRL | window::Modifiers::SHIFT);+ if cfg!(target_os = "macos") {+ assert!(!cleared.contains(&ctrl_shift_p));+ }+ assert_eq!(+ cleared_by_pick(NativeCommandPaletteHotkey::CmdK),+ vec![(window::KeyCode::Char('k'), window::Modifiers::SUPER)]+ );+ }+#[test]fn a_hand_edited_window_opacity_never_costs_the_file() {for (written, read) in [diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rsindex ac623be1..7b395b8c 100644--- a/wezterm-gui/src/settings_window.rs+++ b/wezterm-gui/src/settings_window.rs@@ -5098,6 +5098,13 @@ impl SettingsWindow {if before.tab_icons != after.tab_icons {self.sync_tab_icon_inputs();}+ // Shortcuts changed by hand in settings.json, or by another+ // window: the Keymap page decides from what it shows.+ if before.keymap != after.keymap+ || before.command_palette.hotkey != after.command_palette.hotkey+ {+ self.ui.keymap.refresh();+ }if before.chrome.settings_font_size != after.chrome.settings_font_size|| before.chrome.settings_font_weight != after.chrome.settings_font_weight{diff --git a/wezterm-gui/src/settings_window/keymap.rs b/wezterm-gui/src/settings_window/keymap.rsindex 06f3b3fa..686fd347 100644--- a/wezterm-gui/src/settings_window/keymap.rs+++ b/wezterm-gui/src/settings_window/keymap.rs@@ -269,6 +269,17 @@ fn needs_modifier(key: &KeyCode, mods: Modifiers) -> bool {!matches!(key, KeyCode::Function(_)) && (mods == Modifiers::NONE || mods == Modifiers::SHIFT)}+/// Whether `action` runs a function `wezterm.action_callback` made in+/// thinkterm.lua. Such a function is known by an event numbered in the+/// order the configuration made it (`user-defined-3`), and the next load+/// may give that number to another function: written to settings.json, a+/// shortcut would run whichever function has the number then, or none. It+/// is changed in thinkterm.lua instead. Looked for anywhere in the action,+/// which may hold others (`Multiple`, a confirmation's action).+fn runs_lua_callback(action: &KeyAssignment) -> bool {+ format!("{action:?}").contains("EmitEvent(\"user-defined-")+}+/// Where a shortcut comes from.#[derive(Debug, Clone, Copy, PartialEq, Eq)]enum Source {@@ -310,6 +321,9 @@ struct KeymapView {/// A name for every action the key table holds.names: HashMap<(KeyCode, Modifiers), String>,rendering: UIKeyCapRendering,+ /// The configuration it was built from: a reload of thinkterm.lua+ /// makes it stale, and it is built again before it is painted.+ generation: usize,}impl KeymapView {@@ -347,9 +361,19 @@ impl KeymapView {set_here,names,rendering: config.ui_key_cap_rendering,+ generation: config.generation(),}}+ /// The form the layer set here keeps `chord` in, if it keeps it: the+ /// chord itself, or the physical key a press on another layout was+ /// recorded as (`inputmap::recorded_chord`).+ fn set_here_chord(&self, chord: &(KeyCode, Modifiers)) -> Option<(KeyCode, Modifiers)> {+ crate::inputmap::chord_forms(&chord.0, chord.1)+ .into_iter()+ .find(|form| self.set_here.contains_key(form))+ }+/// What `cap` does with `mods` held, its chord looked up in every form a/// key event for it may take.fn state(&self, cap: &Cap, mods: Modifiers) -> CapState {@@ -359,10 +383,14 @@ impl KeymapView {if reserved_by_system(key, mods) {return CapState::System;}- // Kept in the one form the layer set here writes.- let chord = crate::inputmap::canonical_chord(key, mods);+ // Kept in the one form the layer set here writes; a shortcut set+ // here on this key as a physical key is reported in that form, so+ // what changes it changes that.+ let typed = crate::inputmap::canonical_chord(key, mods);+ let stored = self.set_here_chord(&typed);+ let chord = stored.clone().unwrap_or(typed);if let Some(action) = self.action_for(&chord) {- let set_here = self.set_here.contains_key(&chord);+ let set_here = stored.is_some();let file_action = self.file_action(&chord);let overrides_file = set_here&& file_action@@ -382,7 +410,7 @@ impl KeymapView {overrides_file,};}- if self.set_here.get(&chord) == Some(&KeyAssignment::DisableDefaultAssignment) {+ if stored.is_some() && self.set_here.get(&chord) == Some(&KeyAssignment::DisableDefaultAssignment) {return CapState::Removed { chord };}if used_by_programs(key, mods) {@@ -618,7 +646,16 @@ impl SettingsWindow {x: f32,max_width: f32,) -> anyhow::Result<()> {- if self.ui.keymap.view.is_none() {+ // Built again when there is none, or the one there is predates a+ // reload of thinkterm.lua: its shortcuts may have changed.+ let generation = config::configuration().generation();+ if self+ .ui+ .keymap+ .view+ .as_ref()+ .map_or(true, |view| view.generation != generation)+ {self.ui.keymap.view = Some(KeymapView::build());}let scroll = self.ui.content_scroll.offset;@@ -1491,6 +1528,10 @@ impl SettingsWindow {}KeymapAction::Change => {if let Some((chord, action, name)) = self.keymap_selected_binding() {+ if runs_lua_callback(&action) {+ self.status = crate::i18n::tr("settings-keymap-lua-callback");+ return;+ }self.ui.keymap.set_mode(Mode::Recording {action,name,@@ -1542,6 +1583,10 @@ impl SettingsWindow {else {return;};+ if runs_lua_callback(&action) {+ self.status = crate::i18n::tr("settings-keymap-lua-callback");+ return;+ }match std::mem::take(&mut self.ui.keymap.mode) {Mode::Assigning { chord } => self.keymap_bind(action, chord, None),_ => self.ui.keymap.set_mode(Mode::Recording {@@ -1585,6 +1630,10 @@ impl SettingsWindow {KeyCode::Physical(phys) => phys.to_key_code(),other => other.clone(),};+ let phys = match &event.key {+ KeyCode::Physical(phys) => Some(*phys),+ _ => event.raw.as_ref().and_then(|raw| raw.phys_code),+ };if matches!(key,KeyCode::Shift@@ -1616,8 +1665,12 @@ impl SettingsWindow {let Mode::Recording { action, from, .. } = self.ui.keymap.mode.clone() else {return true;};- let chord = crate::inputmap::canonical_chord(&key, mods);- let (typed_key, typed_mods) = crate::inputmap::typed_chord(&chord.0, chord.1);+ // What the press types, named as the drawn keyboard names it; and+ // the chord it is kept as, which on another layout may be the+ // physical key instead (`inputmap::recorded_chord`).+ let spelled = crate::inputmap::canonical_chord(&key, mods);+ let chord = crate::inputmap::recorded_chord(phys, &key, mods);+ let (typed_key, typed_mods) = crate::inputmap::typed_chord(&spelled.0, spelled.1);if reserved_by_system(&typed_key, typed_mods) {// It never reaches ThinkTerm; keep listening for another.self.status = crate::i18n::tr("settings-keymap-system");@@ -1626,7 +1679,10 @@ impl SettingsWindow {let Some(view) = self.ui.keymap.view.as_ref() else {return true;};- let held = view.action_for(&chord);+ // What the press runs now: a physical binding, else what it types.+ let held = view+ .action_for(&chord)+ .or_else(|| (chord != spelled).then(|| view.action_for(&spelled)).flatten());if held.as_ref() == Some(&action) {// Already this action's: nothing to change.self.ui.keymap.set_mode(Mode::Idle);@@ -1656,6 +1712,10 @@ impl SettingsWindow {from: Option<(KeyCode, Modifiers)>,) {self.ui.keymap.set_mode(Mode::Idle);+ if runs_lua_callback(&action) {+ self.status = crate::i18n::tr("settings-keymap-lua-callback");+ return;+ }let mut changes = vec![(chord.clone(), Some(action))];if let Some(from) = from.filter(|from| *from != chord) {// Moving off a chord set here gives it back to what lies@@ -1692,12 +1752,21 @@ impl SettingsWindow {}}+ /// The selected key's chord, in the form the layer set here keeps it+ /// when it keeps one.fn keymap_selected_chord(&self) -> Option<(KeyCode, Modifiers)> {let cap = self.ui.keymap.selected.and_then(cap_at)?;let CapKind::Key(key) = &cap.kind else {return None;};- Some(crate::inputmap::canonical_chord(key, self.ui.keymap.mods()))+ let chord = crate::inputmap::canonical_chord(key, self.ui.keymap.mods());+ let stored = self+ .ui+ .keymap+ .view+ .as_ref()+ .and_then(|view| view.set_here_chord(&chord));+ Some(stored.unwrap_or(chord))}/// The selected key's shortcut: its chord, action and name.@@ -1750,6 +1819,22 @@ mod tests {assert!(!used_by_programs(&KeyCode::Char('r'), Modifiers::SUPER));}+ #[test]+ fn a_lua_callback_is_never_copied_into_settings() {+ assert!(runs_lua_callback(&KeyAssignment::EmitEvent(+ "user-defined-3".to_string()+ )));+ assert!(runs_lua_callback(&KeyAssignment::Multiple(vec![+ KeyAssignment::ActivateCommandPalette,+ KeyAssignment::EmitEvent("user-defined-0".to_string()),+ ])));+ // An event the configuration named itself keeps its name.+ assert!(!runs_lua_callback(&KeyAssignment::EmitEvent(+ "toggle-opacity".to_string()+ )));+ assert!(!runs_lua_callback(&KeyAssignment::ActivateCommandPalette));+ }+#[test]fn key_names_drop_the_filler_words() {assert_eq!(cap_label("Activate 1st Tab"), "1st Tab");@@ -1772,6 +1857,43 @@ mod tests {.collect(),names: HashMap::new(),rendering: config.ui_key_cap_rendering,+ generation: config.generation(),+ }+ }++ #[test]+ fn a_shortcut_kept_as_a_physical_key_shows_and_changes_on_its_key() {+ let shift_cmd = Modifiers::SUPER | Modifiers::SHIFT;+ // A German ⇧7, recorded as the key pressed.+ let seven = crate::inputmap::recorded_chord(+ Some(window::PhysKeyCode::K7),+ &KeyCode::Char('/'),+ shift_cmd,+ );+ let view = view_with(&[crate::native_settings::KeymapEntry {+ key: seven.0.clone(),+ mods: seven.1,+ action: KeyAssignment::OpenThreadSearch,+ }]);+ let cap = rows()+ .iter()+ .flat_map(|row| row.iter())+ .find(|cap| matches!(&cap.kind, CapKind::Key(KeyCode::Char('7'))))+ .unwrap();+ match view.state(cap, shift_cmd) {+ CapState::Bound {+ chord,+ action,+ source,+ ..+ } => {+ // In the form it is kept in, so Change, Remove and Reset+ // act on that.+ assert_eq!(chord, seven);+ assert_eq!(action, KeyAssignment::OpenThreadSearch);+ assert_eq!(source, Source::SetHere);+ }+ other => panic!("{other:?}"),}}diff --git a/wezterm-gui/src/termwindow/keyevent.rs b/wezterm-gui/src/termwindow/keyevent.rsindex a778b369..99a0c3de 100644--- a/wezterm-gui/src/termwindow/keyevent.rs+++ b/wezterm-gui/src/termwindow/keyevent.rs@@ -861,6 +861,18 @@ impl super::TermWindow {if self.command_palette.is_some() || self.recording_overlay.owns_keyboard() {return;}+ // The chord that opens the palette is left to the cooked event that+ // follows (see `opens_command_palette`): a raw or physical binding+ // of the same key would otherwise fire here first.+ if key.key_is_down {+ let pressed = match (&key.key, key.phys_code) {+ (KeyCode::Physical(_), _) | (_, None) => key.key.clone(),+ (_, Some(phys)) => KeyCode::Physical(phys),+ };+ if self.opens_command_palette(&pressed, key.modifiers.remove_positional_mods()) {+ return;+ }+ }let stage = crate::input_diagnostics::StageTimer::begin("get_active_pane");let pane = self.get_active_pane_or_overlay();stage.finish(pane.is_some());@@ -969,6 +981,27 @@ impl super::TermWindow {}}+ /// Whether the key table gives this chord to the command palette, with+ /// no key table or leader taking keys first. That chord opens it from+ /// anywhere: ahead of a raw binding of the same key, and in a window+ /// whose content view has no pane to take keys -- as the palette's own+ /// shortcut did before it became an entry of the key table.+ fn opens_command_palette(&mut self, key: &KeyCode, mods: Modifiers) -> bool {+ if self.leader_is_active_mut() || self.current_key_table_name().is_some() {+ return false;+ }+ let key = match key {+ KeyCode::Physical(phys) => phys.to_key_code(),+ other => other.clone(),+ };+ matches!(+ self.input_map.lookup_key(&key, mods, None),+ Some(KeyTableEntry {+ action: KeyAssignment::ActivateCommandPalette+ })+ )+ }+pub fn current_modifier_and_led_state(&self) -> (Modifiers, KeyboardLedStatus) {self.current_modifier_and_leds}@@ -1098,6 +1131,16 @@ impl super::TermWindow {}return;}+ if window_key.key_is_down+ && self.opens_command_palette(+ &window_key.key,+ window_key.modifiers.remove_positional_mods(),+ )+ {+ self.toggle_command_palette();+ context.invalidate();+ return;+ }let mut input_trace = crate::input_diagnostics::KeyEventTrace::begin(window_key.key_is_down,window_key.key.is_modifier(),diff --git a/wezterm-input-types/src/lib.rs b/wezterm-input-types/src/lib.rsindex 0f712a57..f63a64a7 100644--- a/wezterm-input-types/src/lib.rs+++ b/wezterm-input-types/src/lib.rs@@ -406,6 +406,11 @@ impl TryFrom<&str> for KeyCode {ApplicationRightArrow,ApplicationUpArrow,ApplicationDownArrow,+ KeyPadHome,+ KeyPadEnd,+ KeyPadPageUp,+ KeyPadPageDown,+ KeyPadBegin,);match s {