Commit d88176172f
Verified · cmc
Changed files (15)
- Sources/OrgApp/KeyBarLayout.swift added +86
- Sources/OrgApp/UserConfig.swift +71 −2
- Sources/OrgCore/Keymap/TOML.swift +77 −3
- Sources/OrgstarMobile/CommandList.swift +5 −2
- Sources/OrgstarMobile/EditorScreen.swift +8 −157
- Sources/OrgstarMobile/KeyBar.swift added +271
- Sources/OrgstarMobile/KeyBarSettings.swift added +102
- Sources/OrgstarMobile/MobileEditor.swift +12 −1
- Sources/OrgstarMobile/MobileModel.swift +17
- Sources/OrgstarMobile/SettingsScreen.swift +5
- Tests/OrgAppTests/KeyBarLayoutTests.swift added +108
- Tests/OrgCoreTests/KeymapTests.swift +18
- docs/manual/guide/13-configuration.org +34
- docs/manual/guide/14-ios.org +14 −2
- l10n/Localizable.xcstrings +344
Sources/OrgApp/KeyBarLayout.swift added +86 · view
| @@ -0,0 +1,86 @@ | ||
| 1 | import Foundation | |
| 2 | import OrgCore | |
| 3 | ||
| 4 | /// The iOS key bar's buttons, `[key-bar]` in config.toml: `iphone` and `ipad`, each a list of | |
| 5 | /// command ids in order. The Mac has no key bar and only reads the table, so the file is the | |
| 6 | /// same on both. | |
| 7 | public enum KeyBarLayout { | |
| 8 | public static let table = "key-bar" | |
| 9 | ||
| 10 | /// Which list a bar uses: `iphone` where the editor is narrow (iPhone, and iPad in Slide | |
| 11 | /// Over or a narrow split), `ipad` where it is wide. | |
| 12 | public enum Width: String, CaseIterable, Sendable { | |
| 13 | case iphone, ipad | |
| 14 | ||
| 15 | /// Where the list is kept, its ids one per line; absent means the default. | |
| 16 | public var defaultsKey: String { self == .iphone ? "keyBarIPhone" : "keyBarIPad" } | |
| 17 | ||
| 18 | public var defaultIDs: [String] { | |
| 19 | ["commands", "fold", "promote", "demote", "move-up", "move-down", "new-heading", "todo", "act"] | |
| 20 | + (self == .ipad ? ["schedule", "deadline", "tags"] : ["plan"]) + ["hide-keyboard"] | |
| 21 | } | |
| 22 | } | |
| 23 | ||
| 24 | public static let nextField = "org.snippet.next-field" | |
| 25 | public static let previousField = "org.snippet.previous-field" | |
| 26 | ||
| 27 | /// The list `defaults` holds for `width`, or nil for the default. Repeated ids count once. | |
| 28 | public static func stored(_ width: Width, in defaults: UserDefaults) -> [String]? { | |
| 29 | defaults.string(forKey: width.defaultsKey).map(ids) | |
| 30 | } | |
| 31 | ||
| 32 | /// The ids of a stored list, each once. | |
| 33 | public static func ids(_ stored: String) -> [String] { | |
| 34 | var seen = Set<String>() | |
| 35 | return stored.split(separator: "\n").map(String.init).filter { seen.insert($0).inserted } | |
| 36 | } | |
| 37 | ||
| 38 | public static func store(_ ids: [String]?, _ width: Width, in defaults: UserDefaults) { | |
| 39 | guard let ids else { return defaults.removeObject(forKey: width.defaultsKey) } | |
| 40 | let joined = ids.joined(separator: "\n") | |
| 41 | if defaults.string(forKey: width.defaultsKey) != joined { defaults.set(joined, forKey: width.defaultsKey) } | |
| 42 | } | |
| 43 | ||
| 44 | /// The problems of a list whose ids `known` doesn't know, which the bar skips. | |
| 45 | public static func problems(_ ids: [String], _ width: Width, known: (String) -> Bool) -> [String] { | |
| 46 | ids.filter { !known($0) }.map { "config.toml: \(table).\(width.rawValue) has no command \($0)" } | |
| 47 | } | |
| 48 | ||
| 49 | /// While a snippet's fields are filled in: Previous Field and Next Field in place of | |
| 50 | /// Promote and Demote, which act on the heading or item rather than the snippet, or first | |
| 51 | /// when the bar lacks them. A bar that has them already is unchanged. | |
| 52 | public static func withSnippetFields(_ ids: [String]) -> [String] { | |
| 53 | var out = ids | |
| 54 | for (field, replaced) in [(previousField, "promote"), (nextField, "demote")] where !out.contains(field) { | |
| 55 | if let index = out.firstIndex(of: replaced) { out[index] = field } | |
| 56 | } | |
| 57 | return [previousField, nextField].filter { !out.contains($0) } + out | |
| 58 | } | |
| 59 | ||
| 60 | /// The buttons that fit in `available` slots, in order, and the rest, which go in a More | |
| 61 | /// button that takes a slot. A button takes `slots(id)` slots; past the first that doesn't | |
| 62 | /// fit, none show, so the order stays. | |
| 63 | public static func fit(_ ids: [String], available: Int, slots: (String) -> Int) -> (shown: [String], more: [String]) { | |
| 64 | guard ids.reduce(0, { $0 + slots($1) }) > available else { return (ids, []) } | |
| 65 | var used = 1 | |
| 66 | var shown: [String] = [] | |
| 67 | for id in ids { | |
| 68 | used += slots(id) | |
| 69 | guard used <= available else { break } | |
| 70 | shown.append(id) | |
| 71 | } | |
| 72 | return (shown, Array(ids.dropFirst(shown.count))) | |
| 73 | } | |
| 74 | ||
| 75 | /// The text on a button for a command without a symbol: its title without the `…` that | |
| 76 | /// says it asks something. | |
| 77 | public static func face(title: String) -> String { | |
| 78 | title.hasSuffix("…") ? String(title.dropLast()) : title | |
| 79 | } | |
| 80 | ||
| 81 | /// A button's width in slots: one for a symbol or a word of up to four letters, as TODO, | |
| 82 | /// two for longer text, which wraps onto two lines. | |
| 83 | public static func slots(symbol: Bool, face: String) -> Int { | |
| 84 | symbol || face.count <= 4 ? 1 : 2 | |
| 85 | } | |
| 86 | } | |
Sources/OrgApp/UserConfig.swift +71 −2 · view
| @@ -474,7 +474,28 @@ public enum UserConfig { | ||
| 474 | 474 | if !tables.contains(where: { $0.name == denoteTemplateTable }), defaults.object(forKey: denoteTemplatesKey) != nil { |
| 475 | 475 | defaults.removeObject(forKey: denoteTemplatesKey) |
| 476 | 476 | } |
| 477 | let keyBar = tables.first { $0.name == KeyBarLayout.table } | |
| 478 | for width in KeyBarLayout.Width.allCases where keyBar?.values[width.rawValue] == nil { | |
| 479 | if defaults.object(forKey: width.defaultsKey) != nil { defaults.removeObject(forKey: width.defaultsKey) } | |
| 480 | } | |
| 477 | 481 | for table in tables { |
| 482 | if table.name == KeyBarLayout.table { | |
| 483 | for key in table.keys { | |
| 484 | guard let width = KeyBarLayout.Width(rawValue: key) else { | |
| 485 | problems.append("config.toml: unknown setting \(path(table.name, key))") | |
| 486 | continue | |
| 487 | } | |
| 488 | let values = table.values[key]?.array | |
| 489 | let ids = values?.compactMap(\.string) ?? [] | |
| 490 | guard let values, ids.count == values.count else { | |
| 491 | problems.append("config.toml: \(path(table.name, key)) must be a list of command ids, such as [\"commands\", \"fold\"]") | |
| 492 | if defaults.object(forKey: width.defaultsKey) != nil { defaults.removeObject(forKey: width.defaultsKey) } | |
| 493 | continue | |
| 494 | } | |
| 495 | KeyBarLayout.store(ids, width, in: defaults) | |
| 496 | } | |
| 497 | continue | |
| 498 | } | |
| 478 | 499 | if table.name == denoteTemplateTable { |
| 479 | 500 | var rows: [String] = [] |
| 480 | 501 | for key in table.keys { |
| @@ -626,6 +647,7 @@ public enum UserConfig { | ||
| 626 | 647 | case .string(let s): |
| 627 | 648 | "\"" + s.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"") |
| 628 | 649 | .replacingOccurrences(of: "\n", with: "\\n").replacingOccurrences(of: "\t", with: "\\t") + "\"" |
| 650 | case .array(let values): "[" + values.map(format).joined(separator: ", ") + "]" | |
| 629 | 651 | } |
| 630 | 652 | } |
| 631 | 653 | |
| @@ -694,8 +716,9 @@ public enum UserConfig { | ||
| 694 | 716 | if !trimmed.isEmpty { lastInSection = index } |
| 695 | 717 | guard let equals = line.firstIndex(of: "="), |
| 696 | 718 | line[..<equals].trimmingCharacters(in: .whitespaces) == key else { continue } |
| 697 | let comment = commentStart(line, after: equals).map { " " + line[$0...] } ?? "" | |
| 698 | lines[index] = line[..<equals] + "= " + format(value) + comment | |
| 719 | let last = lastLine(of: lines, at: index, equals: equals) | |
| 720 | let comment = last == index ? commentStart(line, after: equals).map { " " + line[$0...] } ?? "" : "" | |
| 721 | lines.replaceSubrange(index...last, with: [line[..<equals] + "= " + format(value) + comment]) | |
| 699 | 722 | return lines.joined(separator: "\n") |
| 700 | 723 | } |
| 701 | 724 | if let lastInSection { |
| @@ -710,6 +733,52 @@ public enum UserConfig { | ||
| 710 | 733 | return lines.joined(separator: "\n") |
| 711 | 734 | } |
| 712 | 735 | |
| 736 | /// `text` without `section.key`, as `setting` finds it; unchanged when it isn't there. | |
| 737 | public static func removingSetting(_ text: String, section: String, key: String) -> String { | |
| 738 | var lines = text.components(separatedBy: "\n") | |
| 739 | var current = "" | |
| 740 | for (index, line) in lines.enumerated() { | |
| 741 | let trimmed = line.trimmingCharacters(in: .whitespaces) | |
| 742 | if trimmed.hasPrefix("[") { | |
| 743 | current = trimmed.hasPrefix("[[") ? trimmed : String(trimmed.dropFirst().prefix { $0 != "]" }).trimmingCharacters(in: .whitespaces) | |
| 744 | continue | |
| 745 | } | |
| 746 | guard current == section, let equals = line.firstIndex(of: "="), | |
| 747 | line[..<equals].trimmingCharacters(in: .whitespaces) == key else { continue } | |
| 748 | lines.removeSubrange(index...lastLine(of: lines, at: index, equals: equals)) | |
| 749 | return lines.joined(separator: "\n") | |
| 750 | } | |
| 751 | return text | |
| 752 | } | |
| 753 | ||
| 754 | /// The last line of the value on line `index`: a later one for an array whose closing | |
| 755 | /// bracket is on another line. | |
| 756 | private static func lastLine(of lines: [String], at index: Int, equals: String.Index) -> Int { | |
| 757 | let line = lines[index] | |
| 758 | guard line[line.index(after: equals)...].trimmingCharacters(in: .whitespaces).hasPrefix("[") else { return index } | |
| 759 | var depth = 0 | |
| 760 | var quote: Character? | |
| 761 | for number in index..<lines.count { | |
| 762 | var escaped = false | |
| 763 | for c in number == index ? line[line.index(after: equals)...] : Substring(lines[number]) { | |
| 764 | if let q = quote { | |
| 765 | if escaped { escaped = false } else if c == "\\" && q == "\"" { escaped = true } else if c == q { quote = nil } | |
| 766 | continue | |
| 767 | } | |
| 768 | if c == "#" { break } | |
| 769 | if c == "\"" || c == "'" { | |
| 770 | quote = c | |
| 771 | } else if c == "[" { | |
| 772 | depth += 1 | |
| 773 | } else if c == "]" { | |
| 774 | depth -= 1 | |
| 775 | if depth == 0 { return number } | |
| 776 | } | |
| 777 | } | |
| 778 | } | |
| 779 | return index | |
| 780 | } | |
| 781 | ||
| 713 | 782 | /// Where a `#` comment starts after the value, outside quotes. |
| 714 | 783 | private static func commentStart(_ line: String, after equals: String.Index) -> String.Index? { |
| 715 | 784 | var quote: Character? |
Sources/OrgCore/Keymap/TOML.swift +77 −3 · view
| @@ -1,13 +1,15 @@ | ||
| 1 | 1 | import Foundation |
| 2 | 2 | |
| 3 | 3 | /// The part of TOML keymaps use: `[table]` and `[[array-of-tables]]` headers, and |
| 4 | /// `key = value` lines with basic or literal strings (multi-line ones too), booleans and | |
| 5 | /// integers. Comments start with `#` outside strings. | |
| 4 | /// `key = value` lines with basic or literal strings (multi-line ones too), booleans, | |
| 5 | /// integers and arrays of these, which may run over several lines. Comments start with `#` | |
| 6 | /// outside strings. | |
| 6 | 7 | public enum TOML { |
| 7 | 8 | public enum Value: Sendable, Equatable { |
| 8 | 9 | case string(String) |
| 9 | 10 | case bool(Bool) |
| 10 | 11 | case integer(Int) |
| 12 | case array([Value]) | |
| 11 | 13 | |
| 12 | 14 | public var string: String? { |
| 13 | 15 | if case .string(let value) = self { return value } |
| @@ -23,6 +25,11 @@ public enum TOML { | ||
| 23 | 25 | if case .integer(let value) = self { return value } |
| 24 | 26 | return nil |
| 25 | 27 | } |
| 28 | ||
| 29 | public var array: [Value]? { | |
| 30 | if case .array(let value) = self { return value } | |
| 31 | return nil | |
| 32 | } | |
| 26 | 33 | } |
| 27 | 34 | |
| 28 | 35 | public struct Table: Sendable, Equatable { |
| @@ -83,6 +90,17 @@ public enum TOML { | ||
| 83 | 90 | let end = body.range(of: delimiter)! |
| 84 | 91 | value = .string(try multiline(String(body[..<end.lowerBound]), literal: delimiter == "\'\'\'", line: number)) |
| 85 | 92 | rest = body[end.upperBound...] |
| 93 | } else if rest.first == "[" { | |
| 94 | // An array runs to its closing bracket, on this line or a later one. | |
| 95 | var body = String(rest) | |
| 96 | while !closesArray(body) { | |
| 97 | guard index < lines.count else { throw ParseError(line: number, message: "unclosed array") } | |
| 98 | body += "\n" + lines[index].replacingOccurrences(of: "\r", with: "") | |
| 99 | index += 1 | |
| 100 | } | |
| 101 | var array = Substring(body) | |
| 102 | value = try parseValue(&array, line: number) | |
| 103 | rest = array | |
| 86 | 104 | } else { |
| 87 | 105 | value = try parseValue(&rest, line: number) |
| 88 | 106 | } |
| @@ -134,8 +152,64 @@ public enum TOML { | ||
| 134 | 152 | return out |
| 135 | 153 | } |
| 136 | 154 | |
| 155 | /// Whether `text`, starting with `[`, has the bracket that closes it, outside strings and | |
| 156 | /// comments. | |
| 157 | private static func closesArray(_ text: String) -> Bool { | |
| 158 | var depth = 0 | |
| 159 | var quote: Character? | |
| 160 | var comment = false | |
| 161 | var escaped = false | |
| 162 | for c in text { | |
| 163 | if comment { | |
| 164 | if c == "\n" { comment = false } | |
| 165 | } else if let q = quote { | |
| 166 | if escaped { escaped = false } else if c == "\\" && q == "\"" { escaped = true } else if c == q { quote = nil } | |
| 167 | } else { | |
| 168 | switch c { | |
| 169 | case "\"", "'": quote = c | |
| 170 | case "#": comment = true | |
| 171 | case "[": depth += 1 | |
| 172 | case "]": | |
| 173 | depth -= 1 | |
| 174 | if depth == 0 { return true } | |
| 175 | default: break | |
| 176 | } | |
| 177 | } | |
| 178 | } | |
| 179 | return false | |
| 180 | } | |
| 181 | ||
| 182 | /// Spaces, line ends and comments between an array's values. | |
| 183 | private static func skipBlanks(_ rest: inout Substring) { | |
| 184 | while let c = rest.first { | |
| 185 | if c.isWhitespace { | |
| 186 | rest = rest.dropFirst() | |
| 187 | } else if c == "#" { | |
| 188 | rest = rest.drop { $0 != "\n" } | |
| 189 | } else { | |
| 190 | return | |
| 191 | } | |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 137 | 195 | private static func parseValue(_ rest: inout Substring, line: Int) throws -> Value { |
| 138 | 196 | switch rest.first { |
| 197 | case "[": | |
| 198 | rest = rest.dropFirst() | |
| 199 | var values: [Value] = [] | |
| 200 | while true { | |
| 201 | skipBlanks(&rest) | |
| 202 | if rest.first == "]" { break } | |
| 203 | values.append(try parseValue(&rest, line: line)) | |
| 204 | skipBlanks(&rest) | |
| 205 | if rest.first == "," { | |
| 206 | rest = rest.dropFirst() | |
| 207 | } else if rest.first != "]" { | |
| 208 | throw ParseError(line: line, message: rest.isEmpty ? "unclosed array" : "expected , or ] in array") | |
| 209 | } | |
| 210 | } | |
| 211 | rest = rest.dropFirst() | |
| 212 | return .array(values) | |
| 139 | 213 | case "\"": |
| 140 | 214 | rest = rest.dropFirst() |
| 141 | 215 | var value = "" |
| @@ -171,7 +245,7 @@ public enum TOML { | ||
| 171 | 245 | rest = rest[rest.index(after: end)...] |
| 172 | 246 | return .string(value) |
| 173 | 247 | default: |
| 174 | let word = rest.prefix { !$0.isWhitespace && $0 != "#" } | |
| 248 | let word = rest.prefix { !$0.isWhitespace && $0 != "#" && $0 != "," && $0 != "]" } | |
| 175 | 249 | rest = rest.dropFirst(word.count) |
| 176 | 250 | if word == "true" { return .bool(true) } |
| 177 | 251 | if word == "false" { return .bool(false) } |
Sources/OrgstarMobile/CommandList.swift +5 −2 · view
| @@ -17,6 +17,9 @@ struct CommandRow: Identifiable { | ||
| 17 | 17 | /// subject; a query matches as the Mac's palette does. |
| 18 | 18 | struct CommandList: View { |
| 19 | 19 | let rows: [CommandRow] |
| 20 | var title = String(localized: "Commands") | |
| 21 | /// Choosing a command counts as running it, for Recent and the ranking. | |
| 22 | var recordsUse = true | |
| 20 | 23 | /// Called with the chosen command before the list closes. |
| 21 | 24 | let choose: (String) -> Void |
| 22 | 25 | @State private var query = "" |
| @@ -47,7 +50,7 @@ struct CommandList: View { | ||
| 47 | 50 | if !query.allSatisfy(\.isWhitespace), ranked.rest.isEmpty { ContentUnavailableView.search(text: query) } |
| 48 | 51 | } |
| 49 | 52 | .searchable(text: $query, placement: .navigationBarDrawer(displayMode: .always)) |
| 50 | .navigationTitle("Commands") | |
| 53 | .navigationTitle(title) | |
| 51 | 54 | .navigationBarTitleDisplayMode(.inline) |
| 52 | 55 | .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel") { dismiss() } } } |
| 53 | 56 | } |
| @@ -65,7 +68,7 @@ struct CommandList: View { | ||
| 65 | 68 | |
| 66 | 69 | private func row(_ command: CommandRow) -> some View { |
| 67 | 70 | Button { |
| 68 | CommandUsage.shared.record(command.id) | |
| 71 | if recordsUse { CommandUsage.shared.record(command.id) } | |
| 69 | 72 | choose(command.id) |
| 70 | 73 | dismiss() |
| 71 | 74 | } label: { |
Sources/OrgstarMobile/EditorScreen.swift +8 −157 · view
| @@ -805,159 +805,6 @@ struct EditorTextView: UIViewRepresentable { | ||
| 805 | 805 | } |
| 806 | 806 | } |
| 807 | 807 | |
| 808 | /// Org's keys for a touch keyboard: each button does what its key does at the caret, as the | |
| 809 | /// Emacs keymap binds it (M-→ demotes a heading, indents an item, moves a table column). It holds | |
| 810 | /// what is repeated at the caret while typing; the rest is in Commands. Its buttons share the | |
| 811 | /// width, without scrolling. | |
| 812 | struct KeyBar: View { | |
| 813 | let editor: MobileEditor | |
| 814 | let palette: () -> Void | |
| 815 | @Environment(\.horizontalSizeClass) private var sizeClass | |
| 816 | ||
| 817 | /// A button the bar can hold. | |
| 818 | struct Item { | |
| 819 | enum Action { | |
| 820 | /// What the keys are bound to at the caret. | |
| 821 | case keys(String) | |
| 822 | case command(String) | |
| 823 | case palette | |
| 824 | /// Schedule, Deadline and Tags in a menu. | |
| 825 | case plan | |
| 826 | case hideKeyboard | |
| 827 | } | |
| 828 | ||
| 829 | let label: String | |
| 830 | /// Nil shows the label as text. | |
| 831 | let symbol: String? | |
| 832 | let action: Action | |
| 833 | } | |
| 834 | ||
| 835 | /// Every button the bar can hold, by id. | |
| 836 | static let items: [String: Item] = [ | |
| 837 | "commands": Item(label: String(localized: "Commands"), symbol: "command", action: .palette), | |
| 838 | "fold": Item(label: String(localized: "Fold", comment: "Key bar button"), symbol: "arrow.right.to.line", action: .keys("TAB")), | |
| 839 | "overview": Item(label: String(localized: "Overview", comment: "Key bar button"), symbol: "arrow.left.to.line", action: .keys("S-TAB")), | |
| 840 | "promote": Item(label: String(localized: "Promote", comment: "Key bar button"), symbol: "decrease.indent", action: .keys("M-<left>")), | |
| 841 | "demote": Item(label: String(localized: "Demote", comment: "Key bar button"), symbol: "increase.indent", action: .keys("M-<right>")), | |
| 842 | "move-up": Item(label: String(localized: "Move Up", comment: "Key bar button"), symbol: "arrow.up.square", action: .keys("M-<up>")), | |
| 843 | "move-down": Item(label: String(localized: "Move Down", comment: "Key bar button"), symbol: "arrow.down.square", action: .keys("M-<down>")), | |
| 844 | "new-heading": Item(label: String(localized: "New Heading or Item", comment: "Key bar button"), symbol: "plus", action: .keys("M-RET")), | |
| 845 | "todo": Item(label: "TODO", symbol: nil, action: .keys("C-c C-t")), | |
| 846 | "act": Item(label: String(localized: "Act at Point", comment: "Key bar button"), symbol: "checkmark.square", action: .keys("C-c C-c")), | |
| 847 | "plan": Item(label: String(localized: "Plan", comment: "Key bar button: a menu of Schedule, Deadline and Tags"), symbol: "calendar.badge.clock", action: .plan), | |
| 848 | "schedule": Item(label: String(localized: "Schedule", comment: "Key bar button"), symbol: "calendar", action: .keys("C-c C-s")), | |
| 849 | "deadline": Item(label: String(localized: "Deadline", comment: "Key bar button"), symbol: "calendar.badge.exclamationmark", action: .keys("C-c C-d")), | |
| 850 | "tags": Item(label: String(localized: "Tags", comment: "Key bar button"), symbol: "tag", action: .keys("C-c C-q")), | |
| 851 | "open-link": Item(label: String(localized: "Open Link", comment: "Key bar button"), symbol: "link", action: .keys("C-c C-o")), | |
| 852 | "bold": Item(label: String(localized: "Bold", comment: "Key bar button"), symbol: "bold", action: .command("org.emphasize.bold")), | |
| 853 | "italic": Item(label: String(localized: "Italic", comment: "Key bar button"), symbol: "italic", action: .command("org.emphasize.italic")), | |
| 854 | "code": Item(label: String(localized: "Code", comment: "Key bar button"), symbol: "chevron.left.forwardslash.chevron.right", action: .command("org.emphasize.code")), | |
| 855 | "hide-keyboard": Item(label: String(localized: "Hide Keyboard"), symbol: "keyboard.chevron.compact.down", action: .hideKeyboard), | |
| 856 | ] | |
| 857 | ||
| 858 | /// The bar's buttons in order. On iPad, where it is wider, Plan's three are buttons. | |
| 859 | static func layout(regular: Bool) -> [String] { | |
| 860 | ["commands", "fold", "promote", "demote", "move-up", "move-down", "new-heading", "todo", "act"] | |
| 861 | + (regular ? ["schedule", "deadline", "tags"] : ["plan"]) + ["hide-keyboard"] | |
| 862 | } | |
| 863 | ||
| 864 | /// The bar's buttons are at least 44 points tall, scaled with the text size up to here. | |
| 865 | static let largestSize = DynamicTypeSize.accessibility2 | |
| 866 | static let target: CGFloat = 44 | |
| 867 | static let padding: CGFloat = 4 | |
| 868 | /// The widest a button gets where the bar has room. | |
| 869 | static let widest: CGFloat = 64 | |
| 870 | @ScaledMetric(relativeTo: .body) private var size = KeyBar.target | |
| 871 | ||
| 872 | var body: some View { | |
| 873 | HStack(spacing: 0) { | |
| 874 | ForEach(Self.layout(regular: sizeClass == .regular), id: \.self) { id in | |
| 875 | if let item = Self.items[id] { button(item) } | |
| 876 | } | |
| 877 | } | |
| 878 | .labelStyle(.iconOnly) | |
| 879 | .padding(.horizontal, 6) | |
| 880 | .padding(.vertical, Self.padding) | |
| 881 | .frame(maxWidth: .infinity) | |
| 882 | .background(.bar) | |
| 883 | } | |
| 884 | ||
| 885 | @ViewBuilder | |
| 886 | private func button(_ item: Item) -> some View { | |
| 887 | switch item.action { | |
| 888 | case .plan: | |
| 889 | Menu { | |
| 890 | ForEach(["schedule", "deadline", "tags"], id: \.self) { id in | |
| 891 | if let entry = Self.items[id], case .keys(let keys) = entry.action { | |
| 892 | Button(entry.label, systemImage: entry.symbol ?? "") { editor.run(keys: keys) } | |
| 893 | } | |
| 894 | } | |
| 895 | } label: { | |
| 896 | label(item).modifier(KeyShape(size: size)) | |
| 897 | } | |
| 898 | .accessibilityLabel(item.label) | |
| 899 | default: | |
| 900 | Button { | |
| 901 | switch item.action { | |
| 902 | case .keys(let keys): editor.run(keys: keys) | |
| 903 | case .command(let id): editor.run(id) | |
| 904 | case .palette: palette() | |
| 905 | case .hideKeyboard: editor.textView.resignFirstResponder() | |
| 906 | case .plan: break | |
| 907 | } | |
| 908 | } label: { | |
| 909 | label(item) | |
| 910 | } | |
| 911 | .buttonStyle(KeyStyle(size: size)) | |
| 912 | .accessibilityLabel(item.label) | |
| 913 | } | |
| 914 | } | |
| 915 | ||
| 916 | /// The buttons grow taller with the text size, but their symbols stop growing here, so | |
| 917 | /// that they fit the button's share of the width. | |
| 918 | static let largestSymbolSize = DynamicTypeSize.xxxLarge | |
| 919 | ||
| 920 | @ViewBuilder | |
| 921 | private func label(_ item: Item) -> some View { | |
| 922 | Group { | |
| 923 | if let symbol = item.symbol { | |
| 924 | Label(item.label, systemImage: symbol) | |
| 925 | } else { | |
| 926 | // A word is wider than a symbol, so it stays at the default size. | |
| 927 | Text(item.label).font(.callout.weight(.semibold)).lineLimit(1).minimumScaleFactor(0.5) | |
| 928 | .dynamicTypeSize(...DynamicTypeSize.large) | |
| 929 | } | |
| 930 | } | |
| 931 | .dynamicTypeSize(...Self.largestSymbolSize) | |
| 932 | } | |
| 933 | } | |
| 934 | ||
| 935 | /// A key bar button's look: a tinted label on a rounded tile, `size` tall, sharing the bar's | |
| 936 | /// width with the others. The whole share is the touch target. | |
| 937 | private struct KeyShape: ViewModifier { | |
| 938 | let size: CGFloat | |
| 939 | var pressed = false | |
| 940 | ||
| 941 | func body(content: Content) -> some View { | |
| 942 | content | |
| 943 | .foregroundStyle(.tint) | |
| 944 | .frame(maxWidth: KeyBar.widest, minHeight: size) | |
| 945 | .background(.fill.tertiary, in: .rect(cornerRadius: 10)) | |
| 946 | .opacity(pressed ? 0.5 : 1) | |
| 947 | .padding(.horizontal, 2) | |
| 948 | .frame(maxWidth: .infinity) | |
| 949 | .contentShape(.rect) | |
| 950 | } | |
| 951 | } | |
| 952 | ||
| 953 | private struct KeyStyle: ButtonStyle { | |
| 954 | let size: CGFloat | |
| 955 | ||
| 956 | func makeBody(configuration: Configuration) -> some View { | |
| 957 | configuration.label.modifier(KeyShape(size: size, pressed: configuration.isPressed)) | |
| 958 | } | |
| 959 | } | |
| 960 | ||
| 961 | 808 | /// A command's question: text with choices, a date, or fast selection by keys. |
| 962 | 809 | struct PromptSheet: View { |
| 963 | 810 | let prompt: Prompt |
| @@ -1232,16 +1079,20 @@ struct CommandPalette: View { | ||
| 1232 | 1079 | let context = editor.editContext() |
| 1233 | 1080 | let paneCommands: [(id: String, title: String)] = !panes ? [] : [("app.split-right", "Split Pane Right"), ("app.split-below", "Split Pane Below")] |
| 1234 | 1081 | + (split ? [("app.pane-next", "Next Pane"), ("app.pane-close", "Close Pane"), ("app.pane-only", "Close Other Panes")] : []) |
| 1235 | var seen = Set<String>() | |
| 1236 | let macros = editor.namedMacros.names.map { (id: NamedMacros.commandPrefix + $0, title: $0) } | |
| 1237 | return (paneCommands + Self.viewCommands + Commands.everything.map { ($0.id, $0.title) } + macros) | |
| 1238 | .filter { !AppStoreCommands.hidden.contains($0.id) && Self.offered($0.id) && seen.insert($0.id).inserted } | |
| 1082 | return Self.commands(macros: editor.namedMacros, panes: paneCommands) | |
| 1239 | 1083 | .map { command in |
| 1240 | 1084 | CommandRow(id: command.id, title: CommandTitle.localized(command.title), keys: editor.keymap.keyLabels(for: command.id).first, |
| 1241 | 1085 | reason: reason(command.id, context)) |
| 1242 | 1086 | } |
| 1243 | 1087 | } |
| 1244 | 1088 | |
| 1089 | /// The commands listed, with English titles: `panes`, the editor's, and the named macros. | |
| 1090 | static func commands(macros: NamedMacros, panes: [(id: String, title: String)] = []) -> [(id: String, title: String)] { | |
| 1091 | var seen = Set<String>() | |
| 1092 | return (panes + viewCommands + Commands.everything.map { ($0.id, $0.title) } + macros.names.map { (NamedMacros.commandPrefix + $0, $0) }) | |
| 1093 | .filter { !AppStoreCommands.hidden.contains($0.id) && offered($0.id) && seen.insert($0.id).inserted } | |
| 1094 | } | |
| 1095 | ||
| 1245 | 1096 | /// Commands for a camera or scanner this device lacks aren't listed. |
| 1246 | 1097 | private static func offered(_ id: String) -> Bool { |
| 1247 | 1098 | switch id { |
Sources/OrgstarMobile/KeyBar.swift added +271 · view
| @@ -0,0 +1,271 @@ | ||
| 1 | #if os(iOS) | |
| 2 | import OrgApp | |
| 3 | import OrgCore | |
| 4 | import SwiftUI | |
| 5 | ||
| 6 | /// Org's keys for a touch keyboard: each button does what its key does at the caret, as the | |
| 7 | /// Emacs keymap binds it (M-→ demotes a heading, indents an item, moves a table column), or | |
| 8 | /// runs a command. The buttons are `[key-bar]` in config.toml, or the default; they share the | |
| 9 | /// width without scrolling, and those that don't fit go under More. | |
| 10 | struct KeyBar: View { | |
| 11 | let editor: MobileEditor | |
| 12 | let palette: () -> Void | |
| 13 | @Environment(\.horizontalSizeClass) private var sizeClass | |
| 14 | @AppStorage(KeyBarLayout.Width.iphone.defaultsKey) private var iphone: String? | |
| 15 | @AppStorage(KeyBarLayout.Width.ipad.defaultsKey) private var ipad: String? | |
| 16 | @State private var width: CGFloat? | |
| 17 | ||
| 18 | /// A button the bar can hold. | |
| 19 | struct Item { | |
| 20 | enum Action { | |
| 21 | /// What the keys are bound to at the caret. | |
| 22 | case keys(String) | |
| 23 | case command(String) | |
| 24 | case palette | |
| 25 | /// Schedule, Deadline and Tags in a menu. | |
| 26 | case plan | |
| 27 | case hideKeyboard | |
| 28 | } | |
| 29 | ||
| 30 | let label: String | |
| 31 | /// Nil shows `face` as text. | |
| 32 | let symbol: String? | |
| 33 | let action: Action | |
| 34 | /// The text on the button without a symbol; the label when nil. | |
| 35 | var face: String? = nil | |
| 36 | ||
| 37 | var text: String { face ?? label } | |
| 38 | var slots: Int { KeyBarLayout.slots(symbol: symbol != nil, face: text) } | |
| 39 | } | |
| 40 | ||
| 41 | /// The bar's own buttons, by id. | |
| 42 | static let items: [String: Item] = [ | |
| 43 | "commands": Item(label: String(localized: "Commands"), symbol: "command", action: .palette), | |
| 44 | "fold": Item(label: String(localized: "Fold", comment: "Key bar button"), symbol: "arrow.right.to.line", action: .keys("TAB")), | |
| 45 | "overview": Item(label: String(localized: "Overview", comment: "Key bar button"), symbol: "arrow.left.to.line", action: .keys("S-TAB")), | |
| 46 | "promote": Item(label: String(localized: "Promote", comment: "Key bar button"), symbol: "decrease.indent", action: .keys("M-<left>")), | |
| 47 | "demote": Item(label: String(localized: "Demote", comment: "Key bar button"), symbol: "increase.indent", action: .keys("M-<right>")), | |
| 48 | "move-up": Item(label: String(localized: "Move Up", comment: "Key bar button"), symbol: "arrow.up.square", action: .keys("M-<up>")), | |
| 49 | "move-down": Item(label: String(localized: "Move Down", comment: "Key bar button"), symbol: "arrow.down.square", action: .keys("M-<down>")), | |
| 50 | "new-heading": Item(label: String(localized: "New Heading or Item", comment: "Key bar button"), symbol: "plus", action: .keys("M-RET")), | |
| 51 | "todo": Item(label: "TODO", symbol: nil, action: .keys("C-c C-t")), | |
| 52 | "act": Item(label: String(localized: "Act at Point", comment: "Key bar button"), symbol: "checkmark.square", action: .keys("C-c C-c")), | |
| 53 | "plan": Item(label: String(localized: "Plan", comment: "Key bar button: a menu of Schedule, Deadline and Tags"), symbol: "calendar.badge.clock", action: .plan), | |
| 54 | "schedule": Item(label: String(localized: "Schedule", comment: "Key bar button"), symbol: "calendar", action: .keys("C-c C-s")), | |
| 55 | "deadline": Item(label: String(localized: "Deadline", comment: "Key bar button"), symbol: "calendar.badge.exclamationmark", action: .keys("C-c C-d")), | |
| 56 | "tags": Item(label: String(localized: "Tags", comment: "Key bar button"), symbol: "tag", action: .keys("C-c C-q")), | |
| 57 | "open-link": Item(label: String(localized: "Open Link", comment: "Key bar button"), symbol: "link", action: .keys("C-c C-o")), | |
| 58 | "bold": Item(label: String(localized: "Bold", comment: "Key bar button"), symbol: "bold", action: .command("org.emphasize.bold")), | |
| 59 | "italic": Item(label: String(localized: "Italic", comment: "Key bar button"), symbol: "italic", action: .command("org.emphasize.italic")), | |
| 60 | "code": Item(label: String(localized: "Code", comment: "Key bar button"), symbol: "chevron.left.forwardslash.chevron.right", action: .command("org.emphasize.code")), | |
| 61 | "hide-keyboard": Item(label: String(localized: "Hide Keyboard"), symbol: "keyboard.chevron.compact.down", action: .hideKeyboard), | |
| 62 | ] | |
| 63 | ||
| 64 | /// Commands with a symbol of their own; others show their title. | |
| 65 | static let commandSymbols: [String: String] = [ | |
| 66 | KeyBarLayout.nextField: "forward.end", KeyBarLayout.previousField: "backward.end", | |
| 67 | "edit.undo": "arrow.uturn.backward", "edit.redo": "arrow.uturn.forward", "edit.isearch-forward": "magnifyingglass", | |
| 68 | "org.cycle": "arrow.right.to.line", "org.cycle-global": "arrow.left.to.line", | |
| 69 | "org.emphasize.bold": "bold", "org.emphasize.italic": "italic", "org.emphasize.underline": "underline", | |
| 70 | "org.emphasize.code": "chevron.left.forwardslash.chevron.right", "org.emphasize.strike-through": "strikethrough", | |
| 71 | "org.link.insert": "link.badge.plus", "org.link.open": "link", | |
| 72 | "app.clock.in": "clock", "app.clock.out": "clock.badge.checkmark", | |
| 73 | ] | |
| 74 | ||
| 75 | /// The editor's commands by id, with English titles. | |
| 76 | private static let commandTitles = Dictionary(CommandPalette.viewCommands + Commands.everything.map { ($0.id, $0.title) }) { first, _ in first } | |
| 77 | ||
| 78 | /// The button for an id: one of the bar's own, a command, a named macro (its name) or a | |
| 79 | /// snippet (its trigger); nil for an id that is none of these here. | |
| 80 | static func item(_ id: String) -> Item? { | |
| 81 | if let item = items[id] { return item } | |
| 82 | if let trigger = Snippets.trigger(ofCommand: id) { | |
| 83 | guard let snippet = SnippetLibrary.shared.snippets.first(where: { $0.trigger == trigger }) else { return nil } | |
| 84 | return Item(label: Snippets.label(snippet), symbol: nil, action: .command(id), face: trigger) | |
| 85 | } | |
| 86 | if id.hasPrefix(NamedMacros.commandPrefix) { | |
| 87 | let name = String(id.dropFirst(NamedMacros.commandPrefix.count)) | |
| 88 | return NamedMacros.shared.names.contains(name) ? Item(label: name, symbol: nil, action: .command(id)) : nil | |
| 89 | } | |
| 90 | guard !AppStoreCommands.hidden.contains(id), let title = commandTitles[id].map(CommandTitle.localized) else { return nil } | |
| 91 | return Item(label: title, symbol: commandSymbols[id], action: .command(id), face: KeyBarLayout.face(title: title)) | |
| 92 | } | |
| 93 | ||
| 94 | /// Ids in `[key-bar]` that are no button here. | |
| 95 | static func problems() -> [String] { | |
| 96 | KeyBarLayout.Width.allCases.flatMap { width in | |
| 97 | KeyBarLayout.problems(KeyBarLayout.stored(width, in: .standard) ?? [], width) { item($0) != nil } | |
| 98 | } | |
| 99 | } | |
| 100 | ||
| 101 | /// The bar's buttons are at least 44 points tall, scaled with the text size up to here. | |
| 102 | static let largestSize = DynamicTypeSize.accessibility2 | |
| 103 | static let target: CGFloat = 44 | |
| 104 | static let padding: CGFloat = 4 | |
| 105 | /// The widest a one-slot button gets where the bar has room, and the narrowest. | |
| 106 | nonisolated static let widest: CGFloat = 64 | |
| 107 | static let slot: CGFloat = 32 | |
| 108 | @ScaledMetric(relativeTo: .body) private var size = KeyBar.target | |
| 109 | ||
| 110 | var body: some View { | |
| 111 | let layout = sizeClass == .regular ? KeyBarLayout.Width.ipad : .iphone | |
| 112 | var ids = ((layout == .ipad ? ipad : iphone).map(KeyBarLayout.ids) ?? layout.defaultIDs).filter { Self.item($0) != nil } | |
| 113 | if editor.fields.active { ids = KeyBarLayout.withSnippetFields(ids) } | |
| 114 | let available = width.map { Int(($0 - 12) / Self.slot) } ?? .max | |
| 115 | let (shown, more) = KeyBarLayout.fit(ids, available: available) { Self.item($0)?.slots ?? 1 } | |
| 116 | return SlotRow { | |
| 117 | ForEach(shown, id: \.self) { id in | |
| 118 | if let item = Self.item(id) { button(item).layoutValue(key: Slots.self, value: item.slots) } | |
| 119 | } | |
| 120 | if !more.isEmpty { moreButton(more) } | |
| 121 | } | |
| 122 | .labelStyle(.iconOnly) | |
| 123 | .padding(.horizontal, 6) | |
| 124 | .padding(.vertical, Self.padding) | |
| 125 | .frame(maxWidth: .infinity) | |
| 126 | .onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width = $0 } | |
| 127 | .background(.bar) | |
| 128 | } | |
| 129 | ||
| 130 | @ViewBuilder | |
| 131 | private func button(_ item: Item) -> some View { | |
| 132 | switch item.action { | |
| 133 | case .plan: | |
| 134 | Menu { | |
| 135 | planEntries() | |
| 136 | } label: { | |
| 137 | label(item).modifier(KeyShape(size: size)) | |
| 138 | } | |
| 139 | .accessibilityLabel(item.label) | |
| 140 | default: | |
| 141 | Button { | |
| 142 | run(item) | |
| 143 | } label: { | |
| 144 | label(item) | |
| 145 | } | |
| 146 | .buttonStyle(KeyStyle(size: size, slots: item.slots)) | |
| 147 | .accessibilityLabel(item.label) | |
| 148 | } | |
| 149 | } | |
| 150 | ||
| 151 | private func planEntries() -> some View { | |
| 152 | ForEach(["schedule", "deadline", "tags"], id: \.self) { id in | |
| 153 | if let entry = Self.items[id], case .keys(let keys) = entry.action { | |
| 154 | Button(entry.label, systemImage: entry.symbol ?? "") { editor.run(keys: keys) } | |
| 155 | } | |
| 156 | } | |
| 157 | } | |
| 158 | ||
| 159 | /// The buttons that don't fit, in a menu in their order. | |
| 160 | private func moreButton(_ ids: [String]) -> some View { | |
| 161 | Menu { | |
| 162 | ForEach(ids, id: \.self) { id in | |
| 163 | if let item = Self.item(id) { | |
| 164 | switch item.action { | |
| 165 | case .plan: | |
| 166 | Menu(item.label, systemImage: item.symbol ?? "") { planEntries() } | |
| 167 | default: | |
| 168 | if let symbol = item.symbol { | |
| 169 | Button(item.label, systemImage: symbol) { run(item) } | |
| 170 | } else { | |
| 171 | Button(item.label) { run(item) } | |
| 172 | } | |
| 173 | } | |
| 174 | } | |
| 175 | } | |
| 176 | } label: { | |
| 177 | Label(String(localized: "More"), systemImage: "ellipsis") | |
| 178 | .dynamicTypeSize(...Self.largestSymbolSize) | |
| 179 | .modifier(KeyShape(size: size)) | |
| 180 | } | |
| 181 | .menuOrder(.fixed) | |
| 182 | .accessibilityLabel(String(localized: "More")) | |
| 183 | } | |
| 184 | ||
| 185 | private func run(_ item: Item) { | |
| 186 | switch item.action { | |
| 187 | case .keys(let keys): editor.run(keys: keys) | |
| 188 | case .command(let id): editor.run(id) | |
| 189 | case .palette: palette() | |
| 190 | case .hideKeyboard: editor.textView.resignFirstResponder() | |
| 191 | case .plan: break | |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | /// The buttons grow taller with the text size, but their symbols stop growing here, so | |
| 196 | /// that they fit the button's share of the width. | |
| 197 | static let largestSymbolSize = DynamicTypeSize.xxxLarge | |
| 198 | ||
| 199 | @ViewBuilder | |
| 200 | private func label(_ item: Item) -> some View { | |
| 201 | Group { | |
| 202 | if let symbol = item.symbol { | |
| 203 | Label(item.label, systemImage: symbol) | |
| 204 | } else if item.slots == 1 { | |
| 205 | // A word is wider than a symbol, so it stays at the default size. | |
| 206 | Text(item.text).font(.callout.weight(.semibold)).lineLimit(1).minimumScaleFactor(0.5) | |
| 207 | .dynamicTypeSize(...DynamicTypeSize.large) | |
| 208 | } else { | |
| 209 | Text(item.text).font(.caption.weight(.semibold)).lineLimit(2).minimumScaleFactor(0.6) | |
| 210 | .multilineTextAlignment(.center).padding(.horizontal, 2) | |
| 211 | .dynamicTypeSize(...DynamicTypeSize.large) | |
| 212 | } | |
| 213 | } | |
| 214 | .dynamicTypeSize(...Self.largestSymbolSize) | |
| 215 | } | |
| 216 | } | |
| 217 | ||
| 218 | /// A button's width in slots. | |
| 219 | private struct Slots: LayoutValueKey { | |
| 220 | static let defaultValue = 1 | |
| 221 | } | |
| 222 | ||
| 223 | /// The bar's buttons in a row, each as wide as its share of the slots. | |
| 224 | private struct SlotRow: Layout { | |
| 225 | func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { | |
| 226 | let slots = subviews.reduce(0) { $0 + $1[Slots.self] } | |
| 227 | let width = proposal.width ?? CGFloat(slots) * KeyBar.widest | |
| 228 | let unit = width / CGFloat(max(slots, 1)) | |
| 229 | let height = subviews.map { $0.sizeThatFits(ProposedViewSize(width: unit * CGFloat($0[Slots.self]), height: proposal.height)).height }.max() ?? 0 | |
| 230 | return CGSize(width: width, height: height) | |
| 231 | } | |
| 232 | ||
| 233 | func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { | |
| 234 | let unit = bounds.width / CGFloat(max(subviews.reduce(0) { $0 + $1[Slots.self] }, 1)) | |
| 235 | var x = bounds.minX | |
| 236 | for view in subviews { | |
| 237 | let width = unit * CGFloat(view[Slots.self]) | |
| 238 | view.place(at: CGPoint(x: x, y: bounds.minY), proposal: ProposedViewSize(width: width, height: bounds.height)) | |
| 239 | x += width | |
| 240 | } | |
| 241 | } | |
| 242 | } | |
| 243 | ||
| 244 | /// A key bar button's look: a tinted label on a rounded tile, `size` tall, sharing the bar's | |
| 245 | /// width with the others. The whole share is the touch target. | |
| 246 | private struct KeyShape: ViewModifier { | |
| 247 | let size: CGFloat | |
| 248 | var slots = 1 | |
| 249 | var pressed = false | |
| 250 | ||
| 251 | func body(content: Content) -> some View { | |
| 252 | content | |
| 253 | .foregroundStyle(.tint) | |
| 254 | .frame(maxWidth: KeyBar.widest * CGFloat(slots), minHeight: size) | |
| 255 | .background(.fill.tertiary, in: .rect(cornerRadius: 10)) | |
| 256 | .opacity(pressed ? 0.5 : 1) | |
| 257 | .padding(.horizontal, 2) | |
| 258 | .frame(maxWidth: .infinity) | |
| 259 | .contentShape(.rect) | |
| 260 | } | |
| 261 | } | |
| 262 | ||
| 263 | private struct KeyStyle: ButtonStyle { | |
| 264 | let size: CGFloat | |
| 265 | let slots: Int | |
| 266 | ||
| 267 | func makeBody(configuration: Configuration) -> some View { | |
| 268 | configuration.label.modifier(KeyShape(size: size, slots: slots, pressed: configuration.isPressed)) | |
| 269 | } | |
| 270 | } | |
| 271 | #endif | |
Sources/OrgstarMobile/KeyBarSettings.swift added +102 · view
| @@ -0,0 +1,102 @@ | ||
| 1 | #if os(iOS) | |
| 2 | import OrgApp | |
| 3 | import OrgCore | |
| 4 | import SwiftUI | |
| 5 | ||
| 6 | /// Settings ▸ Key Bar: the key bar's buttons, added from the Commands list, removed and | |
| 7 | /// reordered, for narrow and wide editors. Changes are written to `[key-bar]` in config.toml. | |
| 8 | struct KeyBarSettings: View { | |
| 9 | let model: MobileModel | |
| 10 | @State private var width: KeyBarLayout.Width = UIDevice.current.userInterfaceIdiom == .pad ? .ipad : .iphone | |
| 11 | @State private var adding = false | |
| 12 | ||
| 13 | private var stored: [String]? { | |
| 14 | let _ = model.settingsVersion | |
| 15 | return KeyBarLayout.stored(width, in: .standard) | |
| 16 | } | |
| 17 | ||
| 18 | var body: some View { | |
| 19 | let ids = stored ?? width.defaultIDs | |
| 20 | List { | |
| 21 | Section { | |
| 22 | Picker("Layout", selection: $width) { | |
| 23 | Text(verbatim: "iPhone").tag(KeyBarLayout.Width.iphone) | |
| 24 | Text(verbatim: "iPad").tag(KeyBarLayout.Width.ipad) | |
| 25 | } | |
| 26 | .pickerStyle(.segmented) | |
| 27 | } footer: { | |
| 28 | Text("The iPhone buttons show where the editor is narrow, the iPad buttons where it is wide.") | |
| 29 | } | |
| 30 | Section { | |
| 31 | ForEach(ids, id: \.self) { row($0) } | |
| 32 | .onMove { from, to in | |
| 33 | var list = ids | |
| 34 | list.move(fromOffsets: from, toOffset: to) | |
| 35 | model.setKeyBar(list, width) | |
| 36 | } | |
| 37 | .onDelete { offsets in | |
| 38 | var list = ids | |
| 39 | list.remove(atOffsets: offsets) | |
| 40 | model.setKeyBar(list, width) | |
| 41 | } | |
| 42 | } header: { | |
| 43 | Text("Buttons") | |
| 44 | } footer: { | |
| 45 | Text("Buttons that don't fit go under More. While a snippet's fields are filled in, Previous Snippet Field and Next Snippet Field take the places of Promote and Demote.") | |
| 46 | } | |
| 47 | Section { | |
| 48 | Button("Add Button…") { adding = true } | |
| 49 | Button("Reset to Default") { model.setKeyBar(nil, width) } | |
| 50 | .disabled(stored == nil) | |
| 51 | } | |
| 52 | } | |
| 53 | .environment(\.editMode, .constant(.active)) | |
| 54 | .navigationTitle("Key Bar") | |
| 55 | .sheet(isPresented: $adding) { | |
| 56 | CommandList(rows: candidates(besides: ids), title: String(localized: "Add Button"), recordsUse: false) { id in | |
| 57 | model.setKeyBar(ids + [id], width) | |
| 58 | } | |
| 59 | } | |
| 60 | } | |
| 61 | ||
| 62 | private func row(_ id: String) -> some View { | |
| 63 | let item = KeyBar.item(id) | |
| 64 | return HStack(spacing: 12) { | |
| 65 | Group { | |
| 66 | if let symbol = item?.symbol { | |
| 67 | Image(systemName: symbol).font(.body) | |
| 68 | } else { | |
| 69 | Text(item?.text ?? "?").font(.caption2.weight(.semibold)).lineLimit(2).minimumScaleFactor(0.5) | |
| 70 | .multilineTextAlignment(.center) | |
| 71 | } | |
| 72 | } | |
| 73 | .foregroundStyle(.tint) | |
| 74 | // As on the bar, the tile stops growing where its symbols do. | |
| 75 | .dynamicTypeSize(...KeyBar.largestSymbolSize) | |
| 76 | .frame(width: 56, height: 40) | |
| 77 | .background(.fill.tertiary, in: .rect(cornerRadius: 8)) | |
| 78 | .accessibilityHidden(true) | |
| 79 | VStack(alignment: .leading, spacing: 2) { | |
| 80 | Text(item?.label ?? id) | |
| 81 | if item == nil { | |
| 82 | Text("Not a command here; the key bar skips it.").font(.caption).foregroundStyle(.red) | |
| 83 | } | |
| 84 | } | |
| 85 | } | |
| 86 | } | |
| 87 | ||
| 88 | /// The bar's own buttons, then the editor's commands, named macros and snippets, without | |
| 89 | /// those already on the bar or a command one of the bar's own buttons runs. | |
| 90 | private func candidates(besides ids: [String]) -> [CommandRow] { | |
| 91 | let own = KeyBar.items.values.compactMap { item -> String? in | |
| 92 | if case .command(let id) = item.action { return id } | |
| 93 | return nil | |
| 94 | } | |
| 95 | let commands = KeyBar.items.keys.map { $0 } + CommandPalette.commands(macros: NamedMacros.shared).map(\.id) | |
| 96 | + SnippetLibrary.shared.snippets.filter { !$0.file }.map(\.commandID) | |
| 97 | return commands.filter { !ids.contains($0) && !own.contains($0) }.compactMap { id in | |
| 98 | KeyBar.item(id).map { CommandRow(id: id, title: $0.label) } | |
| 99 | } | |
| 100 | } | |
| 101 | } | |
| 102 | #endif | |
Sources/OrgstarMobile/MobileEditor.swift +12 −1 · view
| @@ -3,6 +3,7 @@ import OrgApp | ||
| 3 | 3 | import OrgCore |
| 4 | 4 | import OrgDocument |
| 5 | 5 | import OrgHighlight |
| 6 | import Observation | |
| 6 | 7 | import OrgPresentation |
| 7 | 8 | import UIKit |
| 8 | 9 | |
| @@ -167,7 +168,11 @@ final class MobileEditor: NSObject, DocumentBuffer { | ||
| 167 | 168 | /// A command's edits being applied, which keep shrunk columns narrow. |
| 168 | 169 | private var commandEditing = false |
| 169 | 170 | /// The snippet whose fields are being filled in, and the range drawn for it last. |
| 170 | var snippetSession: SnippetSession? | |
| 171 | var snippetSession: SnippetSession? { | |
| 172 | didSet { if fields.active != (snippetSession != nil) { fields.active = snippetSession != nil } } | |
| 173 | } | |
| 174 | /// Whether a snippet's fields are being filled in, for the key bar to watch. | |
| 175 | let fields = SnippetFields() | |
| 171 | 176 | var snippetHighlight: Range<Int>? |
| 172 | 177 | var updatingMirrors = false |
| 173 | 178 | |
| @@ -821,4 +826,10 @@ extension MobileEditor: NSTextLayoutManagerDelegate { | ||
| 821 | 826 | return fragment |
| 822 | 827 | } |
| 823 | 828 | } |
| 829 | ||
| 830 | /// Whether a snippet's fields are being filled in. | |
| 831 | @Observable | |
| 832 | final class SnippetFields { | |
| 833 | var active = false | |
| 834 | } | |
| 824 | 835 | #endif |
Sources/OrgstarMobile/MobileModel.swift +17 · view
| @@ -119,6 +119,7 @@ final class MobileModel { | ||
| 119 | 119 | ConfigFolder.clear() |
| 120 | 120 | // What the folder set no longer applies. |
| 121 | 121 | for setting in UserConfig.settings { UserDefaults.standard.removeObject(forKey: setting.defaultsKey) } |
| 122 | for width in KeyBarLayout.Width.allCases { KeyBarLayout.store(nil, width, in: .standard) } | |
| 122 | 123 | } |
| 123 | 124 | configFolder = url |
| 124 | 125 | _ = reloadConfig(after: problem) |
| @@ -150,6 +151,7 @@ final class MobileModel { | ||
| 150 | 151 | configProblems += MacroFile.load().map { "\(NamedMacros.fileName): " + $0 } |
| 151 | 152 | SnippetLibrary.shared.reload(from: UserConfig.file(Snippets.fileName), read: configFolder == nil ? { try? String(contentsOf: $0, encoding: .utf8) } : Self.read) |
| 152 | 153 | configProblems += SnippetLibrary.shared.problems |
| 154 | configProblems += KeyBar.problems() | |
| 153 | 155 | let settings = OrgPreferences.orgSettings() |
| 154 | 156 | session.defaults = settings |
| 155 | 157 | session.options = OrgPreferences.options() |
| @@ -213,11 +215,26 @@ final class MobileModel { | ||
| 213 | 215 | case .bool(let b): UserDefaults.standard.set(b, forKey: defaultsKey) |
| 214 | 216 | case .string(let s): UserDefaults.standard.set(s, forKey: defaultsKey) |
| 215 | 217 | case .integer(let i): UserDefaults.standard.set(i, forKey: defaultsKey) |
| 218 | case .array: break | |
| 216 | 219 | } |
| 217 | 220 | } |
| 218 | 221 | _ = reloadConfig(after: problem) |
| 219 | 222 | } |
| 220 | 223 | |
| 224 | /// Sets the key bar's buttons for `width`, or with nil its default, as `set` does. | |
| 225 | func setKeyBar(_ ids: [String]?, _ width: KeyBarLayout.Width) { | |
| 226 | var problem: String? | |
| 227 | if let configFolder { | |
| 228 | problem = Self.updateConfig(in: configFolder) { text in | |
| 229 | guard let ids else { return UserConfig.removingSetting(text, section: KeyBarLayout.table, key: width.rawValue) } | |
| 230 | return UserConfig.setting(text, section: KeyBarLayout.table, key: width.rawValue, to: .array(ids.map(TOML.Value.string))) | |
| 231 | } | |
| 232 | } else { | |
| 233 | KeyBarLayout.store(ids, width, in: .standard) | |
| 234 | } | |
| 235 | _ = reloadConfig(after: problem) | |
| 236 | } | |
| 237 | ||
| 221 | 238 | /// The capture templates, for the share extension to offer. |
| 222 | 239 | private func shareTemplates() { |
| 223 | 240 | try? inbox?.setTemplates(CaptureTemplates.load().templates.map { CaptureInbox.Template(key: $0.key, name: $0.name) }) |
Sources/OrgstarMobile/SettingsScreen.swift +5 · view
| @@ -73,6 +73,11 @@ struct SettingsScreen: View { | ||
| 73 | 73 | } footer: { |
| 74 | 74 | Text("With a body font, prose uses it while tables, code, dates, tags and drawers keep the monospaced font. Text width keeps lines to that many columns, centred, on a screen wider than that.") |
| 75 | 75 | } |
| 76 | Section { | |
| 77 | NavigationLink("Key Bar") { KeyBarSettings(model: model) } | |
| 78 | } footer: { | |
| 79 | Text("The buttons above the on-screen keyboard.") | |
| 80 | } | |
| 76 | 81 | Section { |
| 77 | 82 | let _ = model.settingsVersion |
| 78 | 83 | Toggle("Show days without entries", isOn: Binding { |
Tests/OrgAppTests/KeyBarLayoutTests.swift added +108 · view
| @@ -0,0 +1,108 @@ | ||
| 1 | import Foundation | |
| 2 | import Testing | |
| 3 | @testable import OrgApp | |
| 4 | ||
| 5 | @MainActor | |
| 6 | struct KeyBarLayoutTests { | |
| 7 | func defaults() -> UserDefaults { TestDefaults("orgstar-keybar") } | |
| 8 | ||
| 9 | @Test func defaultsWithoutTheTable() { | |
| 10 | let d = defaults() | |
| 11 | #expect(UserConfig.apply("fill-column = 70\n", to: d).isEmpty) | |
| 12 | #expect(KeyBarLayout.stored(.iphone, in: d) == nil) | |
| 13 | #expect(KeyBarLayout.stored(.ipad, in: d) == nil) | |
| 14 | #expect(KeyBarLayout.Width.iphone.defaultIDs.contains("plan")) | |
| 15 | #expect(!KeyBarLayout.Width.ipad.defaultIDs.contains("plan")) | |
| 16 | #expect(KeyBarLayout.Width.ipad.defaultIDs.suffix(4) == ["schedule", "deadline", "tags", "hide-keyboard"]) | |
| 17 | } | |
| 18 | ||
| 19 | @Test func readsIPhoneAndIPadLists() { | |
| 20 | let d = defaults() | |
| 21 | let problems = UserConfig.apply(""" | |
| 22 | [key-bar] | |
| 23 | iphone = ["commands", "org.snippet:td", "macro.named.tidy", "commands"] | |
| 24 | ipad = [ | |
| 25 | "fold", # TAB | |
| 26 | "hide-keyboard", | |
| 27 | ] | |
| 28 | """, to: d) | |
| 29 | #expect(problems.isEmpty) | |
| 30 | #expect(KeyBarLayout.stored(.iphone, in: d) == ["commands", "org.snippet:td", "macro.named.tidy"]) | |
| 31 | #expect(KeyBarLayout.stored(.ipad, in: d) == ["fold", "hide-keyboard"]) | |
| 32 | // A list taken out of the file goes back to the default. | |
| 33 | UserConfig.apply("[key-bar]\nipad = []\n", to: d) | |
| 34 | #expect(KeyBarLayout.stored(.iphone, in: d) == nil) | |
| 35 | #expect(KeyBarLayout.stored(.ipad, in: d) == []) | |
| 36 | } | |
| 37 | ||
| 38 | @Test func reportsBadValuesAndUnknownIDs() { | |
| 39 | let d = defaults() | |
| 40 | let problems = UserConfig.apply(""" | |
| 41 | [key-bar] | |
| 42 | iphone = "fold" | |
| 43 | ipad = ["fold", 3] | |
| 44 | watch = [] | |
| 45 | """, to: d) | |
| 46 | #expect(problems.count == 3) | |
| 47 | #expect(problems.contains { $0.contains("key-bar.iphone must be a list") }) | |
| 48 | #expect(problems.contains { $0.contains("unknown setting key-bar.watch") }) | |
| 49 | #expect(KeyBarLayout.stored(.iphone, in: d) == nil) | |
| 50 | let known: Set = ["fold", "commands"] | |
| 51 | #expect(KeyBarLayout.problems(["fold", "nonsense", "commands"], .ipad, known: known.contains) | |
| 52 | == ["config.toml: key-bar.ipad has no command nonsense"]) | |
| 53 | } | |
| 54 | ||
| 55 | @Test func writesAndRemovesLists() throws { | |
| 56 | let start = """ | |
| 57 | fill-column = 80 | |
| 58 | ||
| 59 | [key-bar] | |
| 60 | iphone = [ | |
| 61 | "fold", | |
| 62 | "todo", | |
| 63 | ] # mine | |
| 64 | ipad = ["fold"] | |
| 65 | """ | |
| 66 | let written = UserConfig.setting(start, section: KeyBarLayout.table, key: "iphone", to: .array([.string("act"), .string("org.snippet:td")])) | |
| 67 | #expect(written.contains("iphone = [\"act\", \"org.snippet:td\"]\nipad = [\"fold\"]")) | |
| 68 | let d = defaults() | |
| 69 | #expect(UserConfig.apply(written, to: d).isEmpty) | |
| 70 | #expect(KeyBarLayout.stored(.iphone, in: d) == ["act", "org.snippet:td"]) | |
| 71 | let removed = UserConfig.removingSetting(start, section: KeyBarLayout.table, key: "iphone") | |
| 72 | #expect(removed == "fill-column = 80\n\n[key-bar]\nipad = [\"fold\"]") | |
| 73 | let added = UserConfig.setting("fill-column = 80\n", section: KeyBarLayout.table, key: "ipad", to: .array([.string("fold")])) | |
| 74 | #expect(added.hasSuffix("[key-bar]\nipad = [\"fold\"]\n")) | |
| 75 | } | |
| 76 | ||
| 77 | @Test func fitsOrOverflows() { | |
| 78 | let ids = ["a", "b", "wide", "c", "d"] | |
| 79 | let slots: (String) -> Int = { $0 == "wide" ? 2 : 1 } | |
| 80 | #expect(KeyBarLayout.fit(ids, available: 6, slots: slots) == (ids, [])) | |
| 81 | #expect(KeyBarLayout.fit(ids, available: 20, slots: slots) == (ids, [])) | |
| 82 | // One slot goes to More. | |
| 83 | #expect(KeyBarLayout.fit(ids, available: 5, slots: slots) == (["a", "b", "wide"], ["c", "d"])) | |
| 84 | // A wide button that doesn't fit ends the row, though a narrow one after it would fit. | |
| 85 | #expect(KeyBarLayout.fit(ids, available: 4, slots: slots) == (["a", "b"], ["wide", "c", "d"])) | |
| 86 | #expect(KeyBarLayout.fit(ids, available: 2, slots: slots) == (["a"], ["b", "wide", "c", "d"])) | |
| 87 | #expect(KeyBarLayout.fit(ids, available: 0, slots: slots) == ([], ids)) | |
| 88 | #expect(KeyBarLayout.fit([], available: 0, slots: slots) == ([], [])) | |
| 89 | } | |
| 90 | ||
| 91 | @Test func snippetFieldsTakePromoteAndDemote() { | |
| 92 | let next = KeyBarLayout.nextField, previous = KeyBarLayout.previousField | |
| 93 | #expect(KeyBarLayout.withSnippetFields(KeyBarLayout.Width.iphone.defaultIDs).prefix(4) | |
| 94 | == ["commands", "fold", previous, next]) | |
| 95 | #expect(KeyBarLayout.withSnippetFields(KeyBarLayout.Width.iphone.defaultIDs).count == KeyBarLayout.Width.iphone.defaultIDs.count) | |
| 96 | #expect(KeyBarLayout.withSnippetFields(["fold", "todo"]) == [previous, next, "fold", "todo"]) | |
| 97 | #expect(KeyBarLayout.withSnippetFields(["demote", "fold"]) == [previous, next, "fold"]) | |
| 98 | #expect(KeyBarLayout.withSnippetFields([next, "promote", "demote"]) == [next, previous, "demote"]) | |
| 99 | #expect(KeyBarLayout.withSnippetFields([previous, next]) == [previous, next]) | |
| 100 | } | |
| 101 | ||
| 102 | @Test func faces() { | |
| 103 | #expect(KeyBarLayout.face(title: "Insert Link…") == "Insert Link") | |
| 104 | #expect(KeyBarLayout.slots(symbol: true, face: "Insert Link") == 1) | |
| 105 | #expect(KeyBarLayout.slots(symbol: false, face: "TODO") == 1) | |
| 106 | #expect(KeyBarLayout.slots(symbol: false, face: "Insert Link") == 2) | |
| 107 | } | |
| 108 | } | |
Tests/OrgCoreTests/KeymapTests.swift +18 · view
| @@ -39,6 +39,24 @@ struct TOMLTests { | ||
| 39 | 39 | #expect(tables[2].values["name"] == .string("aé")) |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | @Test func parsesArrays() throws { | |
| 43 | let tables = try TOML.parse(""" | |
| 44 | one = ["a", 'b', 3, true, ["c"]] # comment | |
| 45 | empty = [] | |
| 46 | many = [ | |
| 47 | "x", # first | |
| 48 | "y]", | |
| 49 | ] | |
| 50 | after = 1 | |
| 51 | """) | |
| 52 | #expect(tables[0].values["one"] == .array([.string("a"), .string("b"), .integer(3), .bool(true), .array([.string("c")])])) | |
| 53 | #expect(tables[0].values["empty"] == .array([])) | |
| 54 | #expect(tables[0].values["many"] == .array([.string("x"), .string("y]")])) | |
| 55 | #expect(tables[0].values["after"] == .integer(1)) | |
| 56 | #expect(throws: TOML.ParseError(line: 1, message: "unclosed array")) { try TOML.parse("a = [\"x\",\nb = 1") } | |
| 57 | #expect(throws: TOML.ParseError(line: 1, message: "expected , or ] in array")) { try TOML.parse("a = [\"x\" \"y\"]") } | |
| 58 | } | |
| 59 | ||
| 42 | 60 | @Test func reportsErrorsWithLines() { |
| 43 | 61 | #expect(throws: TOML.ParseError(line: 2, message: "unclosed string")) { try TOML.parse("[[bind]]\nkeys = \"C-c") } |
| 44 | 62 | #expect(throws: TOML.ParseError(line: 1, message: "expected key = value")) { try TOML.parse("keys") } |
docs/manual/guide/13-configuration.org +34 · view
| @@ -387,6 +387,40 @@ memo = "* To\n\n* From\n" | ||
| 387 | 387 | |
| 388 | 388 | Keys are letters, digits, =_= and =-=. Emacs import adds entries here; remove one by deleting its line. |
| 389 | 389 | |
| 390 | ** [key-bar] | |
| 391 | ||
| 392 | The buttons of the key bar above the on-screen keyboard on iPhone and iPad, in order: =iphone= where the editor is narrow (iPhone, and iPad in Slide Over or a narrow split), =ipad= where it is wide. Each is a list of ids: the key bar's own buttons, or any command id from the Commands list, =org.snippet:<trigger>= for a snippet and =macro.named.<name>= for a named keyboard macro. A list may run over several lines. | |
| 393 | ||
| 394 | #+BEGIN_SRC toml | |
| 395 | [key-bar] | |
| 396 | iphone = ["commands", "fold", "promote", "demote", "new-heading", "todo", | |
| 397 | "org.snippet:td", "macro.named.tidy", "edit.undo", "plan", "hide-keyboard"] | |
| 398 | ipad = ["commands", "fold", "overview", "promote", "demote", "move-up", "move-down", | |
| 399 | "new-heading", "todo", "act", "schedule", "deadline", "tags", "open-link", "hide-keyboard"] | |
| 400 | #+END_SRC | |
| 401 | ||
| 402 | | Id | Button | | |
| 403 | |-----------------+----------------------------------------------------------------| | |
| 404 | | =commands= | the Commands list | | |
| 405 | | =fold= | =TAB= | | |
| 406 | | =overview= | =S-TAB= | | |
| 407 | | =promote= | =M-<left>= | | |
| 408 | | =demote= | =M-<right>= | | |
| 409 | | =move-up= | =M-<up>= | | |
| 410 | | =move-down= | =M-<down>= | | |
| 411 | | =new-heading= | =M-RET= | | |
| 412 | | =todo= | =C-c C-t= | | |
| 413 | | =act= | =C-c C-c= | | |
| 414 | | =plan= | a menu of Schedule, Deadline and Tags | | |
| 415 | | =schedule= | =C-c C-s= | | |
| 416 | | =deadline= | =C-c C-d= | | |
| 417 | | =tags= | =C-c C-q= | | |
| 418 | | =open-link= | =C-c C-o= | | |
| 419 | | =bold=, =italic=, =code= | Bold, Italic and Code | | |
| 420 | | =hide-keyboard= | hides the keyboard | | |
| 421 | ||
| 422 | Without a list, its default applies: =commands=, =fold=, =promote=, =demote=, =move-up=, =move-down=, =new-heading=, =todo= and =act=, then =plan= on iPhone or =schedule=, =deadline= and =tags= on iPad, then =hide-keyboard=. An empty list, =[]=, leaves the bar empty. An id that is no command on iPhone and iPad, such as a Mac-only command or a snippet that =snippets.toml= no longer has, is reported under the folder in Settings and skipped. Settings ▸ Key Bar on iOS writes this table, each list on one line, and Reset to Default removes the list; the Mac reads the table and has no key bar. | |
| 423 | ||
| 390 | 424 | ** [[publish]] |
| 391 | 425 | |
| 392 | 426 | Publishing projects, one table each, as =org-publish-project-alist= has them. They're read when you publish; see [[file:12-export.org::*Publishing][Publishing]] for the keys. The Settings window leaves them as they are. |
docs/manual/guide/14-ios.org +14 −2 · view
| @@ -128,7 +128,7 @@ Table columns with width cookies narrow as on the Mac: =#+STARTUP: shrink= narro | ||
| 128 | 128 | |
| 129 | 129 | ** The key bar |
| 130 | 130 | |
| 131 | A bar above the on-screen keyboard has buttons for Org's keys. Each does what its Emacs key does at the caret, so the arrows promote and demote headings, indent list items, or move table columns, depending on where the caret is. The buttons share the bar's width, so all of them show without scrolling. They are at least 44 points high and grow with the text size up to the second accessibility size. | |
| 131 | A bar above the on-screen keyboard has buttons for Org's keys. Each does what its Emacs key does at the caret, so the arrows promote and demote headings, indent list items, or move table columns, depending on where the caret is. The buttons share the bar's width, without scrolling. They are at least 44 points high and grow with the text size up to the second accessibility size. | |
| 132 | 132 | |
| 133 | 133 | #+CAPTION: The iPhone editor with the key bar above the keyboard. |
| 134 | 134 | #+ATTR_HTML: :width 368 |
| @@ -152,6 +152,18 @@ On iPad, where the bar is wider, Schedule, Deadline and Tags are buttons of thei | ||
| 152 | 152 | |
| 153 | 153 | Bold, Italic and Code are in the edit menu of a selection, under Format: each puts =*=, =/= or =~= around the selection. With no selection, the commands of the same names in Commands insert a pair of markers with the caret between. Overview (=S-TAB=, Cycle Global Visibility) and Open Link (=C-c C-o=, or a tap on the link) are in Commands. |
| 154 | 154 | |
| 155 | *** Choosing the buttons | |
| 156 | ||
| 157 | Settings ▸ Key Bar lists the bar's buttons in order. Drag a row by its handle to move it, tap the red minus to remove it, and tap Add Button… to add one from the Commands list, grouped as Commands groups it, with the bar's own buttons (Overview, Open Link, Bold, Italic, Code and the rest) first. Any command can be a button, as can a snippet and a named keyboard macro. Reset to Default brings back the buttons above. The iPhone and iPad tabs at the top choose the list: the iPhone buttons show where the editor is narrow, which includes iPad in Slide Over or a narrow split, and the iPad buttons where it is wide. | |
| 158 | ||
| 159 | The lists are =[key-bar]= in the configuration folder's =config.toml= (see [[file:13-configuration.org][Configuration]]), so edits there apply too, and other devices using the folder share them. Without a configuration folder, they are kept on the device. An id the app doesn't know is reported in red under the folder in Settings, and skipped. | |
| 160 | ||
| 161 | A button shows its command's symbol where it has one, such as the arrows for Undo and Redo or a clock for Clock In; otherwise its title, on up to two lines, in a button twice as wide. A snippet shows its trigger and a macro its name. VoiceOver reads the command's title. | |
| 162 | ||
| 163 | When the buttons don't fit the width, the bar shows as many as fit, in order, and a More button (…) at the end holds the rest as a menu. The bar never scrolls. Turning the device on its side makes room for more. | |
| 164 | ||
| 165 | While a snippet's fields are filled in, Previous Snippet Field and Next Snippet Field take the places of Promote and Demote, so the fields work without a hardware keyboard; Promote and Demote come back when the snippet ends. A bar without Promote or Demote shows the field buttons first. | |
| 166 | ||
| 155 | 167 | ** Commands |
| 156 | 168 | |
| 157 | 169 | Commands, in the key bar and in the toolbar of the editor, the reader and the agenda, lists the commands of the screen. With nothing typed, the ten you ran from Commands most recently come first under Recent, then every command by subject, in the Org menu's groups (Visibility, Headings, TODO and Tags, and so on) followed by Clock, Export, File, Edit and View. Type to search: the letters you type must appear in the title in order, as in the Mac's command palette, and commands you run often rank a little higher. The command runs once the list closes. |
| @@ -214,7 +226,7 @@ Snippets come from =snippets.toml= in the configuration folder, the same file as | ||
| 214 | 226 | |
| 215 | 227 | - Insert Snippet… in Commands lists them and expands the one you choose at the caret, replacing the selection. Questions in the snippet open the question sheet, one after another. |
| 216 | 228 | - With a hardware keyboard, =TAB= after a trigger expands it where =TAB= has no other meaning, as on the Mac, and =TAB=, =S-TAB= and =Escape= move through the fields. |
| 217 | - On the on-screen keyboard, which has no =TAB=, the first field is selected after expanding, so typing replaces it; tapping elsewhere ends the snippet. The key bar has no snippet buttons yet. | |
| 229 | - On the on-screen keyboard, which has no =TAB=, the first field is selected after expanding, so typing replaces it. Previous Snippet Field and Next Snippet Field in the key bar move between the fields; leaving the last field or tapping elsewhere ends the snippet. A snippet can be a key bar button of its own, showing its trigger. | |
| 218 | 230 | - Mirrors and the band behind the active field work as on the Mac. |
| 219 | 231 | - New File from Template… is under + in Folders. |
| 220 | 232 | |
l10n/Localizable.xcstrings +344 · view
| @@ -3275,6 +3275,75 @@ | ||
| 3275 | 3275 | } |
| 3276 | 3276 | } |
| 3277 | 3277 | }, |
| 3278 | "Add Button": { | |
| 3279 | "comment": "Title of the list a key bar button is chosen from", | |
| 3280 | "localizations": { | |
| 3281 | "de": { | |
| 3282 | "stringUnit": { | |
| 3283 | "state": "translated", | |
| 3284 | "value": "Taste hinzufügen" | |
| 3285 | } | |
| 3286 | }, | |
| 3287 | "es": { | |
| 3288 | "stringUnit": { | |
| 3289 | "state": "translated", | |
| 3290 | "value": "Añadir botón" | |
| 3291 | } | |
| 3292 | }, | |
| 3293 | "fr": { | |
| 3294 | "stringUnit": { | |
| 3295 | "state": "translated", | |
| 3296 | "value": "Ajouter un bouton" | |
| 3297 | } | |
| 3298 | }, | |
| 3299 | "ja": { | |
| 3300 | "stringUnit": { | |
| 3301 | "state": "translated", | |
| 3302 | "value": "ボタンを追加" | |
| 3303 | } | |
| 3304 | }, | |
| 3305 | "pt-BR": { | |
| 3306 | "stringUnit": { | |
| 3307 | "state": "translated", | |
| 3308 | "value": "Adicionar botão" | |
| 3309 | } | |
| 3310 | } | |
| 3311 | } | |
| 3312 | }, | |
| 3313 | "Add Button…": { | |
| 3314 | "localizations": { | |
| 3315 | "de": { | |
| 3316 | "stringUnit": { | |
| 3317 | "state": "translated", | |
| 3318 | "value": "Taste hinzufügen …" | |
| 3319 | } | |
| 3320 | }, | |
| 3321 | "es": { | |
| 3322 | "stringUnit": { | |
| 3323 | "state": "translated", | |
| 3324 | "value": "Añadir botón…" | |
| 3325 | } | |
| 3326 | }, | |
| 3327 | "fr": { | |
| 3328 | "stringUnit": { | |
| 3329 | "state": "translated", | |
| 3330 | "value": "Ajouter un bouton…" | |
| 3331 | } | |
| 3332 | }, | |
| 3333 | "ja": { | |
| 3334 | "stringUnit": { | |
| 3335 | "state": "translated", | |
| 3336 | "value": "ボタンを追加…" | |
| 3337 | } | |
| 3338 | }, | |
| 3339 | "pt-BR": { | |
| 3340 | "stringUnit": { | |
| 3341 | "state": "translated", | |
| 3342 | "value": "Adicionar botão…" | |
| 3343 | } | |
| 3344 | } | |
| 3345 | } | |
| 3346 | }, | |
| 3278 | 3347 | "Add Folder": { |
| 3279 | 3348 | "localizations": { |
| 3280 | 3349 | "de": { |
| @@ -6289,6 +6358,75 @@ | ||
| 6289 | 6358 | } |
| 6290 | 6359 | } |
| 6291 | 6360 | }, |
| 6361 | "Buttons": { | |
| 6362 | "comment": "Key bar settings section", | |
| 6363 | "localizations": { | |
| 6364 | "de": { | |
| 6365 | "stringUnit": { | |
| 6366 | "state": "translated", | |
| 6367 | "value": "Tasten" | |
| 6368 | } | |
| 6369 | }, | |
| 6370 | "es": { | |
| 6371 | "stringUnit": { | |
| 6372 | "state": "translated", | |
| 6373 | "value": "Botones" | |
| 6374 | } | |
| 6375 | }, | |
| 6376 | "fr": { | |
| 6377 | "stringUnit": { | |
| 6378 | "state": "translated", | |
| 6379 | "value": "Boutons" | |
| 6380 | } | |
| 6381 | }, | |
| 6382 | "ja": { | |
| 6383 | "stringUnit": { | |
| 6384 | "state": "translated", | |
| 6385 | "value": "ボタン" | |
| 6386 | } | |
| 6387 | }, | |
| 6388 | "pt-BR": { | |
| 6389 | "stringUnit": { | |
| 6390 | "state": "translated", | |
| 6391 | "value": "Botões" | |
| 6392 | } | |
| 6393 | } | |
| 6394 | } | |
| 6395 | }, | |
| 6396 | "Buttons that don't fit go under More. While a snippet's fields are filled in, Previous Snippet Field and Next Snippet Field take the places of Promote and Demote.": { | |
| 6397 | "localizations": { | |
| 6398 | "de": { | |
| 6399 | "stringUnit": { | |
| 6400 | "state": "translated", | |
| 6401 | "value": "Tasten, die nicht passen, stehen unter „Mehr“. Während die Felder eines Textbausteins ausgefüllt werden, ersetzen „Vorheriges Feld im Textbaustein“ und „Nächstes Feld im Textbaustein“ die Tasten „Höherstufen“ und „Tieferstufen“." | |
| 6402 | } | |
| 6403 | }, | |
| 6404 | "es": { | |
| 6405 | "stringUnit": { | |
| 6406 | "state": "translated", | |
| 6407 | "value": "Los botones que no caben van en Más. Mientras se rellenan los campos de un fragmento, Campo anterior del fragmento y Siguiente campo del fragmento ocupan el lugar de Subir nivel y Bajar nivel." | |
| 6408 | } | |
| 6409 | }, | |
| 6410 | "fr": { | |
| 6411 | "stringUnit": { | |
| 6412 | "state": "translated", | |
| 6413 | "value": "Les boutons qui ne tiennent pas vont dans Plus. Pendant qu'on remplit les champs d'un extrait, Champ précédent de l'extrait et Champ suivant de l'extrait prennent la place de Remonter et Abaisser." | |
| 6414 | } | |
| 6415 | }, | |
| 6416 | "ja": { | |
| 6417 | "stringUnit": { | |
| 6418 | "state": "translated", | |
| 6419 | "value": "収まらないボタンは「その他」に入ります。スニペットのフィールドを入力している間は、「レベルを上げる」と「レベルを下げる」の位置に「スニペットの前のフィールド」と「スニペットの次のフィールド」が表示されます。" | |
| 6420 | } | |
| 6421 | }, | |
| 6422 | "pt-BR": { | |
| 6423 | "stringUnit": { | |
| 6424 | "state": "translated", | |
| 6425 | "value": "Os botões que não cabem ficam em Mais. Enquanto os campos de um trecho são preenchidos, Campo Anterior do Trecho e Próximo Campo do Trecho ocupam o lugar de Promover e Rebaixar." | |
| 6426 | } | |
| 6427 | } | |
| 6428 | } | |
| 6429 | }, | |
| 6292 | 6430 | "Buy orgstar+…": { |
| 6293 | 6431 | "extractionState": "stale", |
| 6294 | 6432 | "localizations": { |
| @@ -20364,6 +20502,41 @@ | ||
| 20364 | 20502 | } |
| 20365 | 20503 | } |
| 20366 | 20504 | }, |
| 20505 | "Key Bar": { | |
| 20506 | "comment": "Settings section", | |
| 20507 | "localizations": { | |
| 20508 | "de": { | |
| 20509 | "stringUnit": { | |
| 20510 | "state": "translated", | |
| 20511 | "value": "Tastenleiste" | |
| 20512 | } | |
| 20513 | }, | |
| 20514 | "es": { | |
| 20515 | "stringUnit": { | |
| 20516 | "state": "translated", | |
| 20517 | "value": "Barra de teclas" | |
| 20518 | } | |
| 20519 | }, | |
| 20520 | "fr": { | |
| 20521 | "stringUnit": { | |
| 20522 | "state": "translated", | |
| 20523 | "value": "Barre de touches" | |
| 20524 | } | |
| 20525 | }, | |
| 20526 | "ja": { | |
| 20527 | "stringUnit": { | |
| 20528 | "state": "translated", | |
| 20529 | "value": "キーバー" | |
| 20530 | } | |
| 20531 | }, | |
| 20532 | "pt-BR": { | |
| 20533 | "stringUnit": { | |
| 20534 | "state": "translated", | |
| 20535 | "value": "Barra de teclas" | |
| 20536 | } | |
| 20537 | } | |
| 20538 | } | |
| 20539 | }, | |
| 20367 | 20540 | "Key Bindings": { |
| 20368 | 20541 | "localizations": { |
| 20369 | 20542 | "de": { |
| @@ -20777,6 +20950,41 @@ | ||
| 20777 | 20950 | } |
| 20778 | 20951 | } |
| 20779 | 20952 | }, |
| 20953 | "Layout": { | |
| 20954 | "comment": "Key bar settings: which list of buttons, iPhone or iPad", | |
| 20955 | "localizations": { | |
| 20956 | "de": { | |
| 20957 | "stringUnit": { | |
| 20958 | "state": "translated", | |
| 20959 | "value": "Layout" | |
| 20960 | } | |
| 20961 | }, | |
| 20962 | "es": { | |
| 20963 | "stringUnit": { | |
| 20964 | "state": "translated", | |
| 20965 | "value": "Disposición" | |
| 20966 | } | |
| 20967 | }, | |
| 20968 | "fr": { | |
| 20969 | "stringUnit": { | |
| 20970 | "state": "translated", | |
| 20971 | "value": "Disposition" | |
| 20972 | } | |
| 20973 | }, | |
| 20974 | "ja": { | |
| 20975 | "stringUnit": { | |
| 20976 | "state": "translated", | |
| 20977 | "value": "レイアウト" | |
| 20978 | } | |
| 20979 | }, | |
| 20980 | "pt-BR": { | |
| 20981 | "stringUnit": { | |
| 20982 | "state": "translated", | |
| 20983 | "value": "Layout" | |
| 20984 | } | |
| 20985 | } | |
| 20986 | } | |
| 20987 | }, | |
| 20780 | 20988 | "Leave Block": { |
| 20781 | 20989 | "comment": "Command title", |
| 20782 | 20990 | "localizations": { |
| @@ -26144,6 +26352,40 @@ | ||
| 26144 | 26352 | } |
| 26145 | 26353 | } |
| 26146 | 26354 | }, |
| 26355 | "Not a command here; the key bar skips it.": { | |
| 26356 | "localizations": { | |
| 26357 | "de": { | |
| 26358 | "stringUnit": { | |
| 26359 | "state": "translated", | |
| 26360 | "value": "Hier kein Befehl; die Tastenleiste lässt ihn aus." | |
| 26361 | } | |
| 26362 | }, | |
| 26363 | "es": { | |
| 26364 | "stringUnit": { | |
| 26365 | "state": "translated", | |
| 26366 | "value": "Aquí no es un comando; la barra de teclas lo omite." | |
| 26367 | } | |
| 26368 | }, | |
| 26369 | "fr": { | |
| 26370 | "stringUnit": { | |
| 26371 | "state": "translated", | |
| 26372 | "value": "Pas une commande ici ; la barre de touches l'ignore." | |
| 26373 | } | |
| 26374 | }, | |
| 26375 | "ja": { | |
| 26376 | "stringUnit": { | |
| 26377 | "state": "translated", | |
| 26378 | "value": "ここではコマンドではないため、キーバーでは省略されます。" | |
| 26379 | } | |
| 26380 | }, | |
| 26381 | "pt-BR": { | |
| 26382 | "stringUnit": { | |
| 26383 | "state": "translated", | |
| 26384 | "value": "Não é um comando aqui; a barra de teclas o ignora." | |
| 26385 | } | |
| 26386 | } | |
| 26387 | } | |
| 26388 | }, | |
| 26147 | 26389 | "Not an encrypted entry": { |
| 26148 | 26390 | "localizations": { |
| 26149 | 26391 | "de": { |
| @@ -32603,6 +32845,40 @@ | ||
| 32603 | 32845 | } |
| 32604 | 32846 | } |
| 32605 | 32847 | }, |
| 32848 | "Reset to Default": { | |
| 32849 | "localizations": { | |
| 32850 | "de": { | |
| 32851 | "stringUnit": { | |
| 32852 | "state": "translated", | |
| 32853 | "value": "Auf Standard zurücksetzen" | |
| 32854 | } | |
| 32855 | }, | |
| 32856 | "es": { | |
| 32857 | "stringUnit": { | |
| 32858 | "state": "translated", | |
| 32859 | "value": "Restablecer valores por omisión" | |
| 32860 | } | |
| 32861 | }, | |
| 32862 | "fr": { | |
| 32863 | "stringUnit": { | |
| 32864 | "state": "translated", | |
| 32865 | "value": "Rétablir les valeurs par défaut" | |
| 32866 | } | |
| 32867 | }, | |
| 32868 | "ja": { | |
| 32869 | "stringUnit": { | |
| 32870 | "state": "translated", | |
| 32871 | "value": "デフォルトに戻す" | |
| 32872 | } | |
| 32873 | }, | |
| 32874 | "pt-BR": { | |
| 32875 | "stringUnit": { | |
| 32876 | "state": "translated", | |
| 32877 | "value": "Restaurar padrão" | |
| 32878 | } | |
| 32879 | } | |
| 32880 | } | |
| 32881 | }, | |
| 32606 | 32882 | "Resolve Open Clocks…": { |
| 32607 | 32883 | "comment": "Command title", |
| 32608 | 32884 | "localizations": { |
| @@ -39454,6 +39730,40 @@ | ||
| 39454 | 39730 | } |
| 39455 | 39731 | } |
| 39456 | 39732 | }, |
| 39733 | "The buttons above the on-screen keyboard.": { | |
| 39734 | "localizations": { | |
| 39735 | "de": { | |
| 39736 | "stringUnit": { | |
| 39737 | "state": "translated", | |
| 39738 | "value": "Die Tasten über der Bildschirmtastatur." | |
| 39739 | } | |
| 39740 | }, | |
| 39741 | "es": { | |
| 39742 | "stringUnit": { | |
| 39743 | "state": "translated", | |
| 39744 | "value": "Los botones sobre el teclado en pantalla." | |
| 39745 | } | |
| 39746 | }, | |
| 39747 | "fr": { | |
| 39748 | "stringUnit": { | |
| 39749 | "state": "translated", | |
| 39750 | "value": "Les boutons au-dessus du clavier à l'écran." | |
| 39751 | } | |
| 39752 | }, | |
| 39753 | "ja": { | |
| 39754 | "stringUnit": { | |
| 39755 | "state": "translated", | |
| 39756 | "value": "画面キーボードの上のボタン。" | |
| 39757 | } | |
| 39758 | }, | |
| 39759 | "pt-BR": { | |
| 39760 | "stringUnit": { | |
| 39761 | "state": "translated", | |
| 39762 | "value": "Os botões acima do teclado na tela." | |
| 39763 | } | |
| 39764 | } | |
| 39765 | } | |
| 39766 | }, | |
| 39457 | 39767 | "The calendar button under the sidebar shows your agenda, or a view from views.toml, beside the editor.": { |
| 39458 | 39768 | "localizations": { |
| 39459 | 39769 | "de": { |
| @@ -39794,6 +40104,40 @@ | ||
| 39794 | 40104 | } |
| 39795 | 40105 | } |
| 39796 | 40106 | }, |
| 40107 | "The iPhone buttons show where the editor is narrow, the iPad buttons where it is wide.": { | |
| 40108 | "localizations": { | |
| 40109 | "de": { | |
| 40110 | "stringUnit": { | |
| 40111 | "state": "translated", | |
| 40112 | "value": "Die iPhone-Tasten erscheinen, wo der Editor schmal ist, die iPad-Tasten, wo er breit ist." | |
| 40113 | } | |
| 40114 | }, | |
| 40115 | "es": { | |
| 40116 | "stringUnit": { | |
| 40117 | "state": "translated", | |
| 40118 | "value": "Los botones de iPhone aparecen donde el editor es estrecho; los de iPad, donde es ancho." | |
| 40119 | } | |
| 40120 | }, | |
| 40121 | "fr": { | |
| 40122 | "stringUnit": { | |
| 40123 | "state": "translated", | |
| 40124 | "value": "Les boutons iPhone s'affichent quand l'éditeur est étroit, les boutons iPad quand il est large." | |
| 40125 | } | |
| 40126 | }, | |
| 40127 | "ja": { | |
| 40128 | "stringUnit": { | |
| 40129 | "state": "translated", | |
| 40130 | "value": "エディタの幅が狭いときは iPhone のボタン、広いときは iPad のボタンが表示されます。" | |
| 40131 | } | |
| 40132 | }, | |
| 40133 | "pt-BR": { | |
| 40134 | "stringUnit": { | |
| 40135 | "state": "translated", | |
| 40136 | "value": "Os botões do iPhone aparecem onde o editor é estreito; os do iPad, onde é largo." | |
| 40137 | } | |
| 40138 | } | |
| 40139 | } | |
| 40140 | }, | |
| 39797 | 40141 | "The icon shows in the Dock while orgstar runs. Finder, and the Dock after orgstar quits, show the default icon.": { |
| 39798 | 40142 | "localizations": { |
| 39799 | 40143 | "de": { |