This commit is contained in:
Junkui Zhang 2025-08-26 01:43:35 +08:00
parent 459f168ca9
commit c3c540478b
6 changed files with 19 additions and 1428 deletions

View file

@ -1,3 +1,5 @@
use collections::HashMap;
use crate::{KeybindingKeystroke, Keystroke};
/// A trait for platform-specific keyboard layouts
@ -16,6 +18,9 @@ pub trait PlatformKeyboardMapper {
keystroke: Keystroke,
use_key_equivalents: bool,
) -> KeybindingKeystroke;
/// Get the key equivalents for the current keyboard layout,
/// only used on macOS
fn get_key_equivalents(&self) -> Option<&HashMap<char, char>>;
}
/// A dummy implementation of the platform keyboard mapper
@ -29,4 +34,8 @@ impl PlatformKeyboardMapper for DummyKeyboardMapper {
) -> KeybindingKeystroke {
KeybindingKeystroke::from_keystroke(keystroke)
}
fn get_key_equivalents(&self) -> Option<&HashMap<char, char>> {
None
}
}

View file

@ -44,6 +44,10 @@ impl PlatformKeyboardMapper for MacKeyboardMapper {
}
KeybindingKeystroke::from_keystroke(keystroke)
}
fn get_key_equivalents(&self) -> Option<&HashMap<char, char>> {
self.key_equivalents.as_ref()
}
}
impl MacKeyboardLayout {

View file

@ -89,6 +89,10 @@ impl PlatformKeyboardMapper for WindowsKeyboardMapper {
display_key: key,
}
}
fn get_key_equivalents(&self) -> Option<&HashMap<char, char>> {
None
}
}
impl WindowsKeyboardLayout {

View file

@ -4,7 +4,6 @@ use gpui::{
};
use itertools::Itertools;
use serde_json::json;
use settings::get_key_equivalents;
use ui::{Button, ButtonStyle};
use ui::{
ButtonCommon, Clickable, Context, FluentBuilder, InteractiveElement, Label, LabelCommon,
@ -169,7 +168,8 @@ impl Item for KeyContextView {
impl Render for KeyContextView {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
use itertools::Itertools;
let key_equivalents = get_key_equivalents(cx.keyboard_layout().id());
let key_equivalents = cx.keyboard_mapper().get_key_equivalents();
v_flex()
.id("key-context-view")
.overflow_scroll()

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,5 @@
mod base_keymap_setting;
mod editable_setting_control;
mod key_equivalents;
mod keymap_file;
mod settings_file;
mod settings_json;
@ -14,7 +13,6 @@ use util::asset_str;
pub use base_keymap_setting::*;
pub use editable_setting_control::*;
pub use key_equivalents::*;
pub use keymap_file::{
KeyBindingValidator, KeyBindingValidatorRegistration, KeybindSource, KeybindUpdateOperation,
KeybindUpdateTarget, KeymapFile, KeymapFileLoadResult,