Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions book/src/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
| `clipboard-provider` | Which API to use for clipboard interaction. One of `pasteboard` (MacOS), `wayland`, `x-clip`, `x-sel`, `win-32-yank`, `termux`, `tmux`, `windows`, `termcode`, `none`, or a custom command set. | Platform and environment specific. |
| `editor-config` | Whether to read settings from [EditorConfig](https://editorconfig.org) files | `true` |
| `rainbow-brackets` | Whether to render rainbow colors for matching brackets. Requires tree-sitter `rainbows.scm` queries for the language. | `false` |
| `load-default-keymap` | Whether to load the default before applying the keymap from your config file. Useful for using non qwerty keyboard layouts. | `true` |

### `[editor.clipboard-provider]` Section

Expand Down
39 changes: 26 additions & 13 deletions helix-term/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ impl Config {
local.and_then(|file| toml::from_str(&file).map_err(ConfigLoadError::BadConfig));
let res = match (global_config, local_config) {
(Ok(global), Ok(local)) => {
let mut keys = keymap::default();
if let Some(global_keys) = global.keys {
merge_keys(&mut keys, global_keys)
}
if let Some(local_keys) = local.keys {
merge_keys(&mut keys, local_keys)
}

let editor = match (global.editor, local.editor) {
(None, None) => helix_view::editor::Config::default(),
(None, Some(val)) | (Some(val), None) => {
Expand All @@ -84,6 +76,19 @@ impl Config {
.map_err(ConfigLoadError::BadConfig)?,
};

let mut keys = if editor.load_default_keymap {
keymap::default()
} else {
keymap::empty()
};

if let Some(global_keys) = global.keys {
merge_keys(&mut keys, global_keys)
}
if let Some(local_keys) = local.keys {
merge_keys(&mut keys, local_keys)
}

Config {
theme: local.theme.or(global.theme),
keys,
Expand All @@ -96,17 +101,25 @@ impl Config {
return Err(ConfigLoadError::BadConfig(err))
}
(Ok(config), Err(_)) | (Err(_), Ok(config)) => {
let mut keys = keymap::default();
let editor = config.editor.map_or_else(
|| Ok(helix_view::editor::Config::default()),
|val| val.try_into().map_err(ConfigLoadError::BadConfig),
)?;

let mut keys = if editor.load_default_keymap {
keymap::default()
} else {
keymap::empty()
};

if let Some(keymap) = config.keys {
merge_keys(&mut keys, keymap);
}

Config {
theme: config.theme,
keys,
editor: config.editor.map_or_else(
|| Ok(helix_view::editor::Config::default()),
|val| val.try_into().map_err(ConfigLoadError::BadConfig),
)?,
editor,
}
}

Expand Down
2 changes: 1 addition & 1 deletion helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{
sync::Arc,
};

pub use default::default;
pub use default::{default, empty};
use macros::key;

#[derive(Debug, Clone, Default)]
Expand Down
10 changes: 10 additions & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::HashMap;

use crate::keymap::KeyTrieNode;

use super::macros::keymap;
use super::{KeyTrie, Mode};
use helix_core::hashmap;
Expand Down Expand Up @@ -410,3 +412,11 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
Mode::Insert => insert,
)
}

pub fn empty() -> HashMap<Mode, KeyTrie> {
hashmap!(
Mode::Normal => KeyTrie::Node(KeyTrieNode::new("", HashMap::new(), Vec::new())),
Mode::Select => KeyTrie::Node(KeyTrieNode::new("", HashMap::new(), Vec::new())),
Mode::Insert => KeyTrie::Node(KeyTrieNode::new("", HashMap::new(), Vec::new())),
)
}
3 changes: 3 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ pub struct Config {
pub editor_config: bool,
/// Whether to render rainbow colors for matching brackets. Defaults to `false`.
pub rainbow_brackets: bool,
// Whether to load the default keymap
pub load_default_keymap: bool,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -1061,6 +1063,7 @@ impl Default for Config {
clipboard_provider: ClipboardProvider::default(),
editor_config: true,
rainbow_brackets: false,
load_default_keymap: true,
}
}
}
Expand Down