better help sorting

This commit is contained in:
Stephan Dilly 2020-04-03 16:40:30 +02:00
parent 6001593a0a
commit 448b6927c3
3 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/// ///
#[derive(Copy, Clone)] #[derive(Copy, Clone, PartialEq, PartialOrd, Ord, Eq)]
pub struct CommandText { pub struct CommandText {
/// ///
pub name: &'static str, pub name: &'static str,

View File

@ -127,6 +127,8 @@ impl HelpComponent {
/// ///
pub fn set_cmds(&mut self, cmds: Vec<CommandInfo>) { pub fn set_cmds(&mut self, cmds: Vec<CommandInfo>) {
self.cmds = cmds; self.cmds = cmds;
self.cmds.sort_by_key(|e| e.text);
self.cmds.dedup_by_key(|e| e.text);
self.cmds.sort_by_key(|e| hash(&e.text.group)); self.cmds.sort_by_key(|e| hash(&e.text.group));
} }
@ -162,6 +164,7 @@ impl HelpComponent {
txt.extend( txt.extend(
group group
.into_iter() .into_iter()
.sorted_by_key(|e| e.order)
.map(|e| { .map(|e| {
let is_selected = self.selection == processed; let is_selected = self.selection == processed;
if is_selected { if is_selected {

View File

@ -35,7 +35,7 @@ pub mod commands {
/// ///
pub static CLOSE_POPUP: CommandText = CommandText::new( pub static CLOSE_POPUP: CommandText = CommandText::new(
"Close [esc]", "Close [esc]",
"close popup", "close overlay (e.g commit, help)",
CMD_GROUP_GENERAL, CMD_GROUP_GENERAL,
); );
/// ///
@ -90,7 +90,7 @@ pub mod commands {
pub static STATUS_FOCUS_RIGHT: CommandText = CommandText::new( pub static STATUS_FOCUS_RIGHT: CommandText = CommandText::new(
"Diff [\u{2192}]", //→ "Diff [\u{2192}]", //→
"inspect file diff", "inspect file diff",
CMD_GROUP_GENERAL, CMD_GROUP_CHANGES,
); );
/// ///
pub static QUIT: CommandText = CommandText::new( pub static QUIT: CommandText = CommandText::new(