on master help sign in
fix: Normalize backtab into shift-tab

Fixes #1150

commitcab09093dd5bf9b4707bfdfd8529b348c02670ea authorBlaž Hrastnik <blaz@mxxn.io> dateMon 6 Dec 2021, 12:24 (5 years ago) parent461cd20
6 files changed+20−20
book/src/remapping.md+2−3 helix-term/src/ui/menu.rs+1−1 helix-term/src/ui/picker.rs+1−1 helix-term/src/ui/prompt.rs+1−1 helix-view/src/input.rs+14−10 helix-view/src/keyboard.rs+1−4
book/src/remapping.md+2−3
@@ -42,10 +42,9 @@ Control, Shift and Alt modifiers are encoded respectively with the prefixes
4242| Down | `"down"` |
4343| Home | `"home"` |
4444| End | `"end"` |
45−| Page | `"pageup"` |
46−| Page | `"pagedown"` |
45+| Page Up | `"pageup"` |
46+| Page Down | `"pagedown"` |
4747| Tab | `"tab"` |
48−| Back | `"backtab"` |
4948| Delete | `"del"` |
5049| Insert | `"ins"` |
5150| Null | `"null"` |
helix-term/src/ui/menu.rs+1−1
@@ -202,7 +202,7 @@ impl<T: Item + 'static> Component for Menu<T> {
202202 return close_fn;
203203 }
204204 // arrow up/ctrl-p/shift-tab prev completion choice (including updating the doc)
205− shift!(BackTab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
205+ shift!(Tab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
206206 self.move_up();
207207 (self.callback_fn)(cx.editor, self.selection(), MenuEvent::Update);
208208 return EventResult::Consumed(None);
helix-term/src/ui/picker.rs+1−1
@@ -410,7 +410,7 @@ impl<T: 'static> Component for Picker<T> {
410410 })));
411411
412412 match key_event.into() {
413− shift!(BackTab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
413+ shift!(Tab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
414414 self.move_up();
415415 }
416416 key!(Tab) | key!(Down) | ctrl!('n') | ctrl!('j') => {
helix-term/src/ui/prompt.rs+1−1
@@ -505,7 +505,7 @@ impl Component for Prompt {
505505 self.change_completion_selection(CompletionDirection::Forward);
506506 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
507507 }
508− shift!(BackTab) => {
508+ shift!(Tab) => {
509509 self.change_completion_selection(CompletionDirection::Backward);
510510 (self.callback_fn)(cx, &self.line, PromptEvent::Update)
511511 }
helix-view/src/input.rs+14−10
@@ -36,7 +36,6 @@ pub(crate) mod keys {
3636 pub(crate) const PAGEUP: &str = "pageup";
3737 pub(crate) const PAGEDOWN: &str = "pagedown";
3838 pub(crate) const TAB: &str = "tab";
39− pub(crate) const BACKTAB: &str = "backtab";
4039 pub(crate) const DELETE: &str = "del";
4140 pub(crate) const INSERT: &str = "ins";
4241 pub(crate) const NULL: &str = "null";
@@ -82,7 +81,6 @@ impl fmt::Display for KeyEvent {
8281 KeyCode::PageUp => f.write_str(keys::PAGEUP)?,
8382 KeyCode::PageDown => f.write_str(keys::PAGEDOWN)?,
8483 KeyCode::Tab => f.write_str(keys::TAB)?,
85− KeyCode::BackTab => f.write_str(keys::BACKTAB)?,
8684 KeyCode::Delete => f.write_str(keys::DELETE)?,
8785 KeyCode::Insert => f.write_str(keys::INSERT)?,
8886 KeyCode::Null => f.write_str(keys::NULL)?,
@@ -116,7 +114,6 @@ impl UnicodeWidthStr for KeyEvent {
116114 KeyCode::PageUp => keys::PAGEUP.len(),
117115 KeyCode::PageDown => keys::PAGEDOWN.len(),
118116 KeyCode::Tab => keys::TAB.len(),
119− KeyCode::BackTab => keys::BACKTAB.len(),
120117 KeyCode::Delete => keys::DELETE.len(),
121118 KeyCode::Insert => keys::INSERT.len(),
122119 KeyCode::Null => keys::NULL.len(),
@@ -166,7 +163,6 @@ impl std::str::FromStr for KeyEvent {
166163 keys::PAGEUP => KeyCode::PageUp,
167164 keys::PAGEDOWN => KeyCode::PageDown,
168165 keys::TAB => KeyCode::Tab,
169− keys::BACKTAB => KeyCode::BackTab,
170166 keys::DELETE => KeyCode::Delete,
171167 keys::INSERT => KeyCode::Insert,
172168 keys::NULL => KeyCode::Null,
@@ -220,12 +216,20 @@ impl<'de> Deserialize<'de> for KeyEvent {
220216
221217#[cfg(feature = "term")]
222218impl From<crossterm::event::KeyEvent> for KeyEvent {
223− fn from(
224− crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent,
225− ) -> KeyEvent {
226− KeyEvent {
227− code: code.into(),
228− modifiers: modifiers.into(),
219+ fn from(crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent) -> Self {
220+ if code == crossterm::event::KeyCode::BackTab {
221+ // special case for BackTab -> Shift-Tab
222+ let mut modifiers: KeyModifiers = modifiers.into();
223+ modifiers.insert(KeyModifiers::SHIFT);
224+ Self {
225+ code: KeyCode::Tab,
226+ modifiers,
227+ }
228+ } else {
229+ Self {
230+ code: code.into(),
231+ modifiers: modifiers.into(),
232+ }
229233 }
230234 }
231235}
helix-view/src/keyboard.rs+1−4
@@ -79,8 +79,6 @@ pub enum KeyCode {
7979 PageDown,
8080 /// Tab key.
8181 Tab,
82− /// Shift + Tab key.
83− BackTab,
8482 /// Delete key.
8583 Delete,
8684 /// Insert key.
@@ -116,7 +114,6 @@ impl From<KeyCode> for crossterm::event::KeyCode {
116114 KeyCode::PageUp => CKeyCode::PageUp,
117115 KeyCode::PageDown => CKeyCode::PageDown,
118116 KeyCode::Tab => CKeyCode::Tab,
119− KeyCode::BackTab => CKeyCode::BackTab,
120117 KeyCode::Delete => CKeyCode::Delete,
121118 KeyCode::Insert => CKeyCode::Insert,
122119 KeyCode::F(f_number) => CKeyCode::F(f_number),
@@ -144,7 +141,7 @@ impl From<crossterm::event::KeyCode> for KeyCode {
144141 CKeyCode::PageUp => KeyCode::PageUp,
145142 CKeyCode::PageDown => KeyCode::PageDown,
146143 CKeyCode::Tab => KeyCode::Tab,
147− CKeyCode::BackTab => KeyCode::BackTab,
144+ CKeyCode::BackTab => unreachable!("BackTab should have been handled on KeyEvent level"),
148145 CKeyCode::Delete => KeyCode::Delete,
149146 CKeyCode::Insert => KeyCode::Insert,
150147 CKeyCode::F(f_number) => KeyCode::F(f_number),