mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-28 03:48:34 +00:00
improve hotkey filter performance
This commit is contained in:

committed by
Eugene

parent
9fd23779b0
commit
c57a7e73ea
@@ -8,7 +8,6 @@ import {
|
|||||||
HotkeysService,
|
HotkeysService,
|
||||||
HostAppService,
|
HostAppService,
|
||||||
} from 'tabby-core'
|
} from 'tabby-core'
|
||||||
import deepEqual from 'deep-equal'
|
|
||||||
|
|
||||||
_('Search hotkeys')
|
_('Search hotkeys')
|
||||||
|
|
||||||
@@ -20,6 +19,7 @@ _('Search hotkeys')
|
|||||||
export class HotkeySettingsTabComponent {
|
export class HotkeySettingsTabComponent {
|
||||||
hotkeyFilter = ''
|
hotkeyFilter = ''
|
||||||
hotkeyDescriptions: HotkeyDescription[]
|
hotkeyDescriptions: HotkeyDescription[]
|
||||||
|
allDuplicateHotkeys = this.getAllDuplicateHotkeys()
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
public config: ConfigService,
|
public config: ConfigService,
|
||||||
@@ -53,6 +53,7 @@ export class HotkeySettingsTabComponent {
|
|||||||
: hotkey.strokes,
|
: hotkey.strokes,
|
||||||
)
|
)
|
||||||
this.config.save()
|
this.config.save()
|
||||||
|
this.allDuplicateHotkeys = this.getAllDuplicateHotkeys()
|
||||||
}
|
}
|
||||||
|
|
||||||
hotkeyFilterFn (hotkey: HotkeyDescription, query: string): boolean {
|
hotkeyFilterFn (hotkey: HotkeyDescription, query: string): boolean {
|
||||||
@@ -60,16 +61,23 @@ export class HotkeySettingsTabComponent {
|
|||||||
return s.toLowerCase().includes(query.toLowerCase())
|
return s.toLowerCase().includes(query.toLowerCase())
|
||||||
}
|
}
|
||||||
|
|
||||||
private detectDuplicates (strokes: string[] | string): Hotkey {
|
private getAllDuplicateHotkeys (): string[] {
|
||||||
const allHotkeys = Object
|
const allHotkeys = Object
|
||||||
.values(this.config.store.hotkeys)
|
.values(this.config.store.hotkeys)
|
||||||
.filter((value: unknown) => Array.isArray(value))
|
.filter((value: unknown) => Array.isArray(value))
|
||||||
.flat()
|
.flat()
|
||||||
|
.map((hotkey: string | string[]) => this.toHotkeyIdentifier(hotkey))
|
||||||
|
|
||||||
const isDuplicate = allHotkeys
|
return allHotkeys.filter(hotkey => allHotkeys.indexOf(hotkey) !== allHotkeys.lastIndexOf(hotkey))
|
||||||
.filter(hotkey => deepEqual(hotkey, strokes))
|
}
|
||||||
.length > 1
|
|
||||||
|
|
||||||
|
private detectDuplicates (strokes: string[] | string): Hotkey {
|
||||||
|
const hotkeyIdentifier = this.toHotkeyIdentifier(strokes)
|
||||||
|
const isDuplicate = this.allDuplicateHotkeys.includes(hotkeyIdentifier)
|
||||||
return { strokes, isDuplicate }
|
return { strokes, isDuplicate }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private toHotkeyIdentifier (hotkey: string[] | string): string {
|
||||||
|
return Array.isArray(hotkey) ? hotkey.join('$#!') : hotkey
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user