Skip to content

Commit 528d56e

Browse files
authored
keymap_ui: Add open keymap JSON button (#36182)
Closes #ISSUE Release Notes: - Keymap Editor: Added a button in the top left to allow opening the keymap JSON file. Right clicking the button provides shortcuts to opening the default Zed and Vim keymaps as well.
1 parent f514c7c commit 528d56e

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/icons/json.svg

Lines changed: 4 additions & 0 deletions
Loading

crates/icons/src/icons.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub enum IconName {
140140
Image,
141141
Indicator,
142142
Info,
143+
Json,
143144
Keyboard,
144145
Library,
145146
LineHeight,

crates/settings_ui/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ tree-sitter-rust.workspace = true
4242
ui.workspace = true
4343
ui_input.workspace = true
4444
util.workspace = true
45+
vim.workspace = true
4546
workspace-hack.workspace = true
4647
workspace.workspace = true
48+
zed_actions.workspace = true
4749

4850
[dev-dependencies]
4951
db = {"workspace"= true, "features" = ["test-support"]}

crates/settings_ui/src/keybindings.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use settings::{BaseKeymap, KeybindSource, KeymapFile, Settings as _, SettingsAss
2323
use ui::{
2424
ActiveTheme as _, App, Banner, BorrowAppContext, ContextMenu, IconButtonShape, Indicator,
2525
Modal, ModalFooter, ModalHeader, ParentElement as _, Render, Section, SharedString,
26-
Styled as _, Tooltip, Window, prelude::*,
26+
Styled as _, Tooltip, Window, prelude::*, right_click_menu,
2727
};
2828
use ui_input::SingleLineInput;
2929
use util::ResultExt;
@@ -1536,6 +1536,33 @@ impl Render for KeymapEditor {
15361536
.child(
15371537
h_flex()
15381538
.gap_2()
1539+
.child(
1540+
right_click_menu("open-keymap-menu")
1541+
.menu(|window, cx| {
1542+
ContextMenu::build(window, cx, |menu, _, _| {
1543+
menu.header("Open Keymap JSON")
1544+
.action("User", zed_actions::OpenKeymap.boxed_clone())
1545+
.action("Zed Default", zed_actions::OpenDefaultKeymap.boxed_clone())
1546+
.action("Vim Default", vim::OpenDefaultKeymap.boxed_clone())
1547+
})
1548+
})
1549+
.anchor(gpui::Corner::TopLeft)
1550+
.trigger(|open, _, _|
1551+
IconButton::new(
1552+
"OpenKeymapJsonButton",
1553+
IconName::Json
1554+
)
1555+
.shape(ui::IconButtonShape::Square)
1556+
.when(!open, |this|
1557+
this.tooltip(move |window, cx| {
1558+
Tooltip::with_meta("Open Keymap JSON", Some(&zed_actions::OpenKeymap),"Right click to view more options", window, cx)
1559+
})
1560+
)
1561+
.on_click(|_, window, cx| {
1562+
window.dispatch_action(zed_actions::OpenKeymap.boxed_clone(), cx);
1563+
})
1564+
)
1565+
)
15391566
.child(
15401567
div()
15411568
.key_context({

0 commit comments

Comments
 (0)