Skip to content

Commit 119c750

Browse files
committed
Added better comments and improved book entry. Renamed several functions and calls to be more clear.
1 parent 256e011 commit 119c750

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

book/src/remapping.md

+14
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ Individual keys can be disabled by binding them to the `no_op` command.
5353

5454
To remove the default bindings for all modes defined by the user, `unbind-default-keys = true` can be added to the top level configuration.
5555

56+
```toml
57+
unbind-default-keys = true
58+
59+
# Only these normal mode bindings will be used
60+
[keys.normal]
61+
n = "normal_mode"
62+
t = "goto_definition"
63+
64+
# No select mode bindings will be used
65+
[keys.select]
66+
67+
# All default insert mode bindings will be used because new bindings weren't defined
68+
```
69+
5670
Commands can be found at [Keymap](https://docs.helix-editor.com/keymap.html) Commands.
5771

5872
> Commands can also be found in the source code at [`helix-term/src/commands.rs`](https://github.com/helix-editor/helix/blob/master/helix-term/src/commands.rs) at the invocation of `static_commands!` macro and the `TypableCommandList`.

helix-term/src/application.rs

-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ impl Application {
8989
use helix_view::editor::Action;
9090

9191
let config_dir = helix_loader::config_dir();
92-
if !config_dir.exists() {
93-
std::fs::create_dir_all(&config_dir).ok();
94-
}
95-
9692
let theme_loader = std::sync::Arc::new(theme::Loader::new(
9793
&config_dir,
9894
&helix_loader::runtime_dir(),

helix-term/src/config.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ impl Display for ConfigLoadError {
3636

3737
impl Config {
3838
// avoids confusion between a default rust struct and default helix keys
39+
/// Creates a new empty config
3940
#[allow(clippy::new_without_default)]
4041
pub fn new() -> Self {
4142
Config {
4243
theme: None,
4344
unbind_default_keys: false,
44-
keys: Default::default(),
45-
editor: Default::default(),
45+
keys: HashMap::new(),
46+
editor: helix_view::editor::Config::default(),
4647
}
4748
}
49+
50+
/// Creates a new config with the default keybindings
4851
pub fn with_default_keys() -> Self {
4952
Config {
5053
theme: None,
@@ -72,8 +75,8 @@ impl Config {
7275
}
7376

7477
/// Replace our keys for a mode with other's keys for that mode.
75-
/// Retains existing keys if other does not redefine them
76-
pub fn replace_keys(mut self, other: Self) -> Self {
78+
/// Retains existing modes if other does not redefine them
79+
pub fn replace_key_modes(mut self, other: Self) -> Self {
7780
for (mode, keys) in other.keys.into_iter() {
7881
self.keys.insert(mode, keys);
7982
}
@@ -82,16 +85,16 @@ impl Config {
8285
}
8386

8487
/// Take other's keys and replace our modes into them
85-
pub fn replace_into_keys(mut self, mut other: Self) -> Self {
88+
pub fn replace_into_key_modes(mut self, mut other: Self) -> Self {
8689
std::mem::swap(&mut self.keys, &mut other.keys);
87-
self.replace_keys(other)
90+
self.replace_key_modes(other)
8891
}
8992

9093
pub fn load(config_path: PathBuf) -> Result<Config, ConfigLoadError> {
9194
match std::fs::read_to_string(config_path) {
9295
Ok(config) => match toml::from_str::<Config>(&config) {
9396
Ok(config) if config.unbind_default_keys => {
94-
Ok(config.replace_into_keys(Config::with_default_keys()))
97+
Ok(config.replace_into_key_modes(Config::with_default_keys()))
9598
}
9699
Ok(config) => Ok(config.merge_into_keys(Config::with_default_keys())),
97100

helix-term/src/keymap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ mod tests {
475475

476476
let mut replaced_config = config
477477
.clone()
478-
.replace_into_keys(Config::with_default_keys());
478+
.replace_into_key_modes(Config::with_default_keys());
479479
assert_ne!(config, replaced_config);
480480

481481
let mut keymap = Keymaps::new(Box::new(Constant(replaced_config.keys.clone())));

0 commit comments

Comments
 (0)