Improve search in keyboard shortcuts overview (#2918)

* improve search in keyboard shortcuts overview

* Update CHANGELOG.md
This commit is contained in:
Benno Straub 2024-01-13 16:41:07 +01:00 committed by GitHub
parent f3d1719ca7
commit 9bddebda16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 10 deletions

View File

@ -6,6 +6,7 @@
- [#2723](https://github.com/lapce/lapce/pull/2723): Line wrapping based on width (no column-based yet)
- [#1277](https://github.com/lapce/lapce/pull/1277): Error message prompted on missing git user.email and/or user.name
- [#2910](https://github.com/lapce/lapce/pull/2910): Files can be compared in the diff editor
- [#2918](https://github.com/lapce/lapce/pull/2918): Allow searching the shortcuts overview by shortcut (e.g. "Ctrl+P") or when condition (e.g. "list_focus")
### Bug Fixes
- [#2779](https://github.com/lapce/lapce/pull/2779): Fix files detection on fresh git/VCS repository

View File

@ -57,17 +57,33 @@ pub fn keymap_view(common: Rc<CommonData>) -> impl View {
.iter()
.filter_map(|keymap| {
let cmd = keypress.commands.get(&keymap.command).cloned()?;
let match_pattern =
cmd.kind.str().replace('_', " ").contains(&pattern)
|| cmd
.kind
.desc()
.map(|desc| desc.to_lowercase().contains(&pattern))
.unwrap_or(false);
if !match_pattern {
return None;
let cmd_name_contains_pattern =
cmd.kind.str().replace('_', " ").contains(&pattern);
let cmd_desc_contains_pattern = cmd
.kind
.desc()
.map(|desc| desc.to_lowercase().contains(&pattern))
.unwrap_or(false);
let shortcut_contains_pattern = keymap
.key
.iter()
.any(|k| k.label().trim().to_lowercase().contains(&pattern));
let when_contains_pattern = keymap
.when
.as_ref()
.map(|when| when.to_lowercase().contains(&pattern))
.unwrap_or(false);
if cmd_name_contains_pattern
|| cmd_desc_contains_pattern
|| shortcut_contains_pattern
|| when_contains_pattern
{
Some((cmd, Some(keymap.clone())))
} else {
None
}
Some((cmd, Some(keymap.clone())))
})
.collect::<im::Vector<(LapceCommand, Option<KeyMap>)>>();
items.extend(keypress.commands_without_keymap.iter().filter_map(|cmd| {