feat: better uppercased management

This commit is contained in:
graelo 2021-03-14 20:53:50 +01:00
parent 8e7b1a2d05
commit b5adef94e5
2 changed files with 7 additions and 4 deletions

View file

@ -89,7 +89,6 @@ fn main() -> Result<(), error::ParseError> {
// Finally copy selection to a tmux buffer, and paste it to the active // Finally copy selection to a tmux buffer, and paste it to the active
// buffer if it was uppercased. // buffer if it was uppercased.
// TODO: consider getting rid of multi-selection mode.
match selections { match selections {
None => return Ok(()), None => return Ok(()),

View file

@ -408,6 +408,7 @@ impl<'a> Ui<'a> {
return Event::Exit; return Event::Exit;
} }
let mut uppercased = false;
let mut typed_hint = String::new(); let mut typed_hint = String::new();
self.full_render(writer); self.full_render(writer);
@ -468,7 +469,7 @@ impl<'a> Ui<'a> {
} }
// Yank/copy // Yank/copy
event::Key::Char(_ch @ 'y') => { event::Key::Char(_ch @ 'y') | event::Key::Char(_ch @ '\n') => {
let text = self.matches.get(self.focus_index).unwrap().text; let text = self.matches.get(self.focus_index).unwrap().text;
return Event::Match((text.to_string(), false)); return Event::Match((text.to_string(), false));
} }
@ -477,13 +478,17 @@ impl<'a> Ui<'a> {
return Event::Match((text.to_string(), true)); return Event::Match((text.to_string(), true));
} }
// TODO: use a Trie or another data structure to determine // Use a Trie or another data structure to determine
// if the entered key belongs to a longer hint. // if the entered key belongs to a longer hint.
// Attempts at finding a match with a corresponding hint. // Attempts at finding a match with a corresponding hint.
//
// If any of the typed character is caps, the typed hint is
// deemed as uppercased.
event::Key::Char(ch) => { event::Key::Char(ch) => {
let key = ch.to_string(); let key = ch.to_string();
let lower_key = key.to_lowercase(); let lower_key = key.to_lowercase();
uppercased = uppercased || (key != lower_key);
typed_hint.push_str(&lower_key); typed_hint.push_str(&lower_key);
let node = self let node = self
@ -503,7 +508,6 @@ impl<'a> Ui<'a> {
); );
let mat = self.matches.get(*match_index).expect("By construction, the value in a leaf should correspond to an existing hint."); let mat = self.matches.get(*match_index).expect("By construction, the value in a leaf should correspond to an existing hint.");
let text = mat.text.to_string(); let text = mat.text.to_string();
let uppercased = key != lower_key;
return Event::Match((text, uppercased)); return Event::Match((text, uppercased));
} else { } else {
// The prefix of a hint was entered, but we // The prefix of a hint was entered, but we