charselect: add option to cycle to previous group of characters
This commit is contained in:
1 parent
66c267ef28
commit
cd2c2a1a83
3 files changed
+51
-25
No files matched your search
+31
-16
@@ -335,25 +335,40 @@ pub enum CharSelectGroup {
|
||||
UnicodeNames,
|
||||
}
|
||||
|
||||
impl CharSelectGroup {
|
||||
pub fn next(self) -> Self {
|
||||
match self {
|
||||
Self::RecentlyUsed => Self::SmileysAndEmotion,
|
||||
Self::SmileysAndEmotion => Self::PeopleAndBody,
|
||||
Self::PeopleAndBody => Self::AnimalsAndNature,
|
||||
Self::AnimalsAndNature => Self::FoodAndDrink,
|
||||
Self::FoodAndDrink => Self::TravelAndPlaces,
|
||||
Self::TravelAndPlaces => Self::Activities,
|
||||
Self::Activities => Self::Objects,
|
||||
Self::Objects => Self::Symbols,
|
||||
Self::Symbols => Self::Flags,
|
||||
Self::Flags => Self::NerdFonts,
|
||||
Self::NerdFonts => Self::UnicodeNames,
|
||||
Self::UnicodeNames => Self::RecentlyUsed,
|
||||
// next is default, previous is the reverse
|
||||
macro_rules! char_select_group_impl_next_prev {
|
||||
($($x:ident => $y:ident),+ $(,)?) => {
|
||||
impl CharSelectGroup {
|
||||
pub const fn next(self) -> Self {
|
||||
match self {
|
||||
$(CharSelectGroup::$x => CharSelectGroup::$y),+
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn previous(self) -> Self {
|
||||
match self {
|
||||
$(CharSelectGroup::$y => CharSelectGroup::$x),+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char_select_group_impl_next_prev! (
|
||||
RecentlyUsed => SmileysAndEmotion,
|
||||
SmileysAndEmotion => PeopleAndBody,
|
||||
PeopleAndBody => AnimalsAndNature,
|
||||
AnimalsAndNature => FoodAndDrink,
|
||||
FoodAndDrink => TravelAndPlaces,
|
||||
TravelAndPlaces => Activities,
|
||||
Activities => Objects,
|
||||
Objects => Symbols,
|
||||
Symbols => Flags,
|
||||
Flags => NerdFonts,
|
||||
NerdFonts => UnicodeNames,
|
||||
UnicodeNames => RecentlyUsed,
|
||||
);
|
||||
|
||||
impl Default for CharSelectGroup {
|
||||
fn default() -> Self {
|
||||
Self::SmileysAndEmotion
|
||||
|
||||
@@ -23,15 +23,16 @@ Characters are categorized into the following groups:
|
||||
|
||||
The following key assignments are available (they are not currently configurable):
|
||||
|
||||
|Key | Action |
|
||||
|----------|--------|
|
||||
|UpArrow |Move Up |
|
||||
|DownArrow |Move Down|
|
||||
|Enter |Accept the current item, copy it to the clipboard, insert it into the active pane, and cancel the modal|
|
||||
|Esc |Cancel the modal|
|
||||
|CTRL-g |Cancel the modal|
|
||||
|CTRL-r |Cycle to the next group of characters|
|
||||
|CTRL-u |Clear text input|
|
||||
|Key | Action |
|
||||
|----------------|--------|
|
||||
|UpArrow |Move Up |
|
||||
|DownArrow |Move Down|
|
||||
|Enter |Accept the current item, copy it to the clipboard, insert it into the active pane, and cancel the modal|
|
||||
|Esc |Cancel the modal|
|
||||
|CTRL-g |Cancel the modal|
|
||||
|CTRL-r |Cycle to the next group of characters|
|
||||
|CTRL-SHIFT-r |Cycle to the previous group of characters|
|
||||
|CTRL-u |Clear text input|
|
||||
|
||||
Typing a name or a hex unicode codepoint value will fuzzy search across all
|
||||
possible groups (not just the current group) and filter the results.
|
||||
|
||||
@@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::path::PathBuf;
|
||||
use termwiz::input::Modifiers;
|
||||
use wezterm_term::{KeyCode, KeyModifiers, MouseEvent};
|
||||
use window::color::LinearRgba;
|
||||
|
||||
@@ -551,6 +552,8 @@ impl Modal for CharSelector {
|
||||
mods: KeyModifiers,
|
||||
term_window: &mut TermWindow,
|
||||
) -> anyhow::Result<()> {
|
||||
const CTRL_AND_SHIFT: Modifiers = KeyModifiers::CTRL.union(KeyModifiers::SHIFT);
|
||||
|
||||
match (key, mods) {
|
||||
(KeyCode::Escape, KeyModifiers::NONE) | (KeyCode::Char('g'), KeyModifiers::CTRL) => {
|
||||
term_window.cancel_modal();
|
||||
@@ -562,6 +565,13 @@ impl Modal for CharSelector {
|
||||
self.selection.borrow_mut().clear();
|
||||
self.updated_input();
|
||||
}
|
||||
(KeyCode::Char('R'), KeyModifiers::CTRL) | (KeyCode::Char('r'), CTRL_AND_SHIFT) => {
|
||||
// Cycle the selected group in reverse direction
|
||||
let mut group = self.group.borrow_mut();
|
||||
*group = group.previous();
|
||||
self.selection.borrow_mut().clear();
|
||||
self.updated_input();
|
||||
}
|
||||
(KeyCode::UpArrow, KeyModifiers::NONE) => {
|
||||
self.move_up();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user