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 name: &'static str,

View File

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

View File

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