tmp
This commit is contained in:
parent
11eba96cb8
commit
a4f259066b
1 changed files with 28 additions and 2 deletions
|
@ -35,7 +35,7 @@ pub enum Event {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Command {
|
struct Command {
|
||||||
name: &'static str,
|
name: String,
|
||||||
action: Box<dyn Action>,
|
action: Box<dyn Action>,
|
||||||
keystrokes: Vec<Keystroke>,
|
keystrokes: Vec<Keystroke>,
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ impl CommandPalette {
|
||||||
let actions = cx
|
let actions = cx
|
||||||
.available_actions(cx.window_id(), focused_view_id)
|
.available_actions(cx.window_id(), focused_view_id)
|
||||||
.map(|(name, action, bindings)| Command {
|
.map(|(name, action, bindings)| Command {
|
||||||
name,
|
name: humanize(name),
|
||||||
action,
|
action,
|
||||||
keystrokes: bindings
|
keystrokes: bindings
|
||||||
.last()
|
.last()
|
||||||
|
@ -259,6 +259,30 @@ impl PickerDelegate for CommandPalette {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn humanize(name: &str) -> String {
|
||||||
|
let capacity = name.len() + name.chars().filter(|c| c.is_uppercase()).count();
|
||||||
|
let mut result = String::with_capacity(capacity);
|
||||||
|
let mut prev_char = '\0';
|
||||||
|
for char in name.chars() {
|
||||||
|
if char == ':' {
|
||||||
|
if prev_char == ':' {
|
||||||
|
result.push(' ');
|
||||||
|
} else {
|
||||||
|
result.push(':');
|
||||||
|
}
|
||||||
|
} else if char.is_uppercase() {
|
||||||
|
if prev_char.is_lowercase() {
|
||||||
|
result.push(' ');
|
||||||
|
}
|
||||||
|
result.push(char);
|
||||||
|
} else {
|
||||||
|
result.push(char);
|
||||||
|
}
|
||||||
|
prev_char = char;
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for Command {
|
impl std::fmt::Debug for Command {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.debug_struct("Command")
|
f.debug_struct("Command")
|
||||||
|
@ -267,3 +291,5 @@ impl std::fmt::Debug for Command {
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[cfg(test)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue