mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-22 20:40:08 +00:00
perf: faster hotkey matching
This commit is contained in:
parent
7fcf632378
commit
8269a8e01b
@ -128,15 +128,18 @@ export class HotkeysService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCurrentFullyMatchedHotkey (): string {
|
getCurrentFullyMatchedHotkey (): string {
|
||||||
for (let id in this.getHotkeysConfig()) {
|
let currentStrokes = this.getCurrentKeystrokes()
|
||||||
for (let sequence of this.getHotkeysConfig()[id]) {
|
let config = this.getHotkeysConfig()
|
||||||
let currentStrokes = this.getCurrentKeystrokes()
|
for (let id in config) {
|
||||||
|
for (let sequence of config[id]) {
|
||||||
if (currentStrokes.length < sequence.length) {
|
if (currentStrokes.length < sequence.length) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (sequence.every((x, index) => {
|
if (sequence.every(
|
||||||
return x.toLowerCase() === currentStrokes[currentStrokes.length - sequence.length + index].toLowerCase()
|
(x, index) =>
|
||||||
})) {
|
x.toLowerCase() ===
|
||||||
|
currentStrokes[currentStrokes.length - sequence.length + index].toLowerCase()
|
||||||
|
)) {
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,15 +148,17 @@ export class HotkeysService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCurrentPartiallyMatchedHotkeys (): PartialHotkeyMatch[] {
|
getCurrentPartiallyMatchedHotkeys (): PartialHotkeyMatch[] {
|
||||||
|
let currentStrokes = this.getCurrentKeystrokes()
|
||||||
|
let config = this.getHotkeysConfig()
|
||||||
let result = []
|
let result = []
|
||||||
for (let id in this.getHotkeysConfig()) {
|
for (let id in config) {
|
||||||
for (let sequence of this.getHotkeysConfig()[id]) {
|
for (let sequence of config[id]) {
|
||||||
let currentStrokes = this.getCurrentKeystrokes()
|
|
||||||
|
|
||||||
for (let matchLength = Math.min(currentStrokes.length, sequence.length); matchLength > 0; matchLength--) {
|
for (let matchLength = Math.min(currentStrokes.length, sequence.length); matchLength > 0; matchLength--) {
|
||||||
if (sequence.slice(0, matchLength).every((x, index) => {
|
if (sequence.slice(0, matchLength).every(
|
||||||
return x.toLowerCase() === currentStrokes[currentStrokes.length - matchLength + index].toLowerCase()
|
(x, index) =>
|
||||||
})) {
|
x.toLowerCase() ===
|
||||||
|
currentStrokes[currentStrokes.length - matchLength + index].toLowerCase()
|
||||||
|
)) {
|
||||||
result.push({
|
result.push({
|
||||||
matchedLength: matchLength,
|
matchedLength: matchLength,
|
||||||
id,
|
id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user