diff options
-rw-r--r-- | helix-term/src/commands.rs | 36 | ||||
-rw-r--r-- | helix-view/src/input.rs | 4 |
2 files changed, 8 insertions, 32 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index dc28c098..f6df26ba 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3723,11 +3723,7 @@ fn wclose(cx: &mut Context) { fn select_register(cx: &mut Context) { cx.on_next_key(move |cx, event| { - if let KeyEvent { - code: KeyCode::Char(ch), - .. - } = event - { + if let Some(ch) = event.char() { cx.editor.selected_register.select(ch); } }) @@ -3781,11 +3777,7 @@ fn select_textobject_inner(cx: &mut Context) { fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { let count = cx.count(); cx.on_next_key(move |cx, event| { - if let KeyEvent { - code: KeyCode::Char(ch), - .. - } = event - { + if let Some(ch) = event.char() { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); @@ -3806,11 +3798,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) { fn surround_add(cx: &mut Context) { cx.on_next_key(move |cx, event| { - if let KeyEvent { - code: KeyCode::Char(ch), - .. - } = event - { + if let Some(ch) = event.char() { let (view, doc) = current!(cx.editor); let selection = doc.selection(view.id); let (open, close) = surround::get_pair(ch); @@ -3831,17 +3819,9 @@ fn surround_add(cx: &mut Context) { fn surround_replace(cx: &mut Context) { let count = cx.count(); cx.on_next_key(move |cx, event| { - if let KeyEvent { - code: KeyCode::Char(from), - .. - } = event - { + if let Some(from) = event.char() { cx.on_next_key(move |cx, event| { - if let KeyEvent { - code: KeyCode::Char(to), - .. - } = event - { + if let Some(to) = event.char() { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); let selection = doc.selection(view.id); @@ -3874,11 +3854,7 @@ fn surround_replace(cx: &mut Context) { fn surround_delete(cx: &mut Context) { let count = cx.count(); cx.on_next_key(move |cx, event| { - if let KeyEvent { - code: KeyCode::Char(ch), - .. - } = event - { + if let Some(ch) = event.char() { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); let selection = doc.selection(view.id); diff --git a/helix-view/src/input.rs b/helix-view/src/input.rs index 8d9ee6fb..28b204bb 100644 --- a/helix-view/src/input.rs +++ b/helix-view/src/input.rs @@ -15,10 +15,10 @@ pub struct KeyEvent { } impl KeyEvent { - /// Get only the character involved in this event + /// If a character was pressed (without modifiers), return it. pub fn char(&self) -> Option<char> { match self.code { - KeyCode::Char(ch) => Some(ch), + KeyCode::Char(ch) if self.modifiers.is_empty() => Some(ch), _ => None, } } |