match()

in packages/core/src/models/Shortcut.ts [56:72]


  match(codes: KeyCode[], context: IEngineContext) {
    return this.codes.some((sequence) => {
      const sortedSelf = Shortcut.sortCodes(sequence)
      const sortedTarget: KeyCode[] = Shortcut.sortCodes(codes)
      if (isFn(this.matcher)) {
        return this.matched(this.matcher(sortedTarget), context)
      }
      if (sortedTarget.length !== sortedSelf.length)
        return this.matched(false, context)
      for (let i = 0; i < sortedSelf.length; i++) {
        if (!Shortcut.matchCode(sortedTarget[i], sortedSelf[i])) {
          return this.matched(false, context)
        }
      }
      return this.matched(true, context)
    })
  }