Commit a79f5362fb

a79f5362fbc7c9473d040271cb3e718f88e5daf6

parent: d56fe8ddca

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-26 09:17 UTC

Share Subtree… on the Mac and iOS

The entry at the caret goes through the sharing services as an .org file
named after its heading, holding the file's keyword lines (without its
title and export name) and the entry as the file has it, promoted to
level 1, or as text. Include attachments adds the files in the
attachment folders of the entry and the entries under it as items of
their own. An encrypted entry stays encrypted. On the Mac, File ▸ Share
Subtree… opens a sheet whose Share… button shows NSSharingServicePicker;
on iOS, Share Subtree… in Commands opens a list of ShareLinks.

Closes #158

Layout: unified · split

Changed files (17)
Sources/OrgApp/CommandRanking.swift +1 −1 · view
@@ -93,7 +93,7 @@ public enum CommandGroups {
9393 /// The Org menu's groups and the app's commands outside the Org menu.
9494 public static let commandList: [Group] = orgMenu + [
9595 Group(title: String(localized: "Clock", comment: "Commands list section"), prefixes: ["app.clock."]),
96 Group(title: String(localized: "Export", comment: "Commands list section"), prefixes: ["app.export", "app.copy-rich-text", "app.publish"]),
96 Group(title: String(localized: "Export", comment: "Commands list section"), prefixes: ["app.export", "app.copy-rich-text", "app.publish", "app.share-subtree"]),
9797 Group(title: String(localized: "File", comment: "Commands list section"), prefixes: ["app.save", "app.word-count", "app.recovery", "app.sync-conflicts", "app.lint", "app.working-copy"]),
9898 Group(title: String(localized: "Edit", comment: "Commands list section"), prefixes: ["edit.", "macro."]),
9999 Group(title: String(localized: "View", comment: "Commands list section"), prefixes: ["app.toggle-markup", "editor.", "app.split-", "app.pane-"]),
Sources/OrgApp/CommandTitles.swift +1 · view
@@ -293,6 +293,7 @@ enum CommandTitles {
293293 String(localized: "Set Priority…", comment: "Command title"),
294294 String(localized: "Set Property…", comment: "Command title"),
295295 String(localized: "Set Tags", comment: "Command title"),
296 String(localized: "Share Subtree…", comment: "Command title"),
296297 String(localized: "Shift Timer Values in Region…", comment: "Command title"),
297298 String(localized: "Show Agenda or Files in Sidebar", comment: "Command title"),
298299 String(localized: "Show Attachment Folder", comment: "Command title"),
Sources/OrgApp/SubtreeShare.swift added +70 · view
@@ -0,0 +1,70 @@
1import Foundation
2import OrgCore
3
4/// Share Subtree…: the entry at the caret as an org file of its own or as text, with the files
5/// attached to it and to the entries under it. The entry is taken as the file holds it, so an
6/// encrypted entry is shared encrypted.
7public struct SubtreeShare: Sendable, Identifiable {
8 public let id = UUID()
9 /// The entry with the file's keyword lines, as `ExportScope.entry` gives it.
10 public let text: String
11 /// The `.org` file's name: the heading's title.
12 public let fileName: String
13 /// Files in the attachment folders of the entry and the entries under it.
14 public let attachments: [URL]
15
16 /// The entry at `offset` in `text`, the file at `path`; nil before the first heading.
17 /// `idDir` and `inherit` are `org-attach-id-dir` and `org-attach-use-inheritance`.
18 public init?(text: String, at offset: Int, path: String, settings: OrgSettings = .default,
19 idDir: String = OrgPreferences.attachIDDir(), inherit: Bool? = OrgPreferences.attachUseInheritance()) {
20 guard let entry = ExportScope.entry(text, at: offset, settings: settings) else { return nil }
21 self.text = entry.text
22 let tree = OrgParser.parse(text, defaults: settings)
23 let headings = DocumentModel(tree: tree).headings.filter { entry.range.contains($0.headingRange.lowerBound) }
24 fileName = Self.fileName(entry.title)
25 var folders: [String] = []
26 for heading in headings {
27 guard let dir = OrgAttach.directory(tree: tree, at: heading.headingRange.lowerBound, path: path, idDir: idDir, inherit: inherit, isDirectory: Attachments.isDirectory),
28 !folders.contains(dir) else { continue }
29 folders.append(dir)
30 }
31 // Files only: hidden files and folders inside stay behind.
32 attachments = folders.flatMap { dir in
33 Attachments.files(in: dir).filter { !$0.hasPrefix(".") }.map { URL(fileURLWithPath: dir).appendingPathComponent($0) }
34 .filter { !Attachments.isDirectory($0.path) }
35 }
36 }
37
38 /// `title` as a file name: characters other systems refuse replaced, at most 80 long, with
39 /// `.org`.
40 static func fileName(_ title: String) -> String {
41 var name = title.components(separatedBy: CharacterSet(charactersIn: "/\\:*?\"<>|").union(.newlines).union(.controlCharacters))
42 .joined(separator: "-").trimmingCharacters(in: .whitespaces)
43 while name.hasPrefix(".") { name.removeFirst() }
44 if name.count > 80 { name = String(name.prefix(80)).trimmingCharacters(in: .whitespaces) }
45 return (name.isEmpty ? "Subtree" : name) + ".org"
46 }
47
48 /// Writes the entry as `fileName` in a new temporary folder; its URL.
49 public func writeFile() throws -> URL {
50 let folder = FileManager.default.temporaryDirectory.appendingPathComponent("share-" + id.uuidString)
51 try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
52 let url = folder.appendingPathComponent(fileName)
53 try Data(text.utf8).write(to: url, options: .atomic)
54 return url
55 }
56
57 /// What the share sheet sends: the written file and, when asked, the attachments, each as
58 /// an item of its own.
59 public func files(file: URL, withAttachments: Bool) -> [URL] {
60 [file] + (withAttachments ? attachments : [])
61 }
62}
63
64extension DocumentSession {
65 /// Share Subtree… for the entry at `offset` in the open file at `path`.
66 public func subtreeShare(_ path: String, at offset: Int) -> SubtreeShare? {
67 guard let text = document(of: path)?.text else { return nil }
68 return SubtreeShare(text: text, at: offset, path: path, settings: defaults)
69 }
70}
Sources/OrgCore/Export/ExportScope.swift +24 · view
@@ -56,6 +56,30 @@ public enum ExportScope {
5656 return lines.joined(separator: "\n") + "\n" + body
5757 }
5858
59 /// Keywords of the file that name it or its export, left out of a shared entry.
60 static let fileOnlyKeywords: Set<String> = ["TITLE", "SUBTITLE", "EXPORT_FILE_NAME"]
61
62 /// The subtree containing `offset` as it is in the file, to share as an org file of its own:
63 /// the file's keyword lines (but its title and export name), then the heading and
64 /// everything under it, promoted so the heading is level 1. Its range in `text` and the
65 /// heading's title, links as their descriptions, come with it. Nil before the first heading.
66 public static func entry(_ text: String, at offset: Int, settings: OrgSettings = .default) -> (text: String, range: Range<Int>, title: String)? {
67 let tree = OrgParser.parse(text, defaults: settings)
68 let model = DocumentModel(tree: tree)
69 guard let index = model.headings.lastIndex(where: { $0.headingRange.lowerBound <= offset }) else { return nil }
70 let heading = model.headings[index]
71 let ns = text as NSString
72 let start = heading.headingRange.lowerBound
73 let end = model.headings[(index + 1)...].first { $0.level <= heading.level }?.headingRange.lowerBound ?? ns.length
74 let subtree = ExportPreprocess.shift(ns.substring(with: NSRange(location: start, length: end - start)), to: 1)
75 let lines = preamble(tree).filter { line in
76 guard let m = line.firstMatch(of: #/^#\+([^:\s]+):/#) else { return true }
77 return !fileOnlyKeywords.contains(m.1.uppercased())
78 }
79 let body = subtree.replacing(#/\s+$/#, with: "") + "\n"
80 return ((lines.isEmpty ? "" : lines.joined(separator: "\n") + "\n\n") + body, start..<end, Links.displayFormat(heading.title).trimmingCharacters(in: .whitespaces))
81 }
82
5983 /// The export's name: the subtree's `EXPORT_FILE_NAME` property when exporting the subtree
6084 /// at `offset`, else the file's last `#+EXPORT_FILE_NAME`; nil when neither is set.
6185 public static func fileName(_ text: String, subtreeAt offset: Int? = nil, settings: OrgSettings = .default) -> String? {
Sources/OrgEditorAppKit/EditorCommands.swift +1 · view
@@ -185,6 +185,7 @@ public enum EditorCommands {
185185 EditorCommand(id: "app.export-dialog", title: "Export…", action: .app),
186186 EditorCommand(id: "app.export-subtree", title: "Turn Subtree Export On or Off", action: .app),
187187 EditorCommand(id: "app.export-body-only", title: "Turn Body-Only Export On or Off", action: .app),
188 EditorCommand(id: "app.share-subtree", title: "Share Subtree…", action: .app),
188189 EditorCommand(id: "app.sync-conflicts", title: "Resolve Sync Conflicts…", action: .app),
189190 EditorCommand(id: "app.revert", title: "Revert to File on Disk", action: .app),
190191 EditorCommand(id: "app.recovery", title: "History…", action: .app),
Sources/Orgstar/ContentView.swift +7 −1 · view
@@ -993,6 +993,8 @@ struct ContentView: View {
993993 PlotSheet(content: .chart(plot))
994994 case .plotImage(_, let url):
995995 PlotSheet(content: .image(url))
996 case .shareSubtree(_, let share):
997 ShareSubtreeSheet(share: share) { commands.show($0) }
996998 case .crypt(_, let request):
997999 CryptSheet(request: request, text: { session.document?.text ?? "" }, apply: { applyText($0) }) { message in
9981000 self.panel = nil
@@ -1319,7 +1321,7 @@ struct ContentView: View {
13191321 return commands.show(Self.unavailable(EditorCommands.all.first { $0.id == id }?.title ?? id))
13201322 }
13211323 if let feature = ProFeature.required(byCommand: id), !ProAccess.shared.allows(feature) { return }
1322 let orgOnly = ["app.refile", "app.refile.copy", "app.archive", "app.clock.in", "app.clock.default", "app.copy-rich-text", "app.export-subtree", "app.export-body-only"].contains(id) || (id.hasPrefix("app.export.") && !id.hasPrefix("app.export.icalendar-")) || id.hasPrefix("org.")
1324 let orgOnly = ["app.refile", "app.refile.copy", "app.archive", "app.clock.in", "app.clock.default", "app.copy-rich-text", "app.export-subtree", "app.export-body-only", "app.share-subtree"].contains(id) || (id.hasPrefix("app.export.") && !id.hasPrefix("app.export.icalendar-")) || id.hasPrefix("org.")
13231325 if orgOnly, !session.isOrg {
13241326 commands.show(String(localized: "Not an org file"))
13251327 return
@@ -1520,6 +1522,10 @@ struct ContentView: View {
15201522 lintRun += 1
15211523 case "app.copy-rich-text":
15221524 copyRichText()
1525 case "app.share-subtree":
1526 guard let path = session.path else { return commands.show(String(localized: "No file is open")) }
1527 guard let share = session.subtreeShare(path, at: session.caret) else { return commands.show(String(localized: "Not in a subtree")) }
1528 panel = .shareSubtree(UUID(), share)
15231529 case "app.export-dialog":
15241530 guard let path = session.path else { return commands.show(String(localized: "No file is open")) }
15251531 panel = .export(UUID(), URL(fileURLWithPath: path))
Sources/Orgstar/OrgstarApp.swift +2 · view
@@ -541,6 +541,8 @@ struct OrgstarApp: App {
541541 }
542542 }
543543 .disabled(session.path == nil)
544 Button("Share Subtree…") { commands.run("app.share-subtree") }
545 .disabled(!session.isOrg)
544546 Menu("Publish") {
545547 ForEach(EditorCommands.all.filter { $0.id.hasPrefix("app.publish") }, id: \.id) { command in
546548 Button(command.localizedTitle) { commands.run(command.id) }
Sources/Orgstar/Panels.swift +2 −1 · view
@@ -12,10 +12,11 @@ enum Panel: Identifiable {
1212 case plot(UUID, TablePlot.Plot)
1313 case plotImage(UUID, URL)
1414 case crypt(UUID, CryptRequest)
15 case shareSubtree(UUID, SubtreeShare)
1516
1617 var id: UUID {
1718 switch self {
18 case .columns(let id, _), .export(let id, _), .conflict(let id), .syncCopies(let id), .recovery(let id), .plot(let id, _), .plotImage(let id, _), .crypt(let id, _): id
19 case .columns(let id, _), .export(let id, _), .conflict(let id), .syncCopies(let id), .recovery(let id), .plot(let id, _), .plotImage(let id, _), .crypt(let id, _), .shareSubtree(let id, _): id
1920 }
2021 }
2122}
Sources/Orgstar/ShareSubtreeSheet.swift added +94 · view
@@ -0,0 +1,94 @@
1import AppKit
2import OrgApp
3import SwiftUI
4
5/// Share Subtree…: the entry at the caret as an org file, with its attachments if chosen, or as
6/// text, through the sharing services (AirDrop, Mail, Messages).
7struct ShareSubtreeSheet: View {
8 let share: SubtreeShare
9 let report: (String) -> Void
10 @State private var asFile = true
11 @State private var withAttachments = false
12 @Environment(\.dismiss) private var dismiss
13
14 var body: some View {
15 VStack(alignment: .leading, spacing: 12) {
16 Text("Share Subtree").font(.headline)
17 Picker("Share as", selection: $asFile) {
18 Text("Org file (\(share.fileName))").tag(true)
19 Text("Text").tag(false)
20 }
21 .pickerStyle(.radioGroup)
22 if asFile, !share.attachments.isEmpty {
23 Toggle("Include \(share.attachments.count) attachments", isOn: $withAttachments)
24 }
25 HStack {
26 Spacer()
27 Button("Cancel") { dismiss() }.keyboardShortcut(.cancelAction)
28 SharingButton(title: String(localized: "Share…"), items: items) { dismiss() }
29 .fixedSize()
30 }
31 }
32 .padding(20)
33 .frame(width: 380)
34 }
35
36 /// The text, or the written file and the attachments chosen.
37 private func items() -> [Any] {
38 guard asFile else { return [share.text] }
39 do {
40 return share.files(file: try share.writeFile(), withAttachments: withAttachments)
41 } catch {
42 report(String(localized: "Can't share \(share.fileName): \(error.localizedDescription)"))
43 return []
44 }
45 }
46}
47
48/// A button that opens the sharing services picker under itself with `items`; `chose` runs once
49/// a service is chosen.
50struct SharingButton: NSViewRepresentable {
51 let title: String
52 let items: () -> [Any]
53 let chose: () -> Void
54
55 func makeCoordinator() -> Coordinator { Coordinator(self) }
56
57 func makeNSView(context: Context) -> NSButton {
58 let button = NSButton(title: title, target: context.coordinator, action: #selector(Coordinator.click(_:)))
59 button.bezelStyle = .push
60 button.keyEquivalent = "\r"
61 return button
62 }
63
64 func updateNSView(_ button: NSButton, context: Context) {
65 context.coordinator.parent = self
66 button.title = title
67 }
68
69 @MainActor
70 final class Coordinator: NSObject, NSSharingServicePickerDelegate, NSSharingServiceDelegate {
71 var parent: SharingButton
72
73 init(_ parent: SharingButton) {
74 self.parent = parent
75 }
76
77 @objc func click(_ sender: NSButton) {
78 let items = parent.items()
79 guard !items.isEmpty else { return }
80 let picker = NSSharingServicePicker(items: items)
81 picker.delegate = self
82 picker.show(relativeTo: sender.bounds, of: sender, preferredEdge: .minY)
83 }
84
85 /// The sheet stays while a service such as AirDrop shows its own sheet on it.
86 nonisolated func sharingServicePicker(_ picker: NSSharingServicePicker, delegateFor sharingService: NSSharingService) -> (any NSSharingServiceDelegate)? {
87 self
88 }
89
90 nonisolated func sharingService(_ sharingService: NSSharingService, didShareItems items: [Any]) {
91 MainActor.assumeIsolated { parent.chose() }
92 }
93 }
94}
Sources/OrgstarMobile/EditorScreen.swift +12 −1 · view
@@ -95,6 +95,7 @@ struct EditorScreen: View {
9595 /// Rename Tag or Rename TODO Keyword, starting from this name.
9696 case rename(ReplaceKind, String)
9797 case lint
98 case shareSubtree(SubtreeShare)
9899 /// The subtree at this offset, to export.
99100 case exportSubtree(Int)
100101
@@ -114,6 +115,7 @@ struct EditorScreen: View {
114115 case .graph: "graph"
115116 case .rename(let kind, _): kind.rawValue
116117 case .lint: "lint"
118 case .shareSubtree(let share): share.id.uuidString
117119 case .exportSubtree: "exportSubtree"
118120 }
119121 }
@@ -247,6 +249,8 @@ struct EditorScreen: View {
247249 RenameScreen(kind: kind, workspace: workspace, session: session, initial: initial) { message = $0 }
248250 case .lint:
249251 LintScreen(workspace: workspace, session: session, path: path) { offset in editor?.reveal(offset) }
252 case .shareSubtree(let share):
253 SubtreeShareScreen(share: share) { message = $0 }
250254 }
251255 }
252256 .fileImporter(isPresented: $importingTable, allowedContentTypes: [.commaSeparatedText, .tabSeparatedText, .plainText]) { result in
@@ -474,6 +478,12 @@ struct EditorScreen: View {
474478 sheet = .export
475479 } else if id == EditorScreen.exportSubtreeCommand {
476480 exportSubtree()
481 } else if id == "app.share-subtree" {
482 if let caret = self.editor?.editContext().caret, let share = session.subtreeShare(path, at: caret) {
483 sheet = .shareSubtree(share)
484 } else {
485 message = String(localized: "Not in a subtree")
486 }
477487 } else if id == "app.export.html-open" {
478488 exportHTMLAndOpen()
479489 } else if id == "app.export-body-only" {
@@ -1057,6 +1067,7 @@ struct CommandPalette: View {
10571067 ("app.clock.default", "Mark as Default Clock Task"), ("app.clock.resolve", "Resolve Open Clocks…"),
10581068 ("app.refile", "Refile…"), ("app.refile.copy", "Copy to Refile Target…"), ("app.refile.goto", "Go to Refile Target…"),
10591069 ("app.archive", "Archive Subtree"), ("app.export-dialog", "Export…"), ("app.export-subtree-dialog", "Export Subtree…"),
1070 ("app.share-subtree", "Share Subtree…"),
10601071 ("app.copy-rich-text", "Copy as Rich Text"), ("app.export.html-open", "Export to HTML and Open"),
10611072 ("app.export-body-only", "Turn Body-Only Export On or Off"),
10621073 ("app.export.icalendar-agenda", "Export Agenda Files to iCalendar"), ("app.export.icalendar-combined", "Combine Agenda Files into iCalendar"),
@@ -1151,7 +1162,7 @@ struct CommandPalette: View {
11511162 switch id {
11521163 case "app.recovery": return recoveries > 0 ? nil : String(localized: "No Recovery Versions")
11531164 case "app.sync-conflicts": return syncCopies > 0 ? nil : String(localized: "No sync conflict copies", comment: "Why Resolve Sync Conflicts… is greyed in the Commands list")
1154 case EditorScreen.exportSubtreeCommand:
1165 case EditorScreen.exportSubtreeCommand, "app.share-subtree":
11551166 return ExportScope.subtree(context.text, at: context.caret) != nil ? nil : String(localized: "Not in a subtree", comment: "Why Export Subtree… is greyed in the Commands list")
11561167 default: return editor.applies(id, in: context) ? nil : CommandReason.reason(for: id, in: context)
11571168 }
Sources/OrgstarMobile/ExportMenu.swift +45 · view
@@ -338,4 +338,49 @@ struct SubtreeExportScreen: View {
338338 }
339339 }
340340}
341
342/// Share Subtree…: the entry at the caret as an org file, with its attachments as separate items
343/// if chosen, or as text.
344struct SubtreeShareScreen: View {
345 let share: SubtreeShare
346 var report: (String) -> Void = { _ in }
347 @State private var file: URL?
348 @State private var withAttachments = false
349 @Environment(\.dismiss) private var dismiss
350
351 var body: some View {
352 NavigationStack {
353 List {
354 Section {
355 if let file {
356 ShareLink(items: share.files(file: file, withAttachments: withAttachments)) {
357 Label("Share as Org File", systemImage: "doc")
358 }
359 }
360 if !share.attachments.isEmpty {
361 Toggle("Include \(share.attachments.count) attachments", isOn: $withAttachments)
362 }
363 } footer: {
364 Text(verbatim: share.fileName)
365 }
366 Section {
367 ShareLink(item: share.text, preview: SharePreview(share.fileName)) {
368 Label("Share as Text", systemImage: "text.alignleft")
369 }
370 }
371 }
372 .navigationTitle("Share Subtree")
373 .navigationBarTitleDisplayMode(.inline)
374 .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } }
375 .onAppear {
376 guard file == nil else { return }
377 do {
378 file = try share.writeFile()
379 } catch {
380 report(String(localized: "Can't share \(share.fileName): \(error.localizedDescription)"))
381 }
382 }
383 }
384 }
385}
341386#endif
Sources/OrgstarMobile/MobileEditor.swift +1 −1 · view
@@ -511,7 +511,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
511511 "app.rename-tag", "app.rename-todo-keyword": return onAppCommand != nil
512512 case _ where id.hasPrefix(NamedMacros.commandPrefix): return true
513513 case "app.refile", "app.refile.copy", "app.archive": return onAppCommand != nil && Presentation.heading(containing: context.caret, in: context.tree) != nil
514 case "app.export-dialog", "app.export-subtree-dialog", "app.copy-rich-text", "app.export.html-open", "app.export-body-only", "app.export.icalendar-agenda", "app.export.icalendar-combined": return onAppCommand != nil
514 case "app.export-dialog", "app.export-subtree-dialog", "app.share-subtree", "app.copy-rich-text", "app.export.html-open", "app.export-body-only", "app.export.icalendar-agenda", "app.export.icalendar-combined": return onAppCommand != nil
515515 case _ where id.hasPrefix("app.publish"): return onAppCommand != nil
516516 case "app.working-copy.sync": return onAppCommand != nil
517517 case _ where Self.linkCommands.contains(id): return onAppCommand != nil
Tests/OrgAppTests/SubtreeShareTests.swift added +92 · view
@@ -0,0 +1,92 @@
1import Foundation
2import OrgCore
3import Testing
4@testable import OrgApp
5
6struct SubtreeShareTests {
7 static let text = """
8 #+TITLE: Notes
9 #+TODO: TODO WAIT | DONE
10 #+STARTUP: overview
11
12 * Other
13 ** TODO Trip to [[https://example.com][Lisbon]]: plans :travel:
14 SCHEDULED: <2026-12-01 Tue>
15 :PROPERTIES:
16 :DIR: trip
17 :END:
18 Flights.
19 *** Hotel
20 :PROPERTIES:
21 :DIR: hotel
22 :END:
23 Booked.
24 *** Secret :crypt:
25 -----BEGIN PGP MESSAGE-----
26
27 jA0ECQMC
28 -----END PGP MESSAGE-----
29
30
31 ** Next
32 """
33
34 @Test func theEntryIsSharedAsTheFileHoldsItPromoted() throws {
35 let caret = (Self.text as NSString).range(of: "Flights").location
36 let share = try #require(SubtreeShare(text: Self.text, at: caret, path: "/nowhere/notes.org", idDir: "data/", inherit: nil))
37 #expect(share.text == """
38 #+TODO: TODO WAIT | DONE
39 #+STARTUP: overview
40
41 * TODO Trip to [[https://example.com][Lisbon]]: plans :travel:
42 SCHEDULED: <2026-12-01 Tue>
43 :PROPERTIES:
44 :DIR: trip
45 :END:
46 Flights.
47 ** Hotel
48 :PROPERTIES:
49 :DIR: hotel
50 :END:
51 Booked.
52 ** Secret :crypt:
53 -----BEGIN PGP MESSAGE-----
54
55 jA0ECQMC
56 -----END PGP MESSAGE-----
57
58 """)
59 #expect(share.fileName == "Trip to Lisbon- plans.org")
60 #expect(share.attachments.isEmpty)
61 #expect(SubtreeShare(text: Self.text, at: 3, path: "/nowhere/notes.org") == nil)
62 }
63
64 @Test func attachmentsOfTheEntryAndItsChildrenComeAsFiles() throws {
65 let folder = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
66 defer { try? FileManager.default.removeItem(at: folder) }
67 let files = FileManager.default
68 for dir in ["trip", "hotel", "trip/inside", "elsewhere"] { try files.createDirectory(at: folder.appendingPathComponent(dir), withIntermediateDirectories: true) }
69 for file in ["trip/ticket.pdf", "trip/.DS_Store", "hotel/booking.png", "elsewhere/no.txt"] { try Data("x".utf8).write(to: folder.appendingPathComponent(file)) }
70 let path = folder.appendingPathComponent("notes.org").path
71 let caret = (Self.text as NSString).range(of: "Flights").location
72 let share = try #require(SubtreeShare(text: Self.text, at: caret, path: path, idDir: "data/", inherit: nil))
73 #expect(share.attachments.map(\.lastPathComponent) == ["ticket.pdf", "booking.png"])
74 // Only the child's own folder for the child.
75 let child = try #require(SubtreeShare(text: Self.text, at: (Self.text as NSString).range(of: "Booked").location, path: path, idDir: "data/", inherit: nil))
76 #expect(child.attachments.map(\.lastPathComponent) == ["booking.png"])
77
78 let file = try share.writeFile()
79 defer { try? files.removeItem(at: file.deletingLastPathComponent()) }
80 #expect(file.lastPathComponent == "Trip to Lisbon- plans.org")
81 #expect(try String(contentsOf: file, encoding: .utf8) == share.text)
82 #expect(share.files(file: file, withAttachments: false) == [file])
83 #expect(share.files(file: file, withAttachments: true).map(\.lastPathComponent) == ["Trip to Lisbon- plans.org", "ticket.pdf", "booking.png"])
84 }
85
86 @Test func fileNamesAreSafe() {
87 #expect(SubtreeShare.fileName("a/b: c?") == "a-b- c-.org")
88 #expect(SubtreeShare.fileName(" ") == "Subtree.org")
89 #expect(SubtreeShare.fileName("..hidden") == "hidden.org")
90 #expect(SubtreeShare.fileName(String(repeating: "x", count: 100)).count == 84)
91 }
92}
docs/manual/guide/01-files-and-folders.org +11 · view
@@ -345,6 +345,17 @@ The other device looks for the file in its own added folders. A folder in iCloud
345345
346346Only files in an added folder are offered, and never an encrypted =.org.gpg= file. On iPhone and iPad, the editor offers its file; the reader and the agenda don't.
347347
348* Sharing a subtree
349
350File ▸ Share Subtree… (also in the command palette, and in Commands on iPhone and iPad, under Export) sends the entry at the caret through AirDrop, Mail, Messages or another app:
351
352- Org file :: the entry as an =.org= file named after its heading. The file holds the keyword lines at the top of your file (such as =#+TODO= and =#+STARTUP=, but not =#+TITLE=) and the entry with everything under it, as it is in the file, promoted so the entry is a level-1 heading.
353- Text :: the same text, for an app that takes text.
354
355When the entry or an entry under it has attachments, Include attachments sends each attached file as an item of its own beside the =.org= file. =attachment:= links in the shared file don't reach them on the other side, since the attachment folder isn't sent.
356
357An encrypted entry (=:crypt:=) is shared as the file holds it, still encrypted.
358
348359* Encodings and line endings
349360
350361orgstar edits UTF-8 files, with or without a byte order mark.
docs/manual/guide/03-keys.org +1 · view
@@ -1200,6 +1200,7 @@ No preset binds these. Run them from the palette or a menu, or bind them in =key
12001200| History… (=app.recovery=) | Shows the file's recovery versions and, in the download version, its git commits. Recovery Versions… on iOS. |
12011201| Lint File (=app.lint=) | Lists the problems in the file in a panel under the editor (=org-lint=). File ▸ Lint File. See [[file:02-the-editor.org][The editor]]. |
12021202| Resolve Sync Conflicts… (=app.sync-conflicts=) | Shows the file's sync conflict copies to resolve them. |
1203| Share Subtree… (=app.share-subtree=) | Shares the entry at the caret as an org file, with its attachments if chosen, or as text. File ▸ Share Subtree…. See [[file:01-files-and-folders.org][Files and folders]]. |
12031204| Import Table from File… (=app.table-import=) | Asks for a CSV, TSV or space-separated file and inserts it as a table (=org-table-import=). |
12041205| Export Table to File… (=app.table-export=) | Writes the table at point to a CSV or TSV file (=org-table-export=). |
12051206| Plot Table (=app.plot=) | Plots the table at point as its =#+PLOT:= lines say (=org-plot/gnuplot=, =C-c " g= in the Emacs and Doom presets). |
docs/manual/guide/14-ios.org +2 · view
@@ -411,6 +411,8 @@ PDF export follows =pdf-margin=, =pdf-font= and =pdf-page-numbers= in =config.to
411411
412412Body Only in the Export menu leaves out the title and the page around the text in HTML, Markdown, LaTeX and Plain Text (ASCII), and is kept for each file; the other formats say they have no body-only export while it is on. Export Subtree…, in the editor's Commands and its Export menu on iPad, shares the subtree at the caret in any of the formats.
413413
414Share Subtree…, in the editor's Commands under Export, shares the entry at the caret as it is in the file: Share as Org File sends an =.org= file named after its heading, with Include attachments sending the entry's attached files beside it, and Share as Text sends the text. See [[file:01-files-and-folders.org][Files and folders]], Sharing a subtree.
415
414416The Export menu also has Export Agenda Files to iCalendar, which writes an =.ics= beside each agenda file, and Combine Agenda Files into iCalendar, which shares one calendar of them all. Commands has these, Copy as Rich Text, and Export to HTML and Open, which shows the HTML export in Quick Look. Without orgstar+, the Export menu's items that need it end in "(orgstar+)" and open the orgstar+ screen.
415417
416418Publishing works from Commands as on the Mac, with the =[[publish]]= projects in =config.toml=. A project that publishes outside your folders asks for a folder the first time, and uses it from then on. See [[file:12-export.org][Export]].
l10n/Localizable.xcstrings +373 · view
@@ -7878,6 +7878,40 @@
78787878 }
78797879 }
78807880 },
7881 "Can't share %@: %@": {
7882 "localizations": {
7883 "de": {
7884 "stringUnit": {
7885 "state": "translated",
7886 "value": "%1$@ kann nicht geteilt werden: %2$@"
7887 }
7888 },
7889 "es": {
7890 "stringUnit": {
7891 "state": "translated",
7892 "value": "No se puede compartir %1$@: %2$@"
7893 }
7894 },
7895 "fr": {
7896 "stringUnit": {
7897 "state": "translated",
7898 "value": "Impossible de partager %1$@ : %2$@"
7899 }
7900 },
7901 "ja": {
7902 "stringUnit": {
7903 "state": "translated",
7904 "value": "%1$@を共有できません:%2$@"
7905 }
7906 },
7907 "pt-BR": {
7908 "stringUnit": {
7909 "state": "translated",
7910 "value": "Não é possível compartilhar %1$@: %2$@"
7911 }
7912 }
7913 }
7914 },
78817915 "Can't write %@: %@": {
78827916 "comment": "Echo area: file name, then the reason",
78837917 "localizations": {
@@ -20356,6 +20390,106 @@
2035620390 }
2035720391 }
2035820392 },
20393 "Include %lld attachments": {
20394 "localizations": {
20395 "de": {
20396 "variations": {
20397 "plural": {
20398 "one": {
20399 "stringUnit": {
20400 "state": "translated",
20401 "value": "%lld Anhang mitsenden"
20402 }
20403 },
20404 "other": {
20405 "stringUnit": {
20406 "state": "translated",
20407 "value": "%lld Anhänge mitsenden"
20408 }
20409 }
20410 }
20411 }
20412 },
20413 "en": {
20414 "variations": {
20415 "plural": {
20416 "one": {
20417 "stringUnit": {
20418 "state": "translated",
20419 "value": "Include %lld attachment"
20420 }
20421 },
20422 "other": {
20423 "stringUnit": {
20424 "state": "translated",
20425 "value": "Include %lld attachments"
20426 }
20427 }
20428 }
20429 }
20430 },
20431 "es": {
20432 "variations": {
20433 "plural": {
20434 "one": {
20435 "stringUnit": {
20436 "state": "translated",
20437 "value": "Incluir %lld adjunto"
20438 }
20439 },
20440 "other": {
20441 "stringUnit": {
20442 "state": "translated",
20443 "value": "Incluir %lld adjuntos"
20444 }
20445 }
20446 }
20447 }
20448 },
20449 "fr": {
20450 "variations": {
20451 "plural": {
20452 "one": {
20453 "stringUnit": {
20454 "state": "translated",
20455 "value": "Inclure %lld pièce jointe"
20456 }
20457 },
20458 "other": {
20459 "stringUnit": {
20460 "state": "translated",
20461 "value": "Inclure %lld pièces jointes"
20462 }
20463 }
20464 }
20465 }
20466 },
20467 "ja": {
20468 "stringUnit": {
20469 "state": "translated",
20470 "value": "添付ファイル%lld個を含める"
20471 }
20472 },
20473 "pt-BR": {
20474 "variations": {
20475 "plural": {
20476 "one": {
20477 "stringUnit": {
20478 "state": "translated",
20479 "value": "Incluir %lld anexo"
20480 }
20481 },
20482 "other": {
20483 "stringUnit": {
20484 "state": "translated",
20485 "value": "Incluir %lld anexos"
20486 }
20487 }
20488 }
20489 }
20490 }
20491 }
20492 },
2035920493 "Include files in subfolders": {
2036020494 "localizations": {
2036120495 "de": {
@@ -30453,6 +30587,40 @@
3045330587 }
3045430588 }
3045530589 },
30590 "Org file (%@)": {
30591 "localizations": {
30592 "de": {
30593 "stringUnit": {
30594 "state": "translated",
30595 "value": "Org-Datei (%@)"
30596 }
30597 },
30598 "es": {
30599 "stringUnit": {
30600 "state": "translated",
30601 "value": "Archivo Org (%@)"
30602 }
30603 },
30604 "fr": {
30605 "stringUnit": {
30606 "state": "translated",
30607 "value": "Fichier Org (%@)"
30608 }
30609 },
30610 "ja": {
30611 "stringUnit": {
30612 "state": "translated",
30613 "value": "Orgファイル(%@)"
30614 }
30615 },
30616 "pt-BR": {
30617 "stringUnit": {
30618 "state": "translated",
30619 "value": "Arquivo Org (%@)"
30620 }
30621 }
30622 }
30623 },
3045630624 "Org's date syntax works too: +2d, fri, 14:00": {
3045730625 "localizations": {
3045830626 "de": {
@@ -38026,6 +38194,211 @@
3802638194 }
3802738195 }
3802838196 },
38197 "Share Subtree": {
38198 "localizations": {
38199 "de": {
38200 "stringUnit": {
38201 "state": "translated",
38202 "value": "Teilbaum teilen"
38203 }
38204 },
38205 "es": {
38206 "stringUnit": {
38207 "state": "translated",
38208 "value": "Compartir subárbol"
38209 }
38210 },
38211 "fr": {
38212 "stringUnit": {
38213 "state": "translated",
38214 "value": "Partager le sous-arbre"
38215 }
38216 },
38217 "ja": {
38218 "stringUnit": {
38219 "state": "translated",
38220 "value": "サブツリーを共有"
38221 }
38222 },
38223 "pt-BR": {
38224 "stringUnit": {
38225 "state": "translated",
38226 "value": "Compartilhar Subárvore"
38227 }
38228 }
38229 }
38230 },
38231 "Share Subtree…": {
38232 "comment": "Command title",
38233 "localizations": {
38234 "de": {
38235 "stringUnit": {
38236 "state": "translated",
38237 "value": "Teilbaum teilen …"
38238 }
38239 },
38240 "es": {
38241 "stringUnit": {
38242 "state": "translated",
38243 "value": "Compartir subárbol…"
38244 }
38245 },
38246 "fr": {
38247 "stringUnit": {
38248 "state": "translated",
38249 "value": "Partager le sous-arbre…"
38250 }
38251 },
38252 "ja": {
38253 "stringUnit": {
38254 "state": "translated",
38255 "value": "サブツリーを共有…"
38256 }
38257 },
38258 "pt-BR": {
38259 "stringUnit": {
38260 "state": "translated",
38261 "value": "Compartilhar Subárvore…"
38262 }
38263 }
38264 }
38265 },
38266 "Share as": {
38267 "localizations": {
38268 "de": {
38269 "stringUnit": {
38270 "state": "translated",
38271 "value": "Teilen als"
38272 }
38273 },
38274 "es": {
38275 "stringUnit": {
38276 "state": "translated",
38277 "value": "Compartir como"
38278 }
38279 },
38280 "fr": {
38281 "stringUnit": {
38282 "state": "translated",
38283 "value": "Partager en tant que"
38284 }
38285 },
38286 "ja": {
38287 "stringUnit": {
38288 "state": "translated",
38289 "value": "共有形式"
38290 }
38291 },
38292 "pt-BR": {
38293 "stringUnit": {
38294 "state": "translated",
38295 "value": "Compartilhar como"
38296 }
38297 }
38298 }
38299 },
38300 "Share as Org File": {
38301 "localizations": {
38302 "de": {
38303 "stringUnit": {
38304 "state": "translated",
38305 "value": "Als Org-Datei teilen"
38306 }
38307 },
38308 "es": {
38309 "stringUnit": {
38310 "state": "translated",
38311 "value": "Compartir como archivo Org"
38312 }
38313 },
38314 "fr": {
38315 "stringUnit": {
38316 "state": "translated",
38317 "value": "Partager en fichier Org"
38318 }
38319 },
38320 "ja": {
38321 "stringUnit": {
38322 "state": "translated",
38323 "value": "Orgファイルとして共有"
38324 }
38325 },
38326 "pt-BR": {
38327 "stringUnit": {
38328 "state": "translated",
38329 "value": "Compartilhar como Arquivo Org"
38330 }
38331 }
38332 }
38333 },
38334 "Share as Text": {
38335 "localizations": {
38336 "de": {
38337 "stringUnit": {
38338 "state": "translated",
38339 "value": "Als Text teilen"
38340 }
38341 },
38342 "es": {
38343 "stringUnit": {
38344 "state": "translated",
38345 "value": "Compartir como texto"
38346 }
38347 },
38348 "fr": {
38349 "stringUnit": {
38350 "state": "translated",
38351 "value": "Partager en texte"
38352 }
38353 },
38354 "ja": {
38355 "stringUnit": {
38356 "state": "translated",
38357 "value": "テキストとして共有"
38358 }
38359 },
38360 "pt-BR": {
38361 "stringUnit": {
38362 "state": "translated",
38363 "value": "Compartilhar como Texto"
38364 }
38365 }
38366 }
38367 },
38368 "Share…": {
38369 "localizations": {
38370 "de": {
38371 "stringUnit": {
38372 "state": "translated",
38373 "value": "Teilen …"
38374 }
38375 },
38376 "es": {
38377 "stringUnit": {
38378 "state": "translated",
38379 "value": "Compartir…"
38380 }
38381 },
38382 "fr": {
38383 "stringUnit": {
38384 "state": "translated",
38385 "value": "Partager…"
38386 }
38387 },
38388 "ja": {
38389 "stringUnit": {
38390 "state": "translated",
38391 "value": "共有…"
38392 }
38393 },
38394 "pt-BR": {
38395 "stringUnit": {
38396 "state": "translated",
38397 "value": "Compartilhar…"
38398 }
38399 }
38400 }
38401 },
3802938402 "Shift Timer Values in Region…": {
3803038403 "comment": "Command title",
3803138404 "localizations": {
Keyboard shortcuts

Global

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

Repository & editor

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