From 10548bf0e32209e02460021cc8ca4865c4c75bf7 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Wed, 23 Jun 2021 01:04:04 +0800 Subject: Fix previous broken refactor key into helix-view Need to be used for autoinfo Revert "Revert "Refactor key into helix-view"" This reverts commit 10f9f72232f5789323d689bf0f9cd359715770d6. --- helix-term/src/commands.rs | 71 ++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 27 deletions(-) (limited to 'helix-term/src/commands.rs') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index be350140..d48a2099 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -15,6 +15,7 @@ use helix_core::{ use helix_view::{ document::{IndentStyle, Mode}, + input::{KeyCode, KeyEvent}, view::{View, PADDING}, Document, DocumentId, Editor, ViewId, }; @@ -42,8 +43,8 @@ use std::{ path::{Path, PathBuf}, }; -use crossterm::event::{KeyCode, KeyEvent}; use once_cell::sync::Lazy; +use serde::de::{self, Deserialize, Deserializer}; pub struct Context<'a> { pub selected_register: helix_view::RegisterSelection, @@ -260,6 +261,48 @@ impl Command { ); } +impl fmt::Debug for Command { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Command(name, _) = self; + f.debug_tuple("Command").field(name).finish() + } +} + +impl fmt::Display for Command { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Command(name, _) = self; + f.write_str(name) + } +} + +impl std::str::FromStr for Command { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + Command::COMMAND_LIST + .iter() + .copied() + .find(|cmd| cmd.0 == s) + .ok_or_else(|| anyhow!("No command named '{}'", s)) + } +} + +impl<'de> Deserialize<'de> for Command { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + s.parse().map_err(de::Error::custom) + } +} + +impl PartialEq for Command { + fn eq(&self, other: &Self) -> bool { + self.name() == other.name() + } +} + fn move_char_left(cx: &mut Context) { let count = cx.count(); let (view, doc) = current!(cx.editor); @@ -3456,29 +3499,3 @@ fn surround_delete(cx: &mut Context) { } }) } - -impl fmt::Display for Command { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let Command(name, _) = self; - f.write_str(name) - } -} - -impl std::str::FromStr for Command { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - Command::COMMAND_LIST - .iter() - .copied() - .find(|cmd| cmd.0 == s) - .ok_or_else(|| anyhow!("No command named '{}'", s)) - } -} - -impl fmt::Debug for Command { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let Command(name, _) = self; - f.debug_tuple("Command").field(name).finish() - } -} -- cgit v1.2.3-70-g09d2