keymap: Show error notification when keymap is invalid (#15977)
This adds an error notification that pops up when the user has an invalid keymap, similar to what we added for settings in #15905. Release Notes: - Added a popup that is displayed when the keymap is invalid
This commit is contained in:
parent
92496f33e7
commit
793cd88792
3 changed files with 43 additions and 14 deletions
|
@ -733,6 +733,7 @@ fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
|||
pub fn handle_keymap_file_changes(
|
||||
mut user_keymap_file_rx: mpsc::UnboundedReceiver<String>,
|
||||
cx: &mut AppContext,
|
||||
keymap_changed: impl Fn(Option<anyhow::Error>, &mut AppContext) + 'static,
|
||||
) {
|
||||
BaseKeymap::register(cx);
|
||||
VimModeSetting::register(cx);
|
||||
|
@ -761,10 +762,14 @@ pub fn handle_keymap_file_changes(
|
|||
_ = base_keymap_rx.next() => {}
|
||||
user_keymap_content = user_keymap_file_rx.next() => {
|
||||
if let Some(user_keymap_content) = user_keymap_content {
|
||||
if let Some(keymap_content) = KeymapFile::parse(&user_keymap_content).log_err() {
|
||||
user_keymap = keymap_content;
|
||||
} else {
|
||||
continue
|
||||
match KeymapFile::parse(&user_keymap_content) {
|
||||
Ok(keymap_content) => {
|
||||
cx.update(|cx| keymap_changed(None, cx)).log_err();
|
||||
user_keymap = keymap_content;
|
||||
}
|
||||
Err(error) => {
|
||||
cx.update(|cx| keymap_changed(Some(error), cx)).log_err();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3097,7 +3102,7 @@ mod tests {
|
|||
PathBuf::from("/keymap.json"),
|
||||
);
|
||||
handle_settings_file_changes(settings_rx, cx, |_, _| {});
|
||||
handle_keymap_file_changes(keymap_rx, cx);
|
||||
handle_keymap_file_changes(keymap_rx, cx, |_, _| {});
|
||||
});
|
||||
workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
|
@ -3237,7 +3242,7 @@ mod tests {
|
|||
);
|
||||
|
||||
handle_settings_file_changes(settings_rx, cx, |_, _| {});
|
||||
handle_keymap_file_changes(keymap_rx, cx);
|
||||
handle_keymap_file_changes(keymap_rx, cx, |_, _| {});
|
||||
});
|
||||
|
||||
cx.background_executor.run_until_parked();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue