mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-23 18:06:18 +04:00
f7e00cf720
* 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
34 lines
895 B
Rust
34 lines
895 B
Rust
use anyhow::{Error, Result};
|
|
use std::{collections::HashMap, str::FromStr};
|
|
|
|
use serde::{de::Error as SerdeError, Deserialize, Serialize};
|
|
|
|
use crate::keymap::{parse_keymaps, Keymaps};
|
|
|
|
#[derive(Default)]
|
|
pub struct Config {
|
|
pub keymaps: Keymaps,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
struct TomlConfig {
|
|
keys: Option<HashMap<String, HashMap<String, String>>>,
|
|
}
|
|
|
|
impl<'de> Deserialize<'de> for Config {
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
where
|
|
D: serde::Deserializer<'de>,
|
|
{
|
|
let config = TomlConfig::deserialize(deserializer)?;
|
|
Ok(Self {
|
|
keymaps: config
|
|
.keys
|
|
.map(|r| parse_keymaps(&r))
|
|
.transpose()
|
|
.map_err(|e| D::Error::custom(format!("Error deserializing keymap: {}", e)))?
|
|
.unwrap_or_else(Keymaps::default),
|
|
})
|
|
}
|
|
}
|