Use the word 'keymap' more consistently

Co-authored-by: Keith Simmons <keith@zed.dev>
This commit is contained in:
Max Brunsfeld 2022-04-11 17:02:16 -07:00
parent be11f63f1e
commit ee3eb9658f
6 changed files with 15 additions and 17 deletions

View File

@ -7,14 +7,14 @@ use serde_json::value::RawValue;
#[derive(Deserialize, Default, Clone)] #[derive(Deserialize, Default, Clone)]
#[serde(transparent)] #[serde(transparent)]
pub struct KeyMapFile(BTreeMap<String, ActionsByKeystroke>); pub struct KeymapFile(BTreeMap<String, ActionsByKeystroke>);
type ActionsByKeystroke = BTreeMap<String, Box<RawValue>>; type ActionsByKeystroke = BTreeMap<String, Box<RawValue>>;
#[derive(Deserialize)] #[derive(Deserialize)]
struct ActionWithData<'a>(#[serde(borrow)] &'a str, #[serde(borrow)] &'a RawValue); struct ActionWithData<'a>(#[serde(borrow)] &'a str, #[serde(borrow)] &'a RawValue);
impl KeyMapFile { impl KeymapFile {
pub fn load_defaults(cx: &mut MutableAppContext) { pub fn load_defaults(cx: &mut MutableAppContext) {
for path in ["keymaps/default.json", "keymaps/vim.json"] { for path in ["keymaps/default.json", "keymaps/vim.json"] {
Self::load(path, cx).unwrap(); Self::load(path, cx).unwrap();

View File

@ -15,7 +15,7 @@ use std::{collections::HashMap, sync::Arc};
use theme::{Theme, ThemeRegistry}; use theme::{Theme, ThemeRegistry};
use util::ResultExt as _; use util::ResultExt as _;
pub use keymap_file::KeyMapFile; pub use keymap_file::KeymapFile;
#[derive(Clone)] #[derive(Clone)]
pub struct Settings { pub struct Settings {

View File

@ -24,7 +24,7 @@ impl<'a> VimTestContext<'a> {
editor::init(cx); editor::init(cx);
crate::init(cx); crate::init(cx);
settings::KeyMapFile::load("keymaps/vim.json", cx).unwrap(); settings::KeymapFile::load("keymaps/vim.json", cx).unwrap();
}); });
let params = cx.update(WorkspaceParams::test); let params = cx.update(WorkspaceParams::test);

View File

@ -10,7 +10,7 @@ use gpui::{App, AssetSource, Task};
use log::LevelFilter; use log::LevelFilter;
use parking_lot::Mutex; use parking_lot::Mutex;
use project::Fs; use project::Fs;
use settings::{self, KeyMapFile, Settings, SettingsFileContent}; use settings::{self, KeymapFile, Settings, SettingsFileContent};
use smol::process::Command; use smol::process::Command;
use std::{env, fs, path::PathBuf, sync::Arc}; use std::{env, fs, path::PathBuf, sync::Arc};
use theme::{ThemeRegistry, DEFAULT_THEME_NAME}; use theme::{ThemeRegistry, DEFAULT_THEME_NAME};
@ -112,7 +112,7 @@ fn main() {
}) })
.detach_and_log_err(cx); .detach_and_log_err(cx);
let (settings_file, bindings_file) = cx.background().block(config_files).unwrap(); let (settings_file, keymap_file) = cx.background().block(config_files).unwrap();
let mut settings_rx = settings_from_files( let mut settings_rx = settings_from_files(
default_settings, default_settings,
vec![settings_file], vec![settings_file],
@ -120,7 +120,7 @@ fn main() {
cx.font_cache().clone(), cx.font_cache().clone(),
); );
cx.spawn(|cx| watch_keymap_file(bindings_file, cx)).detach(); cx.spawn(|cx| watch_keymap_file(keymap_file, cx)).detach();
let settings = cx.background().block(settings_rx.next()).unwrap(); let settings = cx.background().block(settings_rx.next()).unwrap();
cx.spawn(|mut cx| async move { cx.spawn(|mut cx| async move {
@ -262,7 +262,7 @@ fn load_config_files(
fs: Arc<dyn Fs>, fs: Arc<dyn Fs>,
) -> oneshot::Receiver<( ) -> oneshot::Receiver<(
WatchedJsonFile<SettingsFileContent>, WatchedJsonFile<SettingsFileContent>,
WatchedJsonFile<KeyMapFile>, WatchedJsonFile<KeymapFile>,
)> { )> {
let executor = app.background(); let executor = app.background();
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
@ -271,9 +271,8 @@ fn load_config_files(
.spawn(async move { .spawn(async move {
let settings_file = let settings_file =
WatchedJsonFile::new(fs.clone(), &executor, zed::SETTINGS_PATH.clone()).await; WatchedJsonFile::new(fs.clone(), &executor, zed::SETTINGS_PATH.clone()).await;
let bindings_file = let keymap_file = WatchedJsonFile::new(fs, &executor, zed::KEYMAP_PATH.clone()).await;
WatchedJsonFile::new(fs, &executor, zed::BINDINGS_PATH.clone()).await; tx.send((settings_file, keymap_file)).ok()
tx.send((settings_file, bindings_file)).ok()
}) })
.detach(); .detach();
rx rx

View File

@ -4,8 +4,7 @@ use postage::sink::Sink as _;
use postage::{prelude::Stream, watch}; use postage::{prelude::Stream, watch};
use project::Fs; use project::Fs;
use serde::Deserialize; use serde::Deserialize;
use settings::KeyMapFile; use settings::{KeymapFile, Settings, SettingsFileContent};
use settings::{Settings, SettingsFileContent};
use std::{path::Path, sync::Arc, time::Duration}; use std::{path::Path, sync::Arc, time::Duration};
use theme::ThemeRegistry; use theme::ThemeRegistry;
use util::ResultExt; use util::ResultExt;
@ -77,11 +76,11 @@ pub fn settings_from_files(
}) })
} }
pub async fn watch_keymap_file(mut file: WatchedJsonFile<KeyMapFile>, mut cx: AsyncAppContext) { pub async fn watch_keymap_file(mut file: WatchedJsonFile<KeymapFile>, mut cx: AsyncAppContext) {
while let Some(content) = file.0.recv().await { while let Some(content) = file.0.recv().await {
cx.update(|cx| { cx.update(|cx| {
cx.clear_bindings(); cx.clear_bindings();
settings::KeyMapFile::load_defaults(cx); settings::KeymapFile::load_defaults(cx);
content.add(cx).log_err(); content.add(cx).log_err();
}); });
} }

View File

@ -45,7 +45,7 @@ lazy_static! {
.expect("failed to determine home directory") .expect("failed to determine home directory")
.join(".zed"); .join(".zed");
pub static ref SETTINGS_PATH: PathBuf = ROOT_PATH.join("settings.json"); pub static ref SETTINGS_PATH: PathBuf = ROOT_PATH.join("settings.json");
pub static ref BINDINGS_PATH: PathBuf = ROOT_PATH.join("bindings.json"); pub static ref KEYMAP_PATH: PathBuf = ROOT_PATH.join("keymap.json");
} }
pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) { pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
@ -103,7 +103,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
workspace::lsp_status::init(cx); workspace::lsp_status::init(cx);
settings::KeyMapFile::load_defaults(cx); settings::KeymapFile::load_defaults(cx);
} }
pub fn build_workspace( pub fn build_workspace(