Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add refresh-config and open-config command #1803

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
03bade9
Add refresh-config and open-config command
jharrilim Mar 13, 2022
4a0eff1
clippy
jharrilim Mar 13, 2022
209112b
Use dynamic dispatch for editor config
jharrilim Mar 13, 2022
f1b21af
Refactor Result::Ok to Ok
jharrilim Mar 13, 2022
124ea23
Remove unused import
jharrilim Mar 13, 2022
3676e2e
cargo fmt
jharrilim Mar 13, 2022
7b74c43
Modify config error handling
jharrilim Mar 13, 2022
6e4da94
cargo xtask docgen
jharrilim Mar 13, 2022
d7e552b
impl display for ConfigLoadError
jharrilim Mar 13, 2022
a41c215
cargo fmt
jharrilim Mar 13, 2022
06bad8c
Put keymaps behind dyn access, refactor config.load()
jharrilim Mar 18, 2022
ea39201
Update command names
jharrilim Mar 18, 2022
0bf7beb
Update helix-term/src/application.rs
jharrilim Mar 18, 2022
161f9b8
Merge branch 'master' into feat/add-refresh-config-command
jharrilim Mar 18, 2022
b459895
Switch to unbounded_channel
jharrilim Mar 18, 2022
f930c77
Remove --edit-config command
jharrilim Mar 18, 2022
e6a2a60
Update configuration docs
jharrilim Mar 18, 2022
c5d7242
Revert "Put keymaps behind dyn access", too hard
jharrilim Mar 19, 2022
dbbea48
Merge branch 'master' into feat/add-refresh-config-command
jharrilim Mar 22, 2022
7df2f0c
Add refresh for keys
jharrilim Mar 23, 2022
681b8c8
Refactor default_keymaps, fix config default, add test
jharrilim Mar 23, 2022
ad5dc91
swap -> store, remove unneeded clone
jharrilim Mar 23, 2022
23e96a6
cargo fmt
jharrilim Mar 23, 2022
252d746
Rename default_keymaps to default
jharrilim Mar 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::{
compositor::Compositor,
config::Config,
job::Jobs,
keymap::Keymaps,
ui::{self, overlay::overlayed},
};

Expand Down Expand Up @@ -111,9 +112,10 @@ impl Application {
})),
);

let editor_view = Box::new(ui::EditorView::new(std::mem::take(
&mut config.load().keys.clone(),
)));
let keys = Box::new(Map::new(Arc::clone(&config), |config: &Config| {
&config.keys
}));
let editor_view = Box::new(ui::EditorView::new(Keymaps::new(keys)));
compositor.push(editor_view);

if args.load_tutor {
Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,7 @@ pub fn command_palette(cx: &mut Context) {
move |compositor: &mut Compositor, cx: &mut compositor::Context| {
let doc = doc_mut!(cx.editor);
let keymap =
compositor.find::<ui::EditorView>().unwrap().keymaps.map[&doc.mode].reverse_map();
compositor.find::<ui::EditorView>().unwrap().keymaps.map()[&doc.mode].reverse_map();

let mut commands: Vec<MappableCommand> = MappableCommand::STATIC_COMMAND_LIST.into();
commands.extend(typed::TYPABLE_COMMAND_LIST.iter().map(|cmd| {
Expand Down
10 changes: 6 additions & 4 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::keymap::{merge_keys, Keymaps};
use crate::keymap::{merge_keys, Keymap};
use helix_view::document::Mode;
use serde::Deserialize;
use std::collections::HashMap;
use std::fmt::Display;
use std::io::Error as IOError;
use std::path::PathBuf;
Expand All @@ -12,7 +14,7 @@ pub struct Config {
#[serde(default)]
pub lsp: LspConfig,
#[serde(default)]
pub keys: Keymaps,
pub keys: HashMap<Mode, Keymap>,
Copy link
Contributor Author

@jharrilim jharrilim Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Keymaps" struct is now divorced from the config. Since the Keymaps encapsulated view state alongside config, it wasn't quite fitting, and had to be changed for config projection to work accordingly.

edit: Oops just realized the #[serde(default)], that needs to be updated to return the proper default HashMap

edit edit: This has now been updated to use the proper default HashMap

#[serde(default)]
pub editor: helix_view::editor::Config,
}
Expand Down Expand Up @@ -76,15 +78,15 @@ mod tests {
assert_eq!(
toml::from_str::<Config>(sample_keymaps).unwrap(),
Config {
keys: Keymaps::new(hashmap! {
keys: hashmap! {
Mode::Insert => Keymap::new(keymap!({ "Insert mode"
"y" => move_line_down,
"S-C-a" => delete_selection,
})),
Mode::Normal => Keymap::new(keymap!({ "Normal mode"
"A-F12" => move_next_word_end,
})),
}),
},
..Default::default()
}
);
Expand Down
Loading