launcher: Add ctrl k/u handling
This commit is contained in:
@@ -13,7 +13,8 @@ pub const XKB_KEY_Down: u32 = 0xff54; /* Move down, down arrow */
|
||||
pub const XKB_KEY_End: u32 = 0xff57; /* EOL */
|
||||
|
||||
//pub const XKB_KEY_ISO_Left_Tab: u32 = 0xfe20;
|
||||
pub const XKB_KEY_e: u32 = 0x0065; /* U+0065 LATIN SMALL LETTER E */
|
||||
pub const XKB_KEY_a: u32 = 0x0061; /* U+0061 LATIN SMALL LETTER A */
|
||||
pub const XKB_KEY_e: u32 = 0x0065; /* U+0065 LATIN SMALL LETTER E */
|
||||
//pub const XKB_KEY_c: u32 = 0x0063; /* U+0063 LATIN SMALL LETTER C */
|
||||
//pub const XKB_KEY_u: u32 = 0x0075; /* U+0075 LATIN SMALL LETTER U */
|
||||
pub const XKB_KEY_k: u32 = 0x006b; /* U+006B LATIN SMALL LETTER K */
|
||||
pub const XKB_KEY_u: u32 = 0x0075; /* U+0075 LATIN SMALL LETTER U */
|
||||
|
||||
+45
-9
@@ -130,20 +130,46 @@ impl Prompt {
|
||||
|
||||
fn backspace(&mut self) {
|
||||
let mut indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect();
|
||||
if !indices.is_empty() && self.cursor > 0 {
|
||||
self.cursor -= 1;
|
||||
indices.remove(self.cursor);
|
||||
self.input = indices.iter().fold("".into(), |acc, el| acc + el.1);
|
||||
if indices.is_empty() {
|
||||
self.mode = PromptMode::Normal;
|
||||
return;
|
||||
}
|
||||
if self.cursor == 0 {
|
||||
return;
|
||||
}
|
||||
self.cursor -= 1;
|
||||
indices.remove(self.cursor);
|
||||
self.input = indices.iter().fold("".into(), |acc, el| acc + el.1);
|
||||
}
|
||||
|
||||
fn delete(&mut self) {
|
||||
let mut indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect();
|
||||
if indices.is_empty() {
|
||||
self.mode = PromptMode::Normal;
|
||||
return;
|
||||
}
|
||||
if self.cursor >= indices.len() {
|
||||
return;
|
||||
}
|
||||
|
||||
indices.remove(self.cursor);
|
||||
self.input = indices.iter().fold("".into(), |acc, el| acc + el.1);
|
||||
}
|
||||
|
||||
fn clear_right(&mut self) {
|
||||
let indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect();
|
||||
if !indices.is_empty() {
|
||||
self.input = indices[0..self.cursor].iter().fold("".into(), |acc, el| acc + el.1);
|
||||
} else {
|
||||
self.mode = PromptMode::Normal;
|
||||
}
|
||||
}
|
||||
|
||||
fn delete(&mut self) {
|
||||
let mut indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect();
|
||||
if !indices.is_empty() && self.cursor < indices.len() {
|
||||
indices.remove(self.cursor);
|
||||
self.input = indices.iter().fold("".into(), |acc, el| acc + el.1);
|
||||
fn clear_left(&mut self) {
|
||||
let indices: Vec<(usize, &str)> = self.input.grapheme_indices(true).collect();
|
||||
if !indices.is_empty() {
|
||||
self.input = indices[self.cursor..indices.len()].iter().fold("".into(), |acc, el| acc + el.1);
|
||||
self.cursor = 0;
|
||||
} else {
|
||||
self.mode = PromptMode::Normal;
|
||||
}
|
||||
@@ -524,6 +550,16 @@ impl Widget for Interface {
|
||||
match event.keysym {
|
||||
keysyms::XKB_KEY_a if event.modifiers.ctrl => self.inner.prompt.home(),
|
||||
keysyms::XKB_KEY_e if event.modifiers.ctrl => self.inner.prompt.end(),
|
||||
keysyms::XKB_KEY_u if event.modifiers.ctrl => {
|
||||
self.inner.prompt.clear_left();
|
||||
self.inner.selection = 0;
|
||||
widget.update(&self.inner);
|
||||
},
|
||||
keysyms::XKB_KEY_k if event.modifiers.ctrl => {
|
||||
self.inner.prompt.clear_right();
|
||||
self.inner.selection = 0;
|
||||
widget.update(&self.inner);
|
||||
},
|
||||
keysyms::XKB_KEY_Home => self.inner.prompt.home(),
|
||||
keysyms::XKB_KEY_End => self.inner.prompt.end(),
|
||||
keysyms::XKB_KEY_BackSpace => {
|
||||
|
||||
Reference in New Issue
Block a user