aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorPabloMansanet2021-06-17 11:08:05 +0000
committerGitHub2021-06-17 11:08:05 +0000
commitf7e00cf720f55ea82933ac6625b7511e9d38139e (patch)
treedc8278b34332eebea8b137d15cca9e5fb08b2b06 /helix-view
parent47d2e3aefa5d31c19e7def624057a29c4bc7bc41 (diff)
Configurable keys 2 (Mapping keys to commands) (#268)
* Add convenience/clarity wrapper for Range initialization * Add keycode parse and display methods * Add remapping functions and tests * Implement key remapping * Add remapping book entry * Use raw string literal for toml * Add command constants * Make command functions private * Map directly to commands * Match key parsing/displaying to Kakoune * Formatting pass * Update documentation * Formatting * Fix example in the book * Refactor into single config file * Formatting * Refactor configuration and add keymap newtype wrappers * Address first batch of PR comments * Replace FromStr with custom deserialize
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/document.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index a1c4b407..254e01b0 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -1,7 +1,9 @@
-use anyhow::{Context, Error};
+use anyhow::{anyhow, Context, Error};
use std::cell::Cell;
+use std::fmt::Display;
use std::future::Future;
use std::path::{Component, Path, PathBuf};
+use std::str::FromStr;
use std::sync::Arc;
use helix_core::{
@@ -86,6 +88,29 @@ impl fmt::Debug for Document {
}
}
+impl Display for Mode {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Mode::Normal => f.write_str("normal"),
+ Mode::Select => f.write_str("select"),
+ Mode::Insert => f.write_str("insert"),
+ }
+ }
+}
+
+impl FromStr for Mode {
+ type Err = Error;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ match s {
+ "normal" => Ok(Mode::Normal),
+ "select" => Ok(Mode::Select),
+ "insert" => Ok(Mode::Insert),
+ _ => Err(anyhow!("Invalid mode '{}'", s)),
+ }
+ }
+}
+
/// Like std::mem::replace() except it allows the replacement value to be mapped from the
/// original value.
fn take_with<T, F>(mut_ref: &mut T, closure: F)