fix: Normalize backtab into shift-tab

Fixes #1150
imgbot
Blaž Hrastnik 3 years ago
parent 461cd20563
commit cab09093dd

@ -42,10 +42,9 @@ Control, Shift and Alt modifiers are encoded respectively with the prefixes
| Down | `"down"` | | Down | `"down"` |
| Home | `"home"` | | Home | `"home"` |
| End | `"end"` | | End | `"end"` |
| Page | `"pageup"` | | Page Up | `"pageup"` |
| Page | `"pagedown"` | | Page Down | `"pagedown"` |
| Tab | `"tab"` | | Tab | `"tab"` |
| Back | `"backtab"` |
| Delete | `"del"` | | Delete | `"del"` |
| Insert | `"ins"` | | Insert | `"ins"` |
| Null | `"null"` | | Null | `"null"` |

@ -202,7 +202,7 @@ impl<T: Item + 'static> Component for Menu<T> {
return close_fn; return close_fn;
} }
// arrow up/ctrl-p/shift-tab prev completion choice (including updating the doc) // arrow up/ctrl-p/shift-tab prev completion choice (including updating the doc)
shift!(BackTab) | key!(Up) | ctrl!('p') | ctrl!('k') => { shift!(Tab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
self.move_up(); self.move_up();
(self.callback_fn)(cx.editor, self.selection(), MenuEvent::Update); (self.callback_fn)(cx.editor, self.selection(), MenuEvent::Update);
return EventResult::Consumed(None); return EventResult::Consumed(None);

@ -410,7 +410,7 @@ impl<T: 'static> Component for Picker<T> {
}))); })));
match key_event.into() { match key_event.into() {
shift!(BackTab) | key!(Up) | ctrl!('p') | ctrl!('k') => { shift!(Tab) | key!(Up) | ctrl!('p') | ctrl!('k') => {
self.move_up(); self.move_up();
} }
key!(Tab) | key!(Down) | ctrl!('n') | ctrl!('j') => { key!(Tab) | key!(Down) | ctrl!('n') | ctrl!('j') => {

@ -505,7 +505,7 @@ impl Component for Prompt {
self.change_completion_selection(CompletionDirection::Forward); self.change_completion_selection(CompletionDirection::Forward);
(self.callback_fn)(cx, &self.line, PromptEvent::Update) (self.callback_fn)(cx, &self.line, PromptEvent::Update)
} }
shift!(BackTab) => { shift!(Tab) => {
self.change_completion_selection(CompletionDirection::Backward); self.change_completion_selection(CompletionDirection::Backward);
(self.callback_fn)(cx, &self.line, PromptEvent::Update) (self.callback_fn)(cx, &self.line, PromptEvent::Update)
} }

@ -36,7 +36,6 @@ pub(crate) mod keys {
pub(crate) const PAGEUP: &str = "pageup"; pub(crate) const PAGEUP: &str = "pageup";
pub(crate) const PAGEDOWN: &str = "pagedown"; pub(crate) const PAGEDOWN: &str = "pagedown";
pub(crate) const TAB: &str = "tab"; pub(crate) const TAB: &str = "tab";
pub(crate) const BACKTAB: &str = "backtab";
pub(crate) const DELETE: &str = "del"; pub(crate) const DELETE: &str = "del";
pub(crate) const INSERT: &str = "ins"; pub(crate) const INSERT: &str = "ins";
pub(crate) const NULL: &str = "null"; pub(crate) const NULL: &str = "null";
@ -82,7 +81,6 @@ impl fmt::Display for KeyEvent {
KeyCode::PageUp => f.write_str(keys::PAGEUP)?, KeyCode::PageUp => f.write_str(keys::PAGEUP)?,
KeyCode::PageDown => f.write_str(keys::PAGEDOWN)?, KeyCode::PageDown => f.write_str(keys::PAGEDOWN)?,
KeyCode::Tab => f.write_str(keys::TAB)?, KeyCode::Tab => f.write_str(keys::TAB)?,
KeyCode::BackTab => f.write_str(keys::BACKTAB)?,
KeyCode::Delete => f.write_str(keys::DELETE)?, KeyCode::Delete => f.write_str(keys::DELETE)?,
KeyCode::Insert => f.write_str(keys::INSERT)?, KeyCode::Insert => f.write_str(keys::INSERT)?,
KeyCode::Null => f.write_str(keys::NULL)?, KeyCode::Null => f.write_str(keys::NULL)?,
@ -116,7 +114,6 @@ impl UnicodeWidthStr for KeyEvent {
KeyCode::PageUp => keys::PAGEUP.len(), KeyCode::PageUp => keys::PAGEUP.len(),
KeyCode::PageDown => keys::PAGEDOWN.len(), KeyCode::PageDown => keys::PAGEDOWN.len(),
KeyCode::Tab => keys::TAB.len(), KeyCode::Tab => keys::TAB.len(),
KeyCode::BackTab => keys::BACKTAB.len(),
KeyCode::Delete => keys::DELETE.len(), KeyCode::Delete => keys::DELETE.len(),
KeyCode::Insert => keys::INSERT.len(), KeyCode::Insert => keys::INSERT.len(),
KeyCode::Null => keys::NULL.len(), KeyCode::Null => keys::NULL.len(),
@ -166,7 +163,6 @@ impl std::str::FromStr for KeyEvent {
keys::PAGEUP => KeyCode::PageUp, keys::PAGEUP => KeyCode::PageUp,
keys::PAGEDOWN => KeyCode::PageDown, keys::PAGEDOWN => KeyCode::PageDown,
keys::TAB => KeyCode::Tab, keys::TAB => KeyCode::Tab,
keys::BACKTAB => KeyCode::BackTab,
keys::DELETE => KeyCode::Delete, keys::DELETE => KeyCode::Delete,
keys::INSERT => KeyCode::Insert, keys::INSERT => KeyCode::Insert,
keys::NULL => KeyCode::Null, keys::NULL => KeyCode::Null,
@ -220,12 +216,20 @@ impl<'de> Deserialize<'de> for KeyEvent {
#[cfg(feature = "term")] #[cfg(feature = "term")]
impl From<crossterm::event::KeyEvent> for KeyEvent { impl From<crossterm::event::KeyEvent> for KeyEvent {
fn from( fn from(crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent) -> Self {
crossterm::event::KeyEvent { code, modifiers }: crossterm::event::KeyEvent, if code == crossterm::event::KeyCode::BackTab {
) -> KeyEvent { // special case for BackTab -> Shift-Tab
KeyEvent { let mut modifiers: KeyModifiers = modifiers.into();
code: code.into(), modifiers.insert(KeyModifiers::SHIFT);
modifiers: modifiers.into(), Self {
code: KeyCode::Tab,
modifiers,
}
} else {
Self {
code: code.into(),
modifiers: modifiers.into(),
}
} }
} }
} }

@ -79,8 +79,6 @@ pub enum KeyCode {
PageDown, PageDown,
/// Tab key. /// Tab key.
Tab, Tab,
/// Shift + Tab key.
BackTab,
/// Delete key. /// Delete key.
Delete, Delete,
/// Insert key. /// Insert key.
@ -116,7 +114,6 @@ impl From<KeyCode> for crossterm::event::KeyCode {
KeyCode::PageUp => CKeyCode::PageUp, KeyCode::PageUp => CKeyCode::PageUp,
KeyCode::PageDown => CKeyCode::PageDown, KeyCode::PageDown => CKeyCode::PageDown,
KeyCode::Tab => CKeyCode::Tab, KeyCode::Tab => CKeyCode::Tab,
KeyCode::BackTab => CKeyCode::BackTab,
KeyCode::Delete => CKeyCode::Delete, KeyCode::Delete => CKeyCode::Delete,
KeyCode::Insert => CKeyCode::Insert, KeyCode::Insert => CKeyCode::Insert,
KeyCode::F(f_number) => CKeyCode::F(f_number), KeyCode::F(f_number) => CKeyCode::F(f_number),
@ -144,7 +141,7 @@ impl From<crossterm::event::KeyCode> for KeyCode {
CKeyCode::PageUp => KeyCode::PageUp, CKeyCode::PageUp => KeyCode::PageUp,
CKeyCode::PageDown => KeyCode::PageDown, CKeyCode::PageDown => KeyCode::PageDown,
CKeyCode::Tab => KeyCode::Tab, CKeyCode::Tab => KeyCode::Tab,
CKeyCode::BackTab => KeyCode::BackTab, CKeyCode::BackTab => unreachable!("BackTab should have been handled on KeyEvent level"),
CKeyCode::Delete => KeyCode::Delete, CKeyCode::Delete => KeyCode::Delete,
CKeyCode::Insert => KeyCode::Insert, CKeyCode::Insert => KeyCode::Insert,
CKeyCode::F(f_number) => KeyCode::F(f_number), CKeyCode::F(f_number) => KeyCode::F(f_number),

Loading…
Cancel
Save