Commit abcaabca33

abcaabca33fcb4101dc96bf6944c550a1517f005

parent: e3a87cf5b4

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-23 04:23 UTC

Share Mac and iOS diff, Emacs import and column grid views; split publish

- DiffView, EmacsImportSections and ColumnViewGrid move to OrgApp.
- Mac settings: one helper for calendar and reminder-list toggles.
- ElectricPair: inhibit and skip share the typed-character prologue.
- Publish: output path and write steps are helpers.
- Qlty: ignore switch and dictionary tables for duplication; turn off
  nested_control_flow for Swift, where else-if chains count as nesting.

Layout: unified · split

.qlty/qlty.toml +9
@@ -58,3 +58,12 @@ match.plugins = ["swiftlint"]
5858match.rules = ["swiftlint:force_try"]
5959match.file_patterns = ["Tests/**"]
6060set.ignored = true
61
62# Exhaustive switch-over-enum lookup tables and the light and dark color tables share shape but not content.
63[language.swift.smells.duplication]
64filter_patterns = ["(import_declaration _)", "(switch_statement _)", "(dictionary_literal _)"]
65
66# tree-sitter-swift nests each `else if` inside the previous branch, so a one-line `if` in the
67# fourth branch of a flat chain reports level 5.
68[language.swift.smells.nested_control_flow]
69enabled = false
Sources/OrgApp/ColumnViewGrid.swift added +31
@@ -0,0 +1,31 @@
1import OrgCore
2import SwiftUI
3
4/// `org-columns` laid out: a row of column titles, a rule, then a row per entry, each cell from `cell(row, column)`.
5public struct ColumnViewGrid<Cell: View>: View {
6 let view: ColumnView.View
7 let verticalSpacing: CGFloat
8 let cell: (Int, Int) -> Cell
9
10 public init(view: ColumnView.View, verticalSpacing: CGFloat, @ViewBuilder cell: @escaping (Int, Int) -> Cell) {
11 self.view = view
12 self.verticalSpacing = verticalSpacing
13 self.cell = cell
14 }
15
16 public var body: some View {
17 Grid(alignment: .leading, horizontalSpacing: 14, verticalSpacing: verticalSpacing) {
18 GridRow {
19 ForEach(view.specs.indices, id: \.self) { i in
20 Text(view.specs[i].title).bold().foregroundStyle(.secondary)
21 }
22 }
23 Divider()
24 ForEach(view.rows.indices, id: \.self) { r in
25 GridRow {
26 ForEach(view.specs.indices, id: \.self) { c in cell(r, c) }
27 }
28 }
29 }
30 }
31}
Sources/OrgApp/DiffView.swift added +79
@@ -0,0 +1,79 @@
1import OrgDocument
2import SwiftUI
3
4/// Lines removed and added between two versions, with a few lines of context around each change.
5public struct DiffView: View {
6 let lines: [DiffLine]
7 var context = 3
8
9 public init(old: String, new: String) {
10 lines = lineDiff(old: old, new: new)
11 }
12
13 /// Lines to show, nil standing for a run of unchanged lines left out.
14 private var shown: [DiffLine?] {
15 let changed = lines.indices.filter { lines[$0].kind != .same }
16 guard !changed.isEmpty else { return [] }
17 var keep = Set<Int>()
18 for i in changed { keep.formUnion(max(0, i - context)...min(lines.count - 1, i + context)) }
19 var out: [DiffLine?] = []
20 var skipped = false
21 for i in lines.indices {
22 if keep.contains(i) {
23 out.append(lines[i])
24 skipped = false
25 } else if !skipped {
26 out.append(nil)
27 skipped = true
28 }
29 }
30 return out
31 }
32
33 public var body: some View {
34 let shown = shown
35 ScrollView([.vertical, .horizontal]) {
36 VStack(alignment: .leading, spacing: 0) {
37 if shown.isEmpty { Text("No differences").foregroundStyle(.secondary).padding(8) }
38 ForEach(shown.indices, id: \.self) { i in
39 if let line = shown[i] {
40 Text(prefix(line.kind) + line.text.trimmingCharacters(in: .newlines))
41 .frame(maxWidth: .infinity, alignment: .leading)
42 .background(background(line.kind))
43 } else {
44 Text("⋯").foregroundStyle(.secondary)
45 }
46 }
47 }
48 #if os(macOS)
49 .font(.system(.callout, design: .monospaced))
50 #else
51 .font(.system(.footnote, design: .monospaced))
52 #endif
53 .textSelection(.enabled)
54 .padding(8)
55 }
56 .defaultScrollAnchor(.topLeading)
57 #if os(macOS)
58 .background(Color(nsColor: .textBackgroundColor))
59 #else
60 .background(Color(uiColor: .secondarySystemBackground))
61 #endif
62 }
63
64 private func prefix(_ kind: DiffLine.Kind) -> String {
65 switch kind {
66 case .same: " "
67 case .removed: "- "
68 case .added: "+ "
69 }
70 }
71
72 private func background(_ kind: DiffLine.Kind) -> Color {
73 switch kind {
74 case .same: .clear
75 case .removed: .red.opacity(0.18)
76 case .added: .green.opacity(0.18)
77 }
78 }
79}
Sources/OrgApp/EmacsImportSections.swift added +60
@@ -0,0 +1,60 @@
1import SwiftUI
2
3extension EmacsImport {
4 /// The items by kind of change, empty kinds left out; agenda folders only when `folders`.
5 public func groups(folders: Bool) -> [(String, [Item])] {
6 [
7 ("Settings", items.filter { if case .setting = $0.change { true } else { false } }),
8 ("Folders", folders ? items.filter { if case .folder = $0.change { true } else { false } } : []),
9 ("Capture templates", items.filter { if case .capture = $0.change { true } else { false } }),
10 ("Key bindings", items.filter { if case .binding = $0.change { true } else { false } }),
11 ("Structure templates", items.filter { if case .structureTemplate = $0.change { true } else { false } }),
12 ("Agenda views", items.filter { if case .view = $0.change { true } else { false } }),
13 ].filter { !$0.1.isEmpty }
14 }
15}
16
17/// A section of toggles per group of an import, then what wasn't imported and why.
18public struct EmacsImportSections: View {
19 let result: EmacsImport
20 let groups: [(String, [EmacsImport.Item])]
21 @Binding var selected: Set<Int>
22 let font: Font
23
24 public init(result: EmacsImport, groups: [(String, [EmacsImport.Item])], selected: Binding<Set<Int>>, font: Font) {
25 self.result = result
26 self.groups = groups
27 _selected = selected
28 self.font = font
29 }
30
31 public var body: some View {
32 ForEach(groups, id: \.0) { title, items in
33 Section(title) {
34 ForEach(items) { item in
35 Toggle(isOn: Binding { selected.contains(item.id) } set: { on in
36 if on { selected.insert(item.id) } else { selected.remove(item.id) }
37 }) {
38 VStack(alignment: .leading, spacing: 1) {
39 Text(item.summary).font(font)
40 Text([item.name == item.summary ? nil : item.name, item.source.isEmpty ? nil : item.source].compactMap { $0 }.joined(separator: " · "))
41 .font(.caption).foregroundStyle(.secondary)
42 }
43 }
44 }
45 }
46 }
47 let notes = result.unsupported.map { ($0.id, $0.name, $0.reason, $0.source) } + result.unreadable.map { ($0.id, $0.name, $0.reason, $0.source) }
48 if !notes.isEmpty || !result.problems.isEmpty {
49 Section("Not imported") {
50 ForEach(result.problems, id: \.self) { Text($0).foregroundStyle(.red) }
51 ForEach(notes, id: \.0) { note in
52 VStack(alignment: .leading, spacing: 1) {
53 Text(note.1).font(font)
54 Text("\(note.2) · \(note.3)").font(.caption).foregroundStyle(.secondary)
55 }
56 }
57 }
58 }
59 }
60}
Sources/OrgApp/Publish.swift +28 −16
@@ -270,27 +270,13 @@ public enum Publish {
270270 let relative = String(file.dropFirst(base.count))
271271 let outputDirectory = directory(p.publishingDirectory) + ((relative as NSString).deletingLastPathComponent.isEmpty ? "" : (relative as NSString).deletingLastPathComponent + "/")
272272 for function in p.publishingFunctions {
273 let output: String
274 if function == "org-publish-attachment" {
275 output = outputDirectory + (file as NSString).lastPathComponent
276 if directory((file as NSString).deletingLastPathComponent) == outputDirectory { continue }
277 } else {
278 let ext = function == "org-md-publish-to-md" ? "md" : "html"
279 guard let text = read(file) else { throw Failure(description: "Can't read \(file)") }
280 output = ExportScope.output(for: URL(fileURLWithPath: outputDirectory + (file as NSString).lastPathComponent),
281 name: ExportScope.fileName(text), extension: ext).path
282 }
273 guard let output = try outputPath(file, function: function, in: outputDirectory, read: read) else { continue }
283274 if !force, upToDate(output, source: file) {
284275 report.skipped.append(file)
285276 continue
286277 }
287278 try fm.createDirectory(atPath: (output as NSString).deletingLastPathComponent, withIntermediateDirectories: true)
288 if function == "org-publish-attachment" {
289 if fm.fileExists(atPath: output) { try fm.removeItem(atPath: output) }
290 try fm.copyItem(atPath: file, toPath: output)
291 } else {
292 try export(function, read(file) ?? "", file, p.bodyOnly).write(toFile: output, atomically: true, encoding: .utf8)
293 }
279 try write(file, to: output, function: function, bodyOnly: p.bodyOnly, read: read, export: export)
294280 report.published.append(file)
295281 }
296282 }
@@ -298,6 +284,32 @@ public enum Publish {
298284 return report
299285 }
300286
287 /// Where `function` publishes `file` in `outputDirectory`; nil for an attachment already there.
288 private static func outputPath(_ file: String, function: String, in outputDirectory: String, read: (String) -> String?) throws -> String? {
289 guard function != "org-publish-attachment" else {
290 if directory((file as NSString).deletingLastPathComponent) == outputDirectory { return nil }
291 return outputDirectory + (file as NSString).lastPathComponent
292 }
293 let ext = function == "org-md-publish-to-md" ? "md" : "html"
294 guard let text = read(file) else { throw Failure(description: "Can't read \(file)") }
295 return ExportScope.output(for: URL(fileURLWithPath: outputDirectory + (file as NSString).lastPathComponent),
296 name: ExportScope.fileName(text), extension: ext).path
297 }
298
299 /// Copies an attachment to `output`, or writes what `function` exports from `file`.
300 private static func write(
301 _ file: String, to output: String, function: String, bodyOnly: Bool,
302 read: (String) -> String?, export: (_ function: String, _ text: String, _ path: String, _ bodyOnly: Bool) -> String
303 ) throws {
304 let fm = FileManager.default
305 if function == "org-publish-attachment" {
306 if fm.fileExists(atPath: output) { try fm.removeItem(atPath: output) }
307 try fm.copyItem(atPath: file, toPath: output)
308 } else {
309 try export(function, read(file) ?? "", file, bodyOnly).write(toFile: output, atomically: true, encoding: .utf8)
310 }
311 }
312
301313 static func upToDate(_ output: String, source: String) -> Bool {
302314 let fm = FileManager.default
303315 guard let out = try? fm.attributesOfItem(atPath: output)[.modificationDate] as? Date,
Sources/OrgCore/Commands/ElectricPair.swift +29 −23
@@ -277,38 +277,44 @@ private final class PairBuffer {
277277 return (innermost!, outermost!)
278278 }
279279
280 /// `electric-pair-inhibit-if-helps-balance`, with the typed character before point.
281 func inhibit(_ c: unichar) -> Bool {
280 /// Runs `check` with the typed character taken out from before point, as electric-pair's
281 /// balance checks do, and puts it back.
282 private func withoutTyped(_ c: unichar, _ check: (Info) -> Bool) -> Bool {
282283 guard let info = info(c) else { return false }
283284 let at = point - 1
284285 delete(at..<point)
285286 defer { insert(String(utf16CodeUnits: [c], count: 1), at: at) }
286 switch info.syntax {
287 case .open:
288 let outermost = balance(forward: true, stringStart: info.stringStart).outermost
289 return outermost.matched ? false : outermost.pair == info.pair
290 case .string:
291 return ppss(length).stringChar == c
292 case .close:
293 return false
287 return check(info)
288 }
289
290 /// `electric-pair-inhibit-if-helps-balance`, with the typed character before point.
291 func inhibit(_ c: unichar) -> Bool {
292 withoutTyped(c) { info in
293 switch info.syntax {
294 case .open:
295 let outermost = balance(forward: true, stringStart: info.stringStart).outermost
296 return outermost.matched ? false : outermost.pair == info.pair
297 case .string:
298 return ppss(length).stringChar == c
299 case .close:
300 return false
301 }
294302 }
295303 }
296304
297305 /// `electric-pair-skip-if-helps-balance`, with the typed character before point.
298306 func skip(_ c: unichar) -> Bool {
299 guard let info = info(c) else { return false }
300 let at = point - 1
301 delete(at..<point)
302 defer { insert(String(utf16CodeUnits: [c], count: 1), at: at) }
303 switch info.syntax {
304 case .close:
305 let (innermost, outermost) = balance(forward: false, stringStart: info.stringStart)
306 if outermost.matched { return innermost.matched }
307 return innermost.matched && outermost.pair != info.pair
308 case .string:
309 return ppss(point).stringChar == c
310 case .open:
311 return false
307 withoutTyped(c) { info in
308 switch info.syntax {
309 case .close:
310 let (innermost, outermost) = balance(forward: false, stringStart: info.stringStart)
311 if outermost.matched { return innermost.matched }
312 return innermost.matched && outermost.pair != info.pair
313 case .string:
314 return ppss(point).stringChar == c
315 case .open:
316 return false
317 }
312318 }
313319 }
314320
Sources/Orgstar/ColumnViewSheet.swift +2 −13
@@ -1,3 +1,4 @@
1import OrgApp
12import OrgCore
23import SwiftUI
34
@@ -37,19 +38,7 @@ struct ColumnViewSheet: View {
3738 .padding(10)
3839 Divider()
3940 ScrollView([.horizontal, .vertical]) {
40 Grid(alignment: .leading, horizontalSpacing: 14, verticalSpacing: 4) {
41 GridRow {
42 ForEach(view.specs.indices, id: \.self) { i in
43 Text(view.specs[i].title).bold().foregroundStyle(.secondary)
44 }
45 }
46 Divider()
47 ForEach(view.rows.indices, id: \.self) { r in
48 GridRow {
49 ForEach(view.specs.indices, id: \.self) { c in cellView(r, c) }
50 }
51 }
52 }
41 ColumnViewGrid(view: view, verticalSpacing: 4) { r, c in cellView(r, c) }
5342 .font(.system(.body, design: .monospaced))
5443 .padding(10)
5544 }
Sources/Orgstar/EmacsImportView.swift +3 −36
@@ -65,42 +65,9 @@ struct EmacsImportView: View {
6565 }
6666
6767 private func list(_ result: EmacsImport) -> some View {
68 let groups: [(String, [EmacsImport.Item])] = [
69 ("Settings", result.items.filter { if case .setting = $0.change { true } else { false } }),
70 ("Folders", result.items.filter { if case .folder = $0.change { true } else { false } }),
71 ("Capture templates", result.items.filter { if case .capture = $0.change { true } else { false } }),
72 ("Key bindings", result.items.filter { if case .binding = $0.change { true } else { false } }),
73 ("Structure templates", result.items.filter { if case .structureTemplate = $0.change { true } else { false } }),
74 ("Agenda views", result.items.filter { if case .view = $0.change { true } else { false } }),
75 ]
76 return List {
77 ForEach(groups.filter { !$0.1.isEmpty }, id: \.0) { title, items in
78 Section(title) {
79 ForEach(items) { item in
80 Toggle(isOn: Binding { selected.contains(item.id) } set: { on in
81 if on { selected.insert(item.id) } else { selected.remove(item.id) }
82 }) {
83 VStack(alignment: .leading, spacing: 1) {
84 Text(item.summary).font(.system(.body, design: .monospaced))
85 Text([item.name == item.summary ? nil : item.name, item.source.isEmpty ? nil : item.source].compactMap { $0 }.joined(separator: " · "))
86 .font(.caption).foregroundStyle(.secondary)
87 }
88 }
89 }
90 }
91 }
92 let notes = result.unsupported.map { ($0.id, $0.name, $0.reason, $0.source) } + result.unreadable.map { ($0.id, $0.name, $0.reason, $0.source) }
93 if !notes.isEmpty || !result.problems.isEmpty {
94 Section("Not imported") {
95 ForEach(result.problems, id: \.self) { Text($0).foregroundStyle(.red) }
96 ForEach(notes, id: \.0) { note in
97 VStack(alignment: .leading, spacing: 1) {
98 Text(note.1).font(.system(.body, design: .monospaced))
99 Text("\(note.2) · \(note.3)").font(.caption).foregroundStyle(.secondary)
100 }
101 }
102 }
103 }
68 List {
69 EmacsImportSections(result: result, groups: result.groups(folders: true), selected: $selected,
70 font: .system(.body, design: .monospaced))
10471 }
10572 }
10673
Sources/Orgstar/OrgstarApp.swift +21 −28
@@ -844,20 +844,7 @@ struct SettingsView: View {
844844 Section {
845845 Toggle("Show events from Calendar", isOn: $calendarEvents)
846846 if calendarEvents {
847 if calendars.isEmpty {
848 Text(CalendarEvents.isAuthorized ? "No calendars." : "Allow orgstar to read your calendars in System Settings ▸ Privacy & Security ▸ Calendars.")
849 .foregroundStyle(.secondary)
850 }
851 ForEach(calendars, id: \.id) { calendar in
852 Toggle(isOn: chosen(calendar, among: calendars, setting: $calendarEventCalendars)) {
853 HStack(spacing: 6) {
854 Circle()
855 .fill(calendar.color.map { Color(.sRGB, red: $0.red, green: $0.green, blue: $0.blue, opacity: $0.alpha) } ?? .secondary)
856 .frame(width: 8, height: 8)
857 Text(calendar.title)
858 }
859 }
860 }
847 choices(calendars, empty: CalendarEvents.isAuthorized ? "No calendars." : "Allow orgstar to read your calendars in System Settings ▸ Privacy & Security ▸ Calendars.", setting: $calendarEventCalendars)
861848 }
862849 } footer: {
863850 Text("Events show in the agenda; double-click one to open it in Calendar, or choose Edit Event… in its context menu. New calendars show while every calendar is checked.")
@@ -870,20 +857,7 @@ struct SettingsView: View {
870857 Section {
871858 Toggle("Show reminders from Reminders", isOn: $agendaReminders)
872859 if agendaReminders {
873 if reminderLists.isEmpty {
874 Text(ReminderLists.isAuthorized ? "No lists." : "Allow orgstar to read your reminders in System Settings ▸ Privacy & Security ▸ Reminders.")
875 .foregroundStyle(.secondary)
876 }
877 ForEach(reminderLists, id: \.id) { list in
878 Toggle(isOn: chosen(list, among: reminderLists, setting: $agendaReminderLists)) {
879 HStack(spacing: 6) {
880 Circle()
881 .fill(list.color.map { Color(.sRGB, red: $0.red, green: $0.green, blue: $0.blue, opacity: $0.alpha) } ?? .secondary)
882 .frame(width: 8, height: 8)
883 Text(list.title)
884 }
885 }
886 }
860 choices(reminderLists, empty: ReminderLists.isAuthorized ? "No lists." : "Allow orgstar to read your reminders in System Settings ▸ Privacy & Security ▸ Reminders.", setting: $agendaReminderLists)
887861 }
888862 } footer: {
889863 Text("Incomplete reminders with a due date show in the agenda read-only, overdue ones under today; double-click one to open it in Reminders.")
@@ -919,6 +893,25 @@ struct SettingsView: View {
919893 .frame(height: 560)
920894 }
921895
896 /// A toggle per calendar or reminder list, with its color; `empty` when there are none.
897 @ViewBuilder
898 private func choices(_ calendars: [(id: String, title: String, color: RGBA?)], empty: LocalizedStringKey, setting: Binding<String>) -> some View {
899 if calendars.isEmpty {
900 Text(empty)
901 .foregroundStyle(.secondary)
902 }
903 ForEach(calendars, id: \.id) { calendar in
904 Toggle(isOn: chosen(calendar, among: calendars, setting: setting)) {
905 HStack(spacing: 6) {
906 Circle()
907 .fill(calendar.color.map { Color(.sRGB, red: $0.red, green: $0.green, blue: $0.blue, opacity: $0.alpha) } ?? .secondary)
908 .frame(width: 8, height: 8)
909 Text(calendar.title)
910 }
911 }
912 }
913 }
914
922915 /// `calendar-event-calendars` and `agenda-reminder-lists`: empty for every calendar or
923916 /// list, else the titles checked.
924917 private func chosen(
Sources/Orgstar/VersionViews.swift −69
@@ -3,75 +3,6 @@ import OrgApp
33import OrgDocument
44import SwiftUI
55
6/// Lines removed and added between two versions, with a few lines of context around each change.
7struct DiffView: View {
8 let lines: [DiffLine]
9 var context = 3
10
11 init(old: String, new: String) {
12 lines = lineDiff(old: old, new: new)
13 }
14
15 /// Lines to show, nil standing for a run of unchanged lines left out.
16 private var shown: [DiffLine?] {
17 let changed = lines.indices.filter { lines[$0].kind != .same }
18 guard !changed.isEmpty else { return [] }
19 var keep = Set<Int>()
20 for i in changed { keep.formUnion(max(0, i - context)...min(lines.count - 1, i + context)) }
21 var out: [DiffLine?] = []
22 var skipped = false
23 for i in lines.indices {
24 if keep.contains(i) {
25 out.append(lines[i])
26 skipped = false
27 } else if !skipped {
28 out.append(nil)
29 skipped = true
30 }
31 }
32 return out
33 }
34
35 var body: some View {
36 let shown = shown
37 ScrollView([.vertical, .horizontal]) {
38 VStack(alignment: .leading, spacing: 0) {
39 if shown.isEmpty { Text("No differences").foregroundStyle(.secondary).padding(8) }
40 ForEach(shown.indices, id: \.self) { i in
41 if let line = shown[i] {
42 Text(prefix(line.kind) + line.text.trimmingCharacters(in: .newlines))
43 .frame(maxWidth: .infinity, alignment: .leading)
44 .background(background(line.kind))
45 } else {
46 Text("⋯").foregroundStyle(.secondary)
47 }
48 }
49 }
50 .font(.system(.callout, design: .monospaced))
51 .textSelection(.enabled)
52 .padding(8)
53 }
54 .defaultScrollAnchor(.topLeading)
55 .background(Color(nsColor: .textBackgroundColor))
56 }
57
58 private func prefix(_ kind: DiffLine.Kind) -> String {
59 switch kind {
60 case .same: " "
61 case .removed: "- "
62 case .added: "+ "
63 }
64 }
65
66 private func background(_ kind: DiffLine.Kind) -> Color {
67 switch kind {
68 case .same: .clear
69 case .removed: .red.opacity(0.18)
70 case .added: .green.opacity(0.18)
71 }
72 }
73}
74
756/// The buffer and the file on disk changed differently: what differs, and how to settle it.
767struct ConflictSheet: View {
778 let session: DocumentSession
Sources/OrgstarMobile/ColumnViewScreen.swift +1 −13
@@ -19,19 +19,7 @@ struct ColumnViewScreen: View {
1919 var body: some View {
2020 NavigationStack {
2121 ScrollView([.horizontal, .vertical]) {
22 Grid(alignment: .leading, horizontalSpacing: 14, verticalSpacing: 6) {
23 GridRow {
24 ForEach(view.specs.indices, id: \.self) { i in
25 Text(view.specs[i].title).bold().foregroundStyle(.secondary)
26 }
27 }
28 Divider()
29 ForEach(view.rows.indices, id: \.self) { r in
30 GridRow {
31 ForEach(view.specs.indices, id: \.self) { c in cellView(r, c) }
32 }
33 }
34 }
22 ColumnViewGrid(view: view, verticalSpacing: 6) { r, c in cellView(r, c) }
3523 .font(.system(.callout, design: .monospaced))
3624 .padding(12)
3725 }
Sources/OrgstarMobile/EmacsImportScreen.swift +3 −38
@@ -27,33 +27,8 @@ struct EmacsImportScreen: View {
2727 if let summary {
2828 Section { Text(summary) }
2929 } else if let result {
30 ForEach(groups(result), id: \.0) { title, items in
31 Section(title) {
32 ForEach(items) { item in
33 Toggle(isOn: Binding { selected.contains(item.id) } set: { on in
34 if on { selected.insert(item.id) } else { selected.remove(item.id) }
35 }) {
36 VStack(alignment: .leading, spacing: 1) {
37 Text(item.summary).font(.system(.callout, design: .monospaced))
38 Text([item.name == item.summary ? nil : item.name, item.source.isEmpty ? nil : item.source].compactMap { $0 }.joined(separator: " · "))
39 .font(.caption).foregroundStyle(.secondary)
40 }
41 }
42 }
43 }
44 }
45 let notes = result.unsupported.map { ($0.id, $0.name, $0.reason, $0.source) } + result.unreadable.map { ($0.id, $0.name, $0.reason, $0.source) }
46 if !notes.isEmpty || !result.problems.isEmpty {
47 Section("Not imported") {
48 ForEach(result.problems, id: \.self) { Text($0).foregroundStyle(.red) }
49 ForEach(notes, id: \.0) { note in
50 VStack(alignment: .leading, spacing: 1) {
51 Text(note.1).font(.system(.callout, design: .monospaced))
52 Text("\(note.2) · \(note.3)").font(.caption).foregroundStyle(.secondary)
53 }
54 }
55 }
56 }
30 EmacsImportSections(result: result, groups: result.groups(folders: false), selected: $selected,
31 font: .system(.callout, design: .monospaced))
5732 }
5833 }
5934 .navigationTitle("Import from Emacs")
@@ -67,23 +42,13 @@ struct EmacsImportScreen: View {
6742 }
6843 }
6944
70 private func groups(_ result: EmacsImport) -> [(String, [EmacsImport.Item])] {
71 [
72 ("Settings", result.items.filter { if case .setting = $0.change { true } else { false } }),
73 ("Capture templates", result.items.filter { if case .capture = $0.change { true } else { false } }),
74 ("Key bindings", result.items.filter { if case .binding = $0.change { true } else { false } }),
75 ("Structure templates", result.items.filter { if case .structureTemplate = $0.change { true } else { false } }),
76 ("Agenda views", result.items.filter { if case .view = $0.change { true } else { false } }),
77 ].filter { !$0.1.isEmpty }
78 }
79
8045 private func read(_ url: URL) {
8146 let accessing = url.startAccessingSecurityScopedResource()
8247 defer { if accessing { url.stopAccessingSecurityScopedResource() } }
8348 location = url
8449 let scanned = EmacsImport.scan(EmacsImport.files(in: url))
8550 result = scanned
86 selected = Set(groups(scanned).flatMap(\.1).map(\.id))
51 selected = Set(scanned.groups(folders: false).flatMap(\.1).map(\.id))
8752 summary = nil
8853 }
8954
Sources/OrgstarMobile/VersionScreens.swift −70
@@ -2,76 +2,6 @@
22import OrgApp
33import OrgDocument
44import SwiftUI
5import UIKit
6
7/// Lines removed and added between two versions, with a few lines of context around each change.
8struct DiffView: View {
9 let lines: [DiffLine]
10 var context = 3
11
12 init(old: String, new: String) {
13 lines = lineDiff(old: old, new: new)
14 }
15
16 /// Lines to show, nil standing for a run of unchanged lines left out.
17 private var shown: [DiffLine?] {
18 let changed = lines.indices.filter { lines[$0].kind != .same }
19 guard !changed.isEmpty else { return [] }
20 var keep = Set<Int>()
21 for i in changed { keep.formUnion(max(0, i - context)...min(lines.count - 1, i + context)) }
22 var out: [DiffLine?] = []
23 var skipped = false
24 for i in lines.indices {
25 if keep.contains(i) {
26 out.append(lines[i])
27 skipped = false
28 } else if !skipped {
29 out.append(nil)
30 skipped = true
31 }
32 }
33 return out
34 }
35
36 var body: some View {
37 let shown = shown
38 ScrollView([.vertical, .horizontal]) {
39 VStack(alignment: .leading, spacing: 0) {
40 if shown.isEmpty { Text("No differences").foregroundStyle(.secondary).padding(8) }
41 ForEach(shown.indices, id: \.self) { i in
42 if let line = shown[i] {
43 Text(prefix(line.kind) + line.text.trimmingCharacters(in: .newlines))
44 .frame(maxWidth: .infinity, alignment: .leading)
45 .background(background(line.kind))
46 } else {
47 Text("⋯").foregroundStyle(.secondary)
48 }
49 }
50 }
51 .font(.system(.footnote, design: .monospaced))
52 .textSelection(.enabled)
53 .padding(8)
54 }
55 .defaultScrollAnchor(.topLeading)
56 .background(Color(uiColor: .secondarySystemBackground))
57 }
58
59 private func prefix(_ kind: DiffLine.Kind) -> String {
60 switch kind {
61 case .same: " "
62 case .removed: "- "
63 case .added: "+ "
64 }
65 }
66
67 private func background(_ kind: DiffLine.Kind) -> Color {
68 switch kind {
69 case .same: .clear
70 case .removed: .red.opacity(0.18)
71 case .added: .green.opacity(0.18)
72 }
73 }
74}
755
766/// The buffer and the file on disk changed differently: what differs, and how to settle it.
777struct ConflictSheet: View {