Sources/OrgApp/KeymapLoader.swift

d8259fc2c727995f7e45dd89b04231a66a65862a
orgstar/Sources/OrgApp/KeymapLoader.swift

21 lines · 854 bytes

 1import Foundation
 2import OrgCore
 3
 4@MainActor
 5public enum KeymapLoader {
 6    /// `<data dir>/keymap.toml`.
 7    public static var userFile: URL { UserConfig.file("keymap.toml") }
 8
 9    /// The preset with the user's file on top, and the problems found in the file. A missing
10    /// file adds nothing; a file that isn't valid TOML adds nothing and is reported.
11    public static func load(_ preset: KeymapPreset, userFile: URL = userFile) -> (keymap: Keymap, problems: [String]) {
12        guard let text = try? String(contentsOf: userFile, encoding: .utf8) else { return (preset.keymap, []) }
13        var problems: [String] = []
14        do {
15            let user = try Keymap(toml: text, problems: &problems)
16            return (.layered([preset.keymap, user]), problems)
17        } catch {
18            return (preset.keymap, ["\(error)"])
19        }
20    }
21}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form