oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2
3struct DocumentKeyboardBinding: Identifiable {
4 let action: String
5 let titleKey: String
6 let key: String
7 var command = false
8 var shift = false
9 var id: String { action + key + String(command) + String(shift) }
10 var display: String {
11 let glyph = key == "\t" ? "⇥" : key == "\r" ? "↩" : key.uppercased()
12 return (shift ? "⇧" : "") + (command ? "⌘" : "") + glyph
13 }
14}
15
16/// Both the native responder and the help sheet read this table.
17enum DocumentKeyboardBindings {
18 static let all: [DocumentKeyboardBinding] = [
19 .init(action: "jump", titleKey: "docs.jumpto.label", key: "k", command: true),
20 .init(action: "bold", titleKey: "docs.editor.toolbar.bold", key: "b", command: true),
21 .init(action: "italic", titleKey: "docs.editor.toolbar.italic", key: "i", command: true),
22 .init(action: "undo", titleKey: "docs.editor.toolbar.undo", key: "z", command: true),
23 .init(action: "redo", titleKey: "docs.editor.toolbar.redo", key: "z", command: true, shift: true),
24 .init(action: "redo", titleKey: "docs.editor.toolbar.redo", key: "y", command: true),
25 .init(action: "indent", titleKey: "docs.editor.shortcuts.indent", key: "\t"),
26 .init(action: "outdent", titleKey: "docs.editor.shortcuts.outdent", key: "\t", shift: true),
27 .init(action: "hard-break", titleKey: "docs.editor.shortcuts.linebreak", key: "\r", shift: true),
28 ]
29 static func action(key: String, command: Bool, shift: Bool, option: Bool = false, control: Bool = false) -> String? {
30 guard !option, !control else { return nil }
31 let key = key == "\n" ? "\r" : key.lowercased()
32 return all.first { $0.key == key && $0.command == command && $0.shift == shift }?.action
33 }
34}
35