/
githubmirror
/
tabby
Обзор
Документация
Войти
/
githubmirror
/
tabby
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tabby-settings/src/components/hotkeySettingsTab.component.ts
97 строк
3 KB
Utkarsh Adhran
fix(settings): guard hotkey config lookup for missing plugin paths (#11422)
11 июл 2026, 12:37
Не верифицирован
11 июл 2026, 12:37
1b1f8e0
Код
Авторство
О чём код?
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker' import { Component, NgZone } from '@angular/core' import { ConfigService, Hotkey, HotkeyDescription, HotkeysService, HostAppService, PlatformService } from 'tabby-core' _('Search hotkeys') /** @hidden */ @Component({ selector: 'hotkey-settings-tab', templateUrl: './hotkeySettingsTab.component.pug', styleUrls: ['./hotkeySettingsTab.component.scss'], }) export class HotkeySettingsTabComponent { hotkeyFilter = '' hotkeyDescriptions: HotkeyDescription[] allDuplicateHotkeys = this.getAllDuplicateHotkeys() constructor ( public config: ConfigService, public hostApp: HostAppService, public zone: NgZone, private platform: PlatformService, hotkeys: HotkeysService, ) { hotkeys.getHotkeyDescriptions().then(descriptions => { this.hotkeyDescriptions = descriptions }) } getHotkeys (id: string): Hotkey[] { let ptr: any = this.config.store.hotkeys for (const token of id.split('.')) { ptr = ptr?.[token] if (ptr == null) { return [] } } return Array.isArray(ptr) ? ptr.map(hotkey => this.detectDuplicates(hotkey)) : [] } setHotkeys (id: string, hotkeys: Hotkey[]) { let ptr: any = this.config.store let prop = 'hotkeys' for (const token of id.split(/\./g)) { if (ptr[prop] == null || typeof ptr[prop] !== 'object' || Array.isArray(ptr[prop])) { ptr[prop] = {} } ptr = ptr[prop] prop = token } ptr[prop] = hotkeys.map(hotkey => hotkey.strokes.length === 1 && Array.isArray(hotkey.strokes) ? hotkey.strokes[0] : hotkey.strokes, ) this.config.save() this.allDuplicateHotkeys = this.getAllDuplicateHotkeys() } copyId (id: string) { this.platform.setClipboard({ text: id, }) } hotkeyFilterFn (hotkey: HotkeyDescription, query: string): boolean { const s = hotkey.name + hotkey.id + this.getHotkeys(hotkey.id).map(h => h.strokes).toString() return s.toLowerCase().includes(query.toLowerCase()) } private getAllDuplicateHotkeys (): string[] { const allHotkeys = Object .values(this.config.store.hotkeys) .filter((value: unknown) => Array.isArray(value)) .flat() .map((hotkey: string | string[]) => this.toHotkeyIdentifier(hotkey)) return allHotkeys.filter(hotkey => allHotkeys.indexOf(hotkey) !== allHotkeys.lastIndexOf(hotkey)) } private detectDuplicates (strokes: string[] | string): Hotkey { const hotkeyIdentifier = this.toHotkeyIdentifier(strokes) const isDuplicate = this.allDuplicateHotkeys.includes(hotkeyIdentifier) return { strokes, isDuplicate } } private toHotkeyIdentifier (hotkey: string[] | string): string { return Array.isArray(hotkey) ? hotkey.join('$#!') : hotkey } }