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

Make stickiness configurable #4164

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions book/src/remapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ Control, Shift and Alt modifiers are encoded respectively with the prefixes

Keys can be disabled by binding them to the `no_op` command.

Making a mode "sticky" can be achieved by adding `sticky = true` to the mapping.

Commands can be found at [Keymap](https://docs.helix-editor.com/keymap.html) Commands.
> 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`.
22 changes: 18 additions & 4 deletions helix-term/src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,25 @@ impl<'de> serde::de::Visitor<'de> for KeyTrieVisitor {
{
let mut mapping = HashMap::new();
let mut order = Vec::new();
while let Some((key, value)) = map.next_entry::<KeyEvent, KeyTrie>()? {
mapping.insert(key, value);
order.push(key);
let mut is_sticky = false;
while let Some(toml_key) = map.next_key::<toml::Value>()? {
let maybe_key_event = toml_key.clone().try_into::<KeyEvent>();
match (maybe_key_event, toml_key.as_str()) {
(Ok(key_event), _) => {
mapping.insert(key_event, map.next_value::<KeyTrie>()?);
order.push(key_event);
}
(Err(_), Some("sticky")) => {
is_sticky = map.next_value::<bool>()?;
}
(Err(err), _) => {
return Err(serde::de::Error::custom(err.to_string()));
}
}
}
Ok(KeyTrie::Node(KeyTrieNode::new("", mapping, order)))
let mut trie_node = KeyTrieNode::new("", mapping, order);
trie_node.is_sticky = is_sticky;
Ok(KeyTrie::Node(trie_node))
}
}

Expand Down