Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

1009 B
Raw Blame
import { Component, inject, signal } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'

const SYMBOLS = {
  meta: '⌘', // ⌘
  control: '⌃', // ⌃
  shift: '⇧', // ⇧
  left: '←', // ←
  right: '→', // →
  up: '↑', // ↑
  down: '↓', // ↓
  arrowleft: '←', // ←
  arrowright: '→', // →
}

@Component({
  selector: 'pngx-hotkey-dialog',
  templateUrl: './hotkey-dialog.component.html',
  styleUrl: './hotkey-dialog.component.scss',
})
export class HotkeyDialogComponent {
  activeModal = inject(NgbActiveModal)
  readonly title = signal($localize`Keyboard shortcuts`)
  readonly hotkeys = signal<Map<string, string>>(new Map())

  public close(): void {
    this.activeModal.close()
  }

  public formatKey(key: string, macOS: boolean = false): string {
    if (macOS) {
      key = key.replace('control', 'meta')
    }
    return key
      .split('.')
      .map((k) => SYMBOLS[k] || k)
      .join(' ')
  }
}