Doom preset: the missing evil commands !453
24 files changed, +967 −29
Layout: unified · split
Sources/OrgApp/CommandTitles.swift +5
| @@ -38,6 +38,7 @@ enum CommandTitles { | ||
| 38 | 38 | String(localized: "Clock Report", comment: "Command title"), |
| 39 | 39 | String(localized: "Clone Subtree with Time Shift", comment: "Command title"), |
| 40 | 40 | String(localized: "Close All Buffers", comment: "Command title"), |
| 41 | String(localized: "Close All Folds", comment: "Command title"), | |
| 41 | 42 | String(localized: "Close Buffer", comment: "Command title"), |
| 42 | 43 | String(localized: "Close Fold", comment: "Command title"), |
| 43 | 44 | String(localized: "Close Other Buffers", comment: "Command title"), |
| @@ -120,6 +121,7 @@ enum CommandTitles { | ||
| 120 | 121 | String(localized: "Go to Today's Daily Note", comment: "Command title"), |
| 121 | 122 | String(localized: "Go to Tomorrow's Daily Note", comment: "Command title"), |
| 122 | 123 | String(localized: "Go to Yesterday's Daily Note", comment: "Command title"), |
| 124 | String(localized: "Hide Next Fold Level", comment: "Command title"), | |
| 123 | 125 | String(localized: "Import Table from File…", comment: "Command title"), |
| 124 | 126 | String(localized: "Import from Emacs…", comment: "Command title"), |
| 125 | 127 | String(localized: "Increase Timestamp Part", comment: "Command title"), |
| @@ -197,9 +199,11 @@ enum CommandTitles { | ||
| 197 | 199 | String(localized: "Next Table Field", comment: "Command title"), |
| 198 | 200 | String(localized: "Next Table Row", comment: "Command title"), |
| 199 | 201 | String(localized: "Next table.el Cell", comment: "Command title"), |
| 202 | String(localized: "Open All Folds", comment: "Command title"), | |
| 200 | 203 | String(localized: "Open Attachment…", comment: "Command title"), |
| 201 | 204 | String(localized: "Open Fold", comment: "Command title"), |
| 202 | 205 | String(localized: "Open Link", comment: "Command title"), |
| 206 | String(localized: "Open Subtree Folds", comment: "Command title"), | |
| 203 | 207 | String(localized: "Outdent Item", comment: "Command title"), |
| 204 | 208 | String(localized: "Outdent Item and Children", comment: "Command title"), |
| 205 | 209 | String(localized: "Paste Subtree", comment: "Command title"), |
| @@ -273,6 +277,7 @@ enum CommandTitles { | ||
| 273 | 277 | String(localized: "Show Agenda or Files in Sidebar", comment: "Command title"), |
| 274 | 278 | String(localized: "Show Attachment Folder", comment: "Command title"), |
| 275 | 279 | String(localized: "Show Backlinks", comment: "Command title"), |
| 280 | String(localized: "Show Next Fold Level", comment: "Command title"), | |
| 276 | 281 | String(localized: "Show Node Graph", comment: "Command title"), |
| 277 | 282 | String(localized: "Show Remaining Countdown Time", comment: "Command title"), |
| 278 | 283 | String(localized: "Show or Hide Backlinks", comment: "Command title"), |
Sources/OrgCore/Keymap/PresetDoom.swift +24
| @@ -574,6 +574,30 @@ extension KeymapPreset { | ||
| 574 | 574 | command = "org.cycle-global" |
| 575 | 575 | mode = "normal" |
| 576 | 576 | [[bind]] |
| 577 | keys = "z C" | |
| 578 | command = "org.fold.close" | |
| 579 | mode = "normal" | |
| 580 | [[bind]] | |
| 581 | keys = "z O" | |
| 582 | command = "org.fold.open-subtree" | |
| 583 | mode = "normal" | |
| 584 | [[bind]] | |
| 585 | keys = "z R" | |
| 586 | command = "org.fold.open-all" | |
| 587 | mode = "normal" | |
| 588 | [[bind]] | |
| 589 | keys = "z M" | |
| 590 | command = "org.fold.close-all" | |
| 591 | mode = "normal" | |
| 592 | [[bind]] | |
| 593 | keys = "z r" | |
| 594 | command = "org.fold.more" | |
| 595 | mode = "normal" | |
| 596 | [[bind]] | |
| 597 | keys = "z m" | |
| 598 | command = "org.fold.less" | |
| 599 | mode = "normal" | |
| 600 | [[bind]] | |
| 577 | 601 | keys = "g h" |
| 578 | 602 | command = "org.heading.up" |
| 579 | 603 | mode = "normal" |
Sources/OrgCore/Keymap/Vim.swift +27 −3
| @@ -56,6 +56,11 @@ public struct Vim: Sendable { | ||
| 56 | 56 | case visualLines(Int) |
| 57 | 57 | /// `zz`, `zt`, `zb`: scroll the caret's line to the window's middle, top or bottom. |
| 58 | 58 | case scroll(ScrollLine) |
| 59 | /// C-e and C-y: scroll the window down (or, negative, up) by lines. | |
| 60 | case scrollLines(Int) | |
| 61 | /// `zl`, `zh`: scroll the window right (or, negative, left) by columns; `zL` and `zH` | |
| 62 | /// with `halfWidths`, by half the window's width. | |
| 63 | case scrollColumns(Int, halfWidths: Bool) | |
| 59 | 64 | /// `q:`, `q/`, `q?`: the command-line window, the earlier commands or searches to pick |
| 60 | 65 | /// from and edit. |
| 61 | 66 | case commandWindow(String) |
| @@ -73,9 +78,16 @@ public struct Vim: Sendable { | ||
| 73 | 78 | public var visible: Range<Int>? |
| 74 | 79 | /// An Org buffer, where evil-org's keys apply. |
| 75 | 80 | public var org: Bool |
| 81 | /// The file's path, for the `%` register. | |
| 82 | public var fileName: String? | |
| 83 | /// The last ex command, for the `:` register. | |
| 84 | public var lastEx: String? | |
| 76 | 85 | |
| 77 | public init(text: String, caret: Int, clipboard: String? = nil, halfPage: Int = 15, marks: [Character: Int] = [:], visible: Range<Int>? = nil, org: Bool = false) { | |
| 86 | public init(text: String, caret: Int, clipboard: String? = nil, halfPage: Int = 15, marks: [Character: Int] = [:], visible: Range<Int>? = nil, org: Bool = false, | |
| 87 | fileName: String? = nil, lastEx: String? = nil) { | |
| 78 | 88 | self.org = org |
| 89 | self.fileName = fileName | |
| 90 | self.lastEx = lastEx | |
| 79 | 91 | self.text = text |
| 80 | 92 | self.caret = caret |
| 81 | 93 | self.clipboard = clipboard |
| @@ -131,6 +143,13 @@ public struct Vim: Sendable { | ||
| 131 | 143 | var replaceStack: [(offset: Int, original: String?, length: Int)] = [] |
| 132 | 144 | var replaceTyped = "" |
| 133 | 145 | var replaceCount = 1 |
| 146 | /// What the last insert state typed, for the `.` register. | |
| 147 | var lastInsertion: String? | |
| 148 | /// The buffer's edits, oldest first, for `g;` and `g,`. | |
| 149 | var changeLog: [Change] = [] | |
| 150 | /// How far back `g;` has gone; 0 after any other command. | |
| 151 | var changeDepth = 0 | |
| 152 | var steppingChanges = false | |
| 134 | 153 | |
| 135 | 154 | public init() {} |
| 136 | 155 | |
| @@ -164,6 +183,8 @@ public struct Vim: Sendable { | ||
| 164 | 183 | return [] |
| 165 | 184 | case .done(let actions): |
| 166 | 185 | pending = [] |
| 186 | if !steppingChanges { changeDepth = 0 } | |
| 187 | steppingChanges = false | |
| 167 | 188 | return actions |
| 168 | 189 | } |
| 169 | 190 | } |
| @@ -189,11 +210,14 @@ public struct Vim: Sendable { | ||
| 189 | 210 | } |
| 190 | 211 | let caret = context.caret |
| 191 | 212 | let lineStart = buffer.lineStart(caret) |
| 213 | if !insertedText.isEmpty { lastInsertion = insertedText } | |
| 214 | // The `^` mark, where `gi` resumes. | |
| 215 | marks["^"] = caret | |
| 192 | 216 | if let block = blockInsert { |
| 193 | 217 | blockInsert = nil |
| 194 | if !insertedText.isEmpty, !insertedText.contains("\n") { return replicateBlockInsert(block, buffer, caret: caret) } | |
| 218 | if !insertedText.isEmpty, !insertedText.contains("\n") { return [.setMark("^", caret)] + replicateBlockInsert(block, buffer, caret: caret) } | |
| 195 | 219 | } |
| 196 | return [.move(caret: caret > lineStart ? caret - 1 : caret)] | |
| 220 | return [.setMark("^", caret), .move(caret: caret > lineStart ? caret - 1 : caret)] | |
| 197 | 221 | } |
| 198 | 222 | if key == KeyChord("w", .control) { |
| 199 | 223 | let start = buffer.wordBackward(context.caret, bigWord: false, stopAtLine: true) |
Sources/OrgCore/Keymap/VimApply.swift +17 −5
| @@ -32,11 +32,22 @@ extension Vim { | ||
| 32 | 32 | return [] |
| 33 | 33 | } |
| 34 | 34 | if yank { registers["0"] = (text, linewise) } |
| 35 | if !yank, register == nil, !text.contains("\n") { registers["-"] = (text, linewise) } | |
| 36 | // Evil reads `1` to `9` from the kill ring: `1` is the latest kill. | |
| 37 | for digit in (2...9).reversed() { registers[Character("\(digit)")] = registers[Character("\(digit - 1)")] } | |
| 38 | registers["1"] = (text, linewise) | |
| 35 | 39 | clipboardRecord = (text, linewise) |
| 36 | 40 | return [.setClipboard(text)] |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | 43 | func paste(_ register: Character?, _ context: Context) -> (String, Bool)? { |
| 44 | switch register { | |
| 45 | case ".": return lastInsertion.map { ($0, false) } | |
| 46 | case ":": return context.lastEx.map { ($0, false) } | |
| 47 | case "%": return context.fileName.map { ($0, false) } | |
| 48 | case "/": return lastSearch.map { ($0.pattern, false) } | |
| 49 | default: break | |
| 50 | } | |
| 40 | 51 | if let register, register != "\"", register != "+", register != "*" { |
| 41 | 52 | return registers[Character(register.lowercased())] |
| 42 | 53 | } |
| @@ -170,7 +181,8 @@ extension Vim { | ||
| 170 | 181 | } |
| 171 | 182 | } |
| 172 | 183 | |
| 173 | mutating func join(_ buffer: Buffer, at caret: Int, lines: Int, keys: [KeyChord]) -> [Action] { | |
| 184 | /// `J`, or without `spaces` `gJ`, which removes the line breaks and nothing else. | |
| 185 | mutating func join(_ buffer: Buffer, at caret: Int, lines: Int, keys: [KeyChord], spaces: Bool = true) -> [Action] { | |
| 174 | 186 | var edits: [TextEdit] = [] |
| 175 | 187 | var line = buffer.lineStart(caret) |
| 176 | 188 | var position = caret |
| @@ -178,11 +190,11 @@ extension Vim { | ||
| 178 | 190 | let end = buffer.lineEnd(line) |
| 179 | 191 | guard end < buffer.length else { break } |
| 180 | 192 | let nextStart = end + 1 |
| 181 | let nextText = buffer.firstNonBlankOrEnd(nextStart) | |
| 193 | let nextText = spaces ? buffer.firstNonBlankOrEnd(nextStart) : nextStart | |
| 182 | 194 | let joinsEmpty = buffer.lineEnd(nextStart) == nextText |
| 183 | let separator = joinsEmpty || buffer.char(nextText) == 41 ? "" : (end > line && buffer.char(end - 1) == 32 ? "" : " ") | |
| 195 | let separator = !spaces || joinsEmpty || buffer.char(nextText) == 41 ? "" : (end > line && buffer.char(end - 1) == 32 ? "" : " ") | |
| 184 | 196 | var from = end |
| 185 | while from > line, let c = buffer.char(from - 1), c == 32 || c == 9 { from -= 1 } | |
| 197 | while spaces, from > line, let c = buffer.char(from - 1), c == 32 || c == 9 { from -= 1 } | |
| 186 | 198 | if !separator.isEmpty || from == end { from = end } |
| 187 | 199 | edits.append(TextEdit(range: from..<nextText, replacement: separator)) |
| 188 | 200 | position = from |
| @@ -192,7 +204,7 @@ extension Vim { | ||
| 192 | 204 | lastChange = (keys, nil) |
| 193 | 205 | // Positions in edits refer to the original text; apply back to front. |
| 194 | 206 | let shift = edits.dropLast().reduce(0) { $0 + $1.replacement.utf16.count - $1.range.count } |
| 195 | return [.edit(edits, caret: position + shift)] | |
| 207 | return [.edit(edits, caret: spaces ? position + shift : buffer.applying(edits).clampNormal(position + shift))] | |
| 196 | 208 | } |
| 197 | 209 | |
| 198 | 210 | mutating func repeatChange(_ count: Int, _ context: Context) -> [Action] { |
Sources/OrgCore/Keymap/VimExtras.swift +1 −1
| @@ -11,7 +11,7 @@ extension Vim { | ||
| 11 | 11 | /// Motions evil records in the jump list. |
| 12 | 12 | static func isJump(_ keys: [KeyChord]) -> Bool { |
| 13 | 13 | guard let key = keys.first, key.modifiers.isEmpty else { return false } |
| 14 | if ["G", "%", "{", "}", "n", "N", "*", "#", "'", "`", "H", "M", "L", "s", "S", "f", "F", "t", "T"].contains(key.key) { return true } | |
| 14 | if ["G", "%", "{", "}", "(", ")", "n", "N", "*", "#", "'", "`", "H", "M", "L", "s", "S", "f", "F", "t", "T"].contains(key.key) { return true } | |
| 15 | 15 | return key.key == "g" && keys.count > 1 && keys[1].key == "g" |
| 16 | 16 | } |
| 17 | 17 | |
Sources/OrgCore/Keymap/VimMore.swift +85 −2
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import Foundation |
| 2 | 2 | |
| 3 | // Scrolling the caret's line (`zz`, `zt`, `zb`), numbers (`C-a`, and Doom's evil-numbers keys | |
| 4 | // `g=` and `g-`), replace state (`R`) and the command-line window (`q:`). | |
| 3 | // Scrolling (`zz`, `zt`, `zb`, C-e, C-y, `zh`, `zl`), `gi`, `gJ`, the change list (`g;`, `g,`), | |
| 4 | // numbers (`C-a`, and Doom's evil-numbers keys `g=` and `g-`), replace state (`R`) and the | |
| 5 | // command-line window (`q:`). | |
| 5 | 6 | |
| 6 | 7 | extension Vim { |
| 7 | 8 | /// Where `zz`, `zt` and `zb` put the caret's line in the window. |
| @@ -18,13 +19,21 @@ extension Vim { | ||
| 18 | 19 | if first == KeyChord("a", .control) { |
| 19 | 20 | return .done(visual ? incrementVisual(buffer, caret, by: n, incremental: false) : increment(buffer, caret, by: n, keys: keys)) |
| 20 | 21 | } |
| 22 | if first == KeyChord("e", .control) { return .done([.scrollLines(n)]) } | |
| 23 | if first == KeyChord("y", .control) { return .done([.scrollLines(-n)]) } | |
| 21 | 24 | guard first.modifiers.isEmpty else { return nil } |
| 22 | 25 | switch first.key { |
| 26 | case "&" where !visual: | |
| 27 | return .done([.ex("&")]) | |
| 23 | 28 | case "z" where !visual: |
| 24 | 29 | guard let second else { return .incomplete } |
| 25 | 30 | guard second.modifiers.isEmpty else { return nil } |
| 26 | 31 | let place: ScrollLine |
| 27 | 32 | switch second.key { |
| 33 | case "l": return .done([.scrollColumns(n, halfWidths: false)]) | |
| 34 | case "h": return .done([.scrollColumns(-n, halfWidths: false)]) | |
| 35 | case "L": return .done([.scrollColumns(n, halfWidths: true)]) | |
| 36 | case "H": return .done([.scrollColumns(-n, halfWidths: true)]) | |
| 28 | 37 | case "z", ".": place = .center |
| 29 | 38 | case "t", "RET": place = .top |
| 30 | 39 | case "b", "-": place = .bottom |
| @@ -48,6 +57,23 @@ extension Vim { | ||
| 48 | 57 | case ("=", true): return .done(incrementVisual(buffer, caret, by: n, incremental: true)) |
| 49 | 58 | case ("-", true): return .done(incrementVisual(buffer, caret, by: -n, incremental: true)) |
| 50 | 59 | case ("+", true): return .done(incrementVisual(buffer, caret, by: n, incremental: false)) |
| 60 | case ("J", false): return .done(join(buffer, at: caret, lines: max(2, n), keys: keys, spaces: false)) | |
| 61 | case ("J", true): | |
| 62 | let range = visualRange(buffer, caret) | |
| 63 | lastVisual = (anchor, caret, mode) | |
| 64 | mode = .normal | |
| 65 | return .done(join(buffer, at: range.range.lowerBound, lines: max(2, buffer.lineCount(range.range)), keys: keys, spaces: false)) | |
| 66 | case ("i", false): | |
| 67 | // `evil-insert-resume`: insert state at the `^` mark. | |
| 68 | let at = min(currentMarks["^"] ?? caret, buffer.length) | |
| 69 | enterInsert(at: at, keys: keys) | |
| 70 | return .done((at == caret ? [] : [.jumped(from: caret)]) + [.move(caret: at)]) | |
| 71 | case (";", false), (",", false): | |
| 72 | steppingChanges = true | |
| 73 | guard let target = stepChange(older: second.key == ";") else { return .done([]) } | |
| 74 | let to = buffer.clampNormal(min(target, buffer.length)) | |
| 75 | return .done((to == caret ? [] : [.jumped(from: caret)]) + [.move(caret: to)]) | |
| 76 | case ("&", false): return .done([.ex("%&&")]) | |
| 51 | 77 | default: return nil |
| 52 | 78 | } |
| 53 | 79 | case "R" where !visual: |
| @@ -66,6 +92,63 @@ extension Vim { | ||
| 66 | 92 | } |
| 67 | 93 | } |
| 68 | 94 | |
| 95 | // MARK: - The change list | |
| 96 | ||
| 97 | /// An edit as goto-chg reads it from the undo list: text between `lower` and `upper` went, | |
| 98 | /// or `delta` characters came in at `lower`; `position` is where `g;` goes for it. | |
| 99 | struct Change { | |
| 100 | var lower: Int | |
| 101 | var upper: Int | |
| 102 | var delta: Int | |
| 103 | var position: Int | |
| 104 | } | |
| 105 | ||
| 106 | /// goto-chg's `glc-default-span`: changes this close to a later one are passed over. | |
| 107 | static let changeSpan = 8 | |
| 108 | ||
| 109 | /// An edit the editor made to the buffer, by any means, for `g;` to find. | |
| 110 | public mutating func changed(_ edit: TextEdit) { | |
| 111 | changeDepth = 0 | |
| 112 | let at = edit.range.lowerBound | |
| 113 | if !edit.range.isEmpty { changeLog.append(Change(lower: at, upper: edit.range.upperBound, delta: -edit.range.count, position: at)) } | |
| 114 | let length = edit.replacement.utf16.count | |
| 115 | if length > 0 { | |
| 116 | // Text typed on from the last insertion is one change, as in the undo list. | |
| 117 | if let last = changeLog.last, last.delta > 0, last.position == at { | |
| 118 | changeLog[changeLog.count - 1] = Change(lower: last.lower, upper: last.lower, delta: last.delta + length, position: at + length) | |
| 119 | } else { | |
| 120 | changeLog.append(Change(lower: at, upper: at, delta: length, position: at + length)) | |
| 121 | } | |
| 122 | } | |
| 123 | if changeLog.count > 200 { changeLog.removeFirst(changeLog.count - 200) } | |
| 124 | } | |
| 125 | ||
| 126 | /// `goto-last-change` and its reverse: the next older (or newer) change's place now, or | |
| 127 | /// nil when there is none. A change within `changeSpan` of a later one is skipped. | |
| 128 | mutating func stepChange(older: Bool) -> Int? { | |
| 129 | var depth = changeDepth | |
| 130 | while true { | |
| 131 | depth += older ? 1 : -1 | |
| 132 | guard depth >= 1, depth <= changeLog.count else { return nil } | |
| 133 | let index = changeLog.count - depth | |
| 134 | var position: Int? = changeLog[index].position | |
| 135 | for later in changeLog[(index + 1)...] { | |
| 136 | guard let p = position else { break } | |
| 137 | if p <= later.lower - Self.changeSpan { | |
| 138 | position = p | |
| 139 | } else if p > later.upper + Self.changeSpan { | |
| 140 | position = p + later.delta | |
| 141 | } else { | |
| 142 | position = nil | |
| 143 | } | |
| 144 | } | |
| 145 | if let position { | |
| 146 | changeDepth = depth | |
| 147 | return position | |
| 148 | } | |
| 149 | } | |
| 150 | } | |
| 151 | ||
| 69 | 152 | // MARK: - Numbers |
| 70 | 153 | |
| 71 | 154 | /// The numbers of a line, as Vim reads them with `nrformats` `bin,hex`. |
Sources/OrgCore/Keymap/VimMotions.swift +18
| @@ -142,6 +142,18 @@ extension Vim { | ||
| 142 | 142 | var p = c |
| 143 | 143 | for _ in 0..<n { p = buffer.paragraph(p, forward: key.key == "}") } |
| 144 | 144 | return .moved(p, .exclusive) |
| 145 | case (")", []), ("(", []): | |
| 146 | goalColumn = nil | |
| 147 | var p = c | |
| 148 | for _ in 0..<n { p = buffer.sentence(p, forward: key.key == ")", org: contextOrg) } | |
| 149 | guard p != c else { return .invalid } | |
| 150 | // Evil's exclusive motion that ends at a line's start stops at the end of the line | |
| 151 | // before, and from the line's indentation takes whole lines. | |
| 152 | if operatorPending, p > c, p == buffer.lineStart(p), p > 0, buffer.char(p - 1) == 10 { | |
| 153 | if c <= buffer.firstNonBlankOrEnd(buffer.lineStart(c)) { return .moved(p - 1, .linewise) } | |
| 154 | return .moved(p - 1, .exclusive) | |
| 155 | } | |
| 156 | return .moved(p, .exclusive) | |
| 145 | 157 | case ("n", []), ("N", []): |
| 146 | 158 | guard let search = lastSearch else { return .invalid } |
| 147 | 159 | let forward = key.key == "n" ? search.forward : !search.forward |
| @@ -258,6 +270,12 @@ extension Vim { | ||
| 258 | 270 | return buffer.bracketObject(c, open: 60, close: 62, inner: inner).map { ($0, false) } |
| 259 | 271 | case "p": |
| 260 | 272 | return buffer.paragraphObject(c, inner: inner).map { ($0, true) } |
| 273 | case "s": | |
| 274 | return buffer.sentenceObject(c, inner: inner, count: count, org: contextOrg).map { ($0, false) } | |
| 275 | case "t": | |
| 276 | return buffer.tagObject(c, inner: inner, count: count).map { range in | |
| 277 | !inner && buffer.coversLines(range) ? (range.lowerBound..<min(buffer.length, range.upperBound + 1), true) : (range, false) | |
| 278 | } | |
| 261 | 279 | case "e", "E", "r", "R": |
| 262 | 280 | return Self.orgObject(key.key, inner: inner, buffer, c) |
| 263 | 281 | default: |
Sources/OrgCore/Keymap/VimObjects.swift added +149
| @@ -0,0 +1,149 @@ | ||
| 1 | import Foundation | |
| 2 | ||
| 3 | // Sentences (`(`, `)`, `is`, `as`) and XML tags (`it`, `at`). | |
| 4 | ||
| 5 | extension Vim.Buffer { | |
| 6 | /// `sentence-end` with Doom's `sentence-end-double-space` off, and the blanks after it. | |
| 7 | private static let sentenceEnd = try! NSRegularExpression(pattern: "[.?!…‽][\\]\"'”’)}»›]*(?:$|[ \\t])[ \\t\\n]*", options: .anchorsMatchLines) | |
| 8 | private static let orgParagraphStart = try! NSRegularExpression(pattern: "^(?:\\*+ |[ \\t]*(?:[-+]|[0-9]+[.)])(?: |$)|[ \\t]+\\* )") | |
| 9 | ||
| 10 | private func isBlankLine(_ line: Int) -> Bool { | |
| 11 | (line..<lineEnd(line)).allSatisfy { Self.isBlank(char($0)!) } | |
| 12 | } | |
| 13 | ||
| 14 | /// Each line's start. | |
| 15 | private var lineStarts: [Int] { | |
| 16 | var lines = [0] | |
| 17 | var p = 0 | |
| 18 | while p < length { | |
| 19 | if char(p) == 10, p + 1 < length { lines.append(p + 1) } | |
| 20 | p += 1 | |
| 21 | } | |
| 22 | return lines | |
| 23 | } | |
| 24 | ||
| 25 | /// Where sentences begin, in order: after a sentence's end and at the start of a | |
| 26 | /// paragraph's text. Blank lines separate paragraphs; in Org, headings and list items | |
| 27 | /// start one too. | |
| 28 | func sentenceStarts(org: Bool) -> [Int] { | |
| 29 | var all: Set<Int> = [] | |
| 30 | var previousSeparates = true | |
| 31 | for line in lineStarts { | |
| 32 | let text = substring(line..<lineEnd(line)) | |
| 33 | let special = org && Self.orgParagraphStart.firstMatch(in: text, range: NSRange(location: 0, length: (text as NSString).length)) != nil | |
| 34 | if isBlankLine(line) { | |
| 35 | previousSeparates = true | |
| 36 | continue | |
| 37 | } | |
| 38 | if previousSeparates || special { all.insert(firstNonBlankOrEnd(line)) } | |
| 39 | previousSeparates = org && text.hasPrefix("*") && special | |
| 40 | } | |
| 41 | for match in Self.sentenceEnd.matches(in: ns as String, range: NSRange(location: 0, length: length)) where NSMaxRange(match.range) < length { | |
| 42 | all.insert(NSMaxRange(match.range)) | |
| 43 | } | |
| 44 | return all.sorted() | |
| 45 | } | |
| 46 | ||
| 47 | /// `)` and `(`: the next sentence's beginning or the blank line after the paragraph; the | |
| 48 | /// previous sentence's beginning or the blank line before the paragraph. | |
| 49 | func sentence(_ c: Int, forward: Bool, org: Bool) -> Int { | |
| 50 | let starts = sentenceStarts(org: org) | |
| 51 | let lines = lineStarts | |
| 52 | if forward { | |
| 53 | var target = starts.first { $0 > c } ?? length | |
| 54 | for (i, line) in lines.enumerated() where line > c && line < target && i > 0 && isBlankLine(line) && !isBlankLine(lines[i - 1]) { | |
| 55 | target = line | |
| 56 | break | |
| 57 | } | |
| 58 | return target | |
| 59 | } | |
| 60 | var target = starts.last { $0 < c } ?? 0 | |
| 61 | for (i, line) in lines.enumerated().reversed() where line < c && line > target && i + 1 < lines.count && isBlankLine(line) && !isBlankLine(lines[i + 1]) { | |
| 62 | target = line | |
| 63 | break | |
| 64 | } | |
| 65 | return target | |
| 66 | } | |
| 67 | ||
| 68 | /// `is` and `as`: sentences and the blanks between them count alike for `is`; `as` takes a | |
| 69 | /// sentence with the blanks after it on its line, or else the blanks before it on its | |
| 70 | /// line, and on blanks takes them with the sentence after. | |
| 71 | func sentenceObject(_ c: Int, inner: Bool, count: Int, org: Bool) -> Range<Int>? { | |
| 72 | let starts = sentenceStarts(org: org) | |
| 73 | guard c < length, !starts.isEmpty else { return nil } | |
| 74 | // Each sentence's text, without the blanks after it. | |
| 75 | var sentences: [Range<Int>] = [] | |
| 76 | for (i, start) in starts.enumerated() { | |
| 77 | var end = i + 1 < starts.count ? starts[i + 1] : length | |
| 78 | while end > start, let ch = char(end - 1), Self.isSpace(ch) { end -= 1 } | |
| 79 | sentences.append(start..<end) | |
| 80 | } | |
| 81 | let n = max(1, count) | |
| 82 | let index = sentences.firstIndex { $0.contains(c) } | |
| 83 | if inner { | |
| 84 | // Sentences and gaps in order. | |
| 85 | var bounds = [0] | |
| 86 | for s in sentences { bounds += [s.lowerBound, s.upperBound] } | |
| 87 | bounds.append(length) | |
| 88 | let segments = zip(bounds, bounds.dropFirst()).filter { $0 < $1 }.map { $0..<$1 } | |
| 89 | guard let first = segments.firstIndex(where: { $0.contains(c) }) else { return nil } | |
| 90 | return segments[first].lowerBound..<segments[min(segments.count - 1, first + n - 1)].upperBound | |
| 91 | } | |
| 92 | func nextStart(_ i: Int) -> Int { i + 1 < sentences.count ? sentences[i + 1].lowerBound : length } | |
| 93 | var lower: Int | |
| 94 | var last: Int | |
| 95 | // Whether the range ends with the blanks after `last`. | |
| 96 | var blanksAfter = false | |
| 97 | if let index { | |
| 98 | last = index | |
| 99 | lower = sentences[index].lowerBound | |
| 100 | let end = sentences[index].upperBound | |
| 101 | let before = max(index > 0 ? sentences[index - 1].upperBound : 0, lineStart(lower)) | |
| 102 | if min(nextStart(index), lineEnd(end)) > end { | |
| 103 | blanksAfter = true | |
| 104 | if n == 1 { return lower..<min(nextStart(index), lineEnd(end)) } | |
| 105 | } else if before < lower { | |
| 106 | lower = before | |
| 107 | } | |
| 108 | } else { | |
| 109 | guard let next = sentences.firstIndex(where: { $0.lowerBound > c }) else { return nil } | |
| 110 | lower = next > 0 ? sentences[next - 1].upperBound : 0 | |
| 111 | last = next | |
| 112 | } | |
| 113 | for _ in 1..<n where last + 1 < sentences.count { | |
| 114 | last += 1 | |
| 115 | if blanksAfter { blanksAfter = nextStart(last) > sentences[last].upperBound } | |
| 116 | } | |
| 117 | return lower..<(blanksAfter ? nextStart(last) : sentences[last].upperBound) | |
| 118 | } | |
| 119 | ||
| 120 | private static let tag = try! NSRegularExpression(pattern: "<(/?)([^\\s<>/]+)(?:\\s[^<>]*?)?(/?)>") | |
| 121 | ||
| 122 | /// `it` and `at`: the `count`th pair of XML tags around `c`, a tag itself counting as inside | |
| 123 | /// its pair; `inner` is the text between them. | |
| 124 | func tagObject(_ c: Int, inner: Bool, count: Int) -> Range<Int>? { | |
| 125 | var open: [(name: String, range: NSRange)] = [] | |
| 126 | var pairs: [(open: NSRange, close: NSRange)] = [] | |
| 127 | for match in Self.tag.matches(in: ns as String, range: NSRange(location: 0, length: length)) { | |
| 128 | guard match.range(at: 3).length == 0 else { continue } | |
| 129 | let name = ns.substring(with: match.range(at: 2)) | |
| 130 | if match.range(at: 1).length == 0 { | |
| 131 | open.append((name, match.range)) | |
| 132 | } else if let i = open.lastIndex(where: { $0.name == name }) { | |
| 133 | pairs.append((open[i].range, match.range)) | |
| 134 | open.removeSubrange(i...) | |
| 135 | } | |
| 136 | } | |
| 137 | // Innermost first. | |
| 138 | let around = pairs.filter { $0.open.location <= c && c < NSMaxRange($0.close) }.sorted { $0.open.location > $1.open.location } | |
| 139 | guard around.count >= max(1, count) else { return nil } | |
| 140 | let pair = around[max(1, count) - 1] | |
| 141 | return inner ? NSMaxRange(pair.open)..<pair.close.location : pair.open.location..<NSMaxRange(pair.close) | |
| 142 | } | |
| 143 | ||
| 144 | /// Whether `range` is every character of two or more lines, which makes `at` take the lines. | |
| 145 | func coversLines(_ range: Range<Int>) -> Bool { | |
| 146 | range.lowerBound == lineStart(range.lowerBound) && range.upperBound == lineEnd(range.upperBound) | |
| 147 | && lineStart(range.upperBound) > range.lowerBound | |
| 148 | } | |
| 149 | } | |
Sources/OrgEditorAppKit/EditorCommands.swift +5
| @@ -43,6 +43,11 @@ public enum EditorCommands { | ||
| 43 | 43 | EditorCommand(id: "org.fold.toggle", title: "Toggle Fold", action: .view), |
| 44 | 44 | EditorCommand(id: "org.fold.open", title: "Open Fold", action: .view), |
| 45 | 45 | EditorCommand(id: "org.fold.close", title: "Close Fold", action: .view), |
| 46 | EditorCommand(id: "org.fold.open-subtree", title: "Open Subtree Folds", action: .view), | |
| 47 | EditorCommand(id: "org.fold.open-all", title: "Open All Folds", action: .view), | |
| 48 | EditorCommand(id: "org.fold.close-all", title: "Close All Folds", action: .view), | |
| 49 | EditorCommand(id: "org.fold.more", title: "Show Next Fold Level", action: .view), | |
| 50 | EditorCommand(id: "org.fold.less", title: "Hide Next Fold Level", action: .view), | |
| 46 | 51 | EditorCommand(id: "org.narrow.subtree", title: "Narrow to Subtree", action: .view), |
| 47 | 52 | EditorCommand(id: "org.narrow.block", title: "Narrow to Block", action: .view), |
| 48 | 53 | EditorCommand(id: "org.widen", title: "Widen", action: .view), |
Sources/OrgEditorAppKit/Modal.swift +39 −1
| @@ -106,7 +106,8 @@ extension OrgEditor { | ||
| 106 | 106 | if jumpIndex > 0, jumpIndex <= jumpList.count { marks["'"] = jumpList[jumpIndex - 1] } |
| 107 | 107 | vim.registers = Self.vimRegisters |
| 108 | 108 | vim.clipboardRecord = Self.vimClipboardRecord |
| 109 | let actions = vim.feed(key, Vim.Context(text: document.text, caret: caret, clipboard: clipboard, halfPage: halfPage, marks: marks, visible: visibleText, org: isOrg)) | |
| 109 | let actions = vim.feed(key, Vim.Context(text: document.text, caret: caret, clipboard: clipboard, halfPage: halfPage, marks: marks, visible: visibleText, org: isOrg, | |
| 110 | fileName: fileName, lastEx: Self.promptHistory[":"]?.last)) | |
| 110 | 111 | Self.vimRegisters = vim.registers |
| 111 | 112 | Self.vimClipboardRecord = vim.clipboardRecord |
| 112 | 113 | apply(actions) |
| @@ -289,6 +290,10 @@ extension OrgEditor { | ||
| 289 | 290 | textView.setSelectedRanges(ranges.map { NSValue(range: NSRange($0)) }, affinity: .downstream, stillSelecting: false) |
| 290 | 291 | case .scroll(let place): |
| 291 | 292 | scrollCaretLine(place) |
| 293 | case .scrollLines(let count): | |
| 294 | scrollLines(count) | |
| 295 | case .scrollColumns(let count, let halfWidths): | |
| 296 | scrollColumns(count, halfWidths: halfWidths) | |
| 292 | 297 | case .commandWindow(let kind): |
| 293 | 298 | prompt(kind, history: true) |
| 294 | 299 | } |
| @@ -328,6 +333,34 @@ extension OrgEditor { | ||
| 328 | 333 | scroll.reflectScrolledClipView(scroll.contentView) |
| 329 | 334 | } |
| 330 | 335 | |
| 336 | /// C-e and C-y: the window down or up by lines; the cursor stays in it, as in Emacs. | |
| 337 | private func scrollLines(_ count: Int) { | |
| 338 | guard let scroll = textView.enclosingScrollView, let font = textView.font else { return } | |
| 339 | let lineHeight = max(1, font.ascender - font.descender + font.leading) | |
| 340 | let bounds = scroll.contentView.bounds | |
| 341 | let maxY = max(0, textView.frame.height - bounds.height) | |
| 342 | scroll.contentView.scroll(to: NSPoint(x: bounds.origin.x, y: min(max(0, bounds.origin.y + CGFloat(count) * lineHeight), maxY))) | |
| 343 | scroll.reflectScrolledClipView(scroll.contentView) | |
| 344 | guard vim.mode == .normal, let visible = visibleText, !visible.isEmpty else { return } | |
| 345 | let caret = textView.selectedRange().location | |
| 346 | if caret < visible.lowerBound { | |
| 347 | setCaret(visible.lowerBound) | |
| 348 | } else if caret >= visible.upperBound { | |
| 349 | setCaret((document.text as NSString).lineRange(for: NSRange(location: visible.upperBound - 1, length: 0)).location) | |
| 350 | } | |
| 351 | } | |
| 352 | ||
| 353 | /// `zl`, `zh`, `zL` and `zH`: the window right or left by columns or half its width, which | |
| 354 | /// moves nothing while lines wrap. | |
| 355 | private func scrollColumns(_ count: Int, halfWidths: Bool) { | |
| 356 | guard let scroll = textView.enclosingScrollView, let font = textView.font else { return } | |
| 357 | let bounds = scroll.contentView.bounds | |
| 358 | let step = halfWidths ? bounds.width / 2 : (" " as NSString).size(withAttributes: [.font: font]).width | |
| 359 | let maxX = max(0, textView.frame.width - bounds.width) | |
| 360 | scroll.contentView.scroll(to: NSPoint(x: min(max(0, bounds.origin.x + CGFloat(count) * step), maxX), y: bounds.origin.y)) | |
| 361 | scroll.reflectScrolledClipView(scroll.contentView) | |
| 362 | } | |
| 363 | ||
| 331 | 364 | /// `/`, `?` and `:` read their argument in the echo area; `history` (`q:`) offers the |
| 332 | 365 | /// earlier ones to pick and edit. |
| 333 | 366 | private func prompt(_ kind: String, history: Bool = false) { |
| @@ -372,6 +405,10 @@ extension OrgEditor { | ||
| 372 | 405 | onAppCommand?("app.save") |
| 373 | 406 | textView.window?.performClose(nil) |
| 374 | 407 | case "noh", "nohlsearch": break |
| 408 | case "s", "&", "&&", "%&&": | |
| 409 | // The last substitution again; `&&` keeps its flags. | |
| 410 | guard let last = Self.lastSubstitute else { return } | |
| 411 | substitute(whole: trimmed.hasPrefix("%"), pattern: last.pattern, replacement: last.replacement, flags: trimmed.hasSuffix("&&") ? last.flags : "") | |
| 375 | 412 | default: |
| 376 | 413 | if let line = Int(trimmed) { |
| 377 | 414 | let ns = document.text as NSString |
| @@ -386,6 +423,7 @@ extension OrgEditor { | ||
| 386 | 423 | return |
| 387 | 424 | } |
| 388 | 425 | if let m = trimmed.firstMatch(of: /^(%?)s\/((?:[^\/\\]|\\.)*)\/((?:[^\/\\]|\\.)*)\/?([gi]*)$/) { |
| 426 | Self.lastSubstitute = (String(m.2), String(m.3), String(m.4)) | |
| 389 | 427 | substitute(whole: !m.1.isEmpty, pattern: String(m.2), replacement: String(m.3), flags: String(m.4)) |
| 390 | 428 | return |
| 391 | 429 | } |
Sources/OrgEditorAppKit/OrgEditor+Shrink.swift +11 −3
| @@ -80,15 +80,23 @@ extension OrgEditor { | ||
| 80 | 80 | return true |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | /// Doom's `za`, `zo` (on a heading line) and `zc` (anywhere in a subtree). | |
| 83 | /// Doom's `za`, `zo` (on a heading line), `zc` and `zO` (anywhere in a subtree), and `zR`, | |
| 84 | /// `zM`, `zr` and `zm` for the whole buffer. | |
| 84 | 85 | func fold(_ id: String) { |
| 85 | 86 | leaveSparseTree() |
| 86 | 87 | let caret = textView.selectedRange().location |
| 87 | 88 | let tree = document.tree |
| 88 | 89 | let next: FoldState? |
| 89 | if id == "org.fold.close" { | |
| 90 | if id == "org.fold.close" || id == "org.fold.open-subtree" { | |
| 90 | 91 | next = Presentation.outline(tree).last { $0.start <= caret && (caret < $0.end || $0.end == utf16Length) } |
| 91 | .map { Presentation.hideSubtree($0.start, foldState) } | |
| 92 | .map { id == "org.fold.close" ? Presentation.hideSubtree($0.start, foldState) : Presentation.showSubtree($0.start, in: tree, foldState) } | |
| 93 | } else if id == "org.fold.open-all" { | |
| 94 | next = Presentation.showAllHeadings(foldState) | |
| 95 | } else if id == "org.fold.close-all" { | |
| 96 | next = Presentation.hideSublevels(1, in: tree, foldState) | |
| 97 | } else if id == "org.fold.more" || id == "org.fold.less" { | |
| 98 | let level = Presentation.foldLevel(in: tree, foldState) | |
| 99 | next = Presentation.hideSublevels(id == "org.fold.more" ? level + 1 : max(1, level - 1), in: tree, foldState) | |
| 92 | 100 | } else { |
| 93 | 101 | next = Presentation.heading(containing: caret, in: tree).map { |
| 94 | 102 | id == "org.fold.open" ? Presentation.openFold($0, in: tree, foldState) : Presentation.toggleFold($0, in: tree, foldState) |
Sources/OrgEditorAppKit/OrgEditor.swift +6 −1
| @@ -441,6 +441,10 @@ public final class OrgEditor: NSObject { | ||
| 441 | 441 | static var macros: [Character: [KeyChord]] = [:] |
| 442 | 442 | /// What `:`, `/` and `?` read, oldest first, for the command-line window (`q:`). |
| 443 | 443 | static var promptHistory: [String: [String]] = [:] |
| 444 | /// The last `:s`, for `&` and `g&`. | |
| 445 | static var lastSubstitute: (pattern: String, replacement: String, flags: String)? | |
| 446 | /// The file's path, for the `%` register. | |
| 447 | public var fileName: String? | |
| 444 | 448 | /// Shows `editor`'s buffer with the caret at the offset, for a jump to a file mark set |
| 445 | 449 | /// there. |
| 446 | 450 | public var onJumpToEditor: ((OrgEditor, Int) -> Void)? |
| @@ -576,7 +580,7 @@ public final class OrgEditor: NSObject { | ||
| 576 | 580 | switch id { |
| 577 | 581 | case "org.cycle": cycleAtCaret() |
| 578 | 582 | case "org.cycle-global": cycleGlobal() |
| 579 | case "org.fold.toggle", "org.fold.open", "org.fold.close": fold(id) | |
| 583 | case _ where id.hasPrefix("org.fold."): fold(id) | |
| 580 | 584 | case "org.narrow.subtree", "org.narrow.block", "org.narrow.toggle", "org.widen": narrow(id) |
| 581 | 585 | case "org.toggle-inline-images": toggleImages() |
| 582 | 586 | case "org.latex-preview": toggleLatex() |
| @@ -790,6 +794,7 @@ public final class OrgEditor: NSObject { | ||
| 790 | 794 | mapWrapperFolds(through: edit, near: min(oldMapped.lowerBound, newAffected.lowerBound)..<max(oldMapped.upperBound, newAffected.upperBound)) |
| 791 | 795 | if let narrowed { self.narrowed = ViewState(selection: [narrowed]).mapped(through: [edit]).selection[0] } |
| 792 | 796 | mapVimPositions(through: edit) |
| 797 | vim.changed(edit) | |
| 793 | 798 | if let sparse = sparseHidden { sparseHidden = ViewState(selection: sparse).mapped(through: [edit]).selection.filter { !$0.isEmpty } } |
| 794 | 799 | let oldHighlights = ViewState(selection: highlights).mapped(through: [edit]).selection |
| 795 | 800 | highlights = [] |
Sources/OrgPresentation/Folding.swift +38
| @@ -105,6 +105,44 @@ extension Presentation { | ||
| 105 | 105 | return next |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | /// Doom's `zO` (`outline-show-subtree`): the heading's whole subtree open. | |
| 109 | public static func showSubtree(_ heading: Int, in tree: OrgTree, _ state: FoldState) -> FoldState { | |
| 110 | guard let entry = outline(tree).first(where: { $0.start == heading }) else { return state } | |
| 111 | var next = state | |
| 112 | next.folds = next.folds.filter { $0 < entry.start || $0 >= entry.end } | |
| 113 | next.bodyFolds = next.bodyFolds.filter { $0 < entry.start || $0 >= entry.end } | |
| 114 | return next | |
| 115 | } | |
| 116 | ||
| 117 | /// Doom's `zR` (`outline-show-all`): every heading open; drawers and blocks stay as they are. | |
| 118 | public static func showAllHeadings(_ state: FoldState) -> FoldState { | |
| 119 | FoldState(wrapperFolds: state.wrapperFolds) | |
| 120 | } | |
| 121 | ||
| 122 | /// `outline-hide-sublevels`, behind Doom's `zM`, `zr` and `zm`: headings down to `levels` | |
| 123 | /// show, without bodies. | |
| 124 | public static func hideSublevels(_ levels: Int, in tree: OrgTree, _ state: FoldState) -> FoldState { | |
| 125 | var next = foldState(showingLevels: levels, in: tree) | |
| 126 | next.wrapperFolds = state.wrapperFolds | |
| 127 | return next | |
| 128 | } | |
| 129 | ||
| 130 | /// Doom's `+org--get-foldlevel`: the deepest level of a visible folded heading, or 1. | |
| 131 | public static func foldLevel(in tree: OrgTree, _ state: FoldState) -> Int { | |
| 132 | let outline = outline(tree) | |
| 133 | var level = 1 | |
| 134 | for entry in outline where isFolded(entry.start, state) { | |
| 135 | var parent = entry.parent | |
| 136 | var hidden = false | |
| 137 | while let index = parent { | |
| 138 | if state.folds.contains(outline[index].start) { hidden = true } | |
| 139 | parent = outline[index].parent | |
| 140 | } | |
| 141 | if !hidden { level = max(level, entry.level) } | |
| 142 | } | |
| 143 | return level | |
| 144 | } | |
| 145 | ||
| 108 | 146 | /// Whether the heading's body is hidden. |
| 109 | 147 | private static func isFolded(_ heading: Int, _ state: FoldState) -> Bool { |
| 110 | 148 | state.folds.contains(heading) || state.bodyFolds.contains(heading) |
Sources/Orgstar/PaneView.swift +1
| @@ -91,6 +91,7 @@ struct PaneView: NSViewRepresentable { | ||
| 91 | 91 | let store = commands.store |
| 92 | 92 | editor.onChange = { [weak session] in session?.bufferChanged(path) } |
| 93 | 93 | editor.baseDirectory = URL(fileURLWithPath: path).deletingLastPathComponent() |
| 94 | editor.fileName = path | |
| 94 | 95 | editor.attachmentPath = { DocumentSession.attachmentPath($0, at: $1, tree: $2, path: path) } |
| 95 | 96 | editor.onMessage = { [weak commands] in commands?.show($0) } |
| 96 | 97 | editor.onKeysPending = { [weak commands] keys, next in |
Sources/OrgstarMobile/EditorScreen.swift +1
| @@ -452,6 +452,7 @@ struct EditorScreen: View { | ||
| 452 | 452 | showMarkup: model.showMarkup, baseDirectory: URL(fileURLWithPath: path).deletingLastPathComponent() |
| 453 | 453 | ) |
| 454 | 454 | let path = path |
| 455 | editor.fileName = path | |
| 455 | 456 | editor.attachmentPath = { DocumentSession.attachmentPath($0, at: $1, tree: $2, path: path) } |
| 456 | 457 | return editor |
| 457 | 458 | } |
Sources/OrgstarMobile/MobileEditor+Display.swift +25
| @@ -199,6 +199,31 @@ extension MobileEditor { | ||
| 199 | 199 | setFolds(state) |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | /// Doom's `za`, `zo` (on a heading line), `zc` and `zO` (anywhere in a subtree), and `zR`, | |
| 203 | /// `zM`, `zr` and `zm` for the whole buffer. | |
| 204 | func foldCommand(_ id: String) { | |
| 205 | let caret = textView.selectedRange.location | |
| 206 | let tree = document.tree | |
| 207 | let length = (document.text as NSString).length | |
| 208 | let next: FoldState? | |
| 209 | if id == "org.fold.close" || id == "org.fold.open-subtree" { | |
| 210 | next = Presentation.outline(tree).last { $0.start <= caret && (caret < $0.end || $0.end == length) } | |
| 211 | .map { id == "org.fold.close" ? Presentation.hideSubtree($0.start, fold) : Presentation.showSubtree($0.start, in: tree, fold) } | |
| 212 | } else if id == "org.fold.open-all" { | |
| 213 | next = Presentation.showAllHeadings(fold) | |
| 214 | } else if id == "org.fold.close-all" { | |
| 215 | next = Presentation.hideSublevels(1, in: tree, fold) | |
| 216 | } else if id == "org.fold.more" || id == "org.fold.less" { | |
| 217 | let level = Presentation.foldLevel(in: tree, fold) | |
| 218 | next = Presentation.hideSublevels(id == "org.fold.more" ? level + 1 : max(1, level - 1), in: tree, fold) | |
| 219 | } else { | |
| 220 | next = Presentation.heading(containing: caret, in: tree).map { | |
| 221 | id == "org.fold.open" ? Presentation.openFold($0, in: tree, fold) : Presentation.toggleFold($0, in: tree, fold) | |
| 222 | } | |
| 223 | } | |
| 224 | if let next, next != fold { setFolds(next) } | |
| 225 | } | |
| 226 | ||
| 202 | 227 | /// Opens the folds hiding `offset`. |
| 203 | 228 | func unfold(around offset: Int) { |
| 204 | 229 | var state = fold |
Sources/OrgstarMobile/MobileEditor+Modal.swift +37 −1
| @@ -61,7 +61,8 @@ extension MobileEditor { | ||
| 61 | 61 | // Reading the clipboard asks for permission, so only the keys that paste read it. |
| 62 | 62 | let pastes = key.modifiers.isEmpty && (key.key == "p" || key.key == "P") |
| 63 | 63 | let clipboard = pastes ? UIPasteboard.general.string : Self.vimClipboardRecord?.text |
| 64 | let actions = vim.feed(key, Vim.Context(text: document.text, caret: caret, clipboard: clipboard, halfPage: halfPage, marks: marks, visible: visibleText, org: true)) | |
| 64 | let actions = vim.feed(key, Vim.Context(text: document.text, caret: caret, clipboard: clipboard, halfPage: halfPage, marks: marks, visible: visibleText, org: true, | |
| 65 | fileName: fileName, lastEx: Self.promptHistory[":"]?.last)) | |
| 65 | 66 | Self.vimRegisters = vim.registers |
| 66 | 67 | Self.vimClipboardRecord = vim.clipboardRecord |
| 67 | 68 | apply(actions) |
| @@ -197,6 +198,10 @@ extension MobileEditor { | ||
| 197 | 198 | } |
| 198 | 199 | case .scroll(let place): |
| 199 | 200 | scrollCaretLine(place) |
| 201 | case .scrollLines(let count): | |
| 202 | scrollLines(count) | |
| 203 | case .scrollColumns(let count, let halfWidths): | |
| 204 | scrollColumns(count, halfWidths: halfWidths) | |
| 200 | 205 | } |
| 201 | 206 | } |
| 202 | 207 | } |
| @@ -237,6 +242,32 @@ extension MobileEditor { | ||
| 237 | 242 | textView.setContentOffset(CGPoint(x: textView.contentOffset.x, y: min(max(-textView.adjustedContentInset.top, y), maxY)), animated: false) |
| 238 | 243 | } |
| 239 | 244 | |
| 245 | /// C-e and C-y: the window down or up by lines; the cursor stays in it, as in Emacs. | |
| 246 | private func scrollLines(_ count: Int) { | |
| 247 | let inset = textView.adjustedContentInset | |
| 248 | let maxY = max(-inset.top, textView.contentSize.height - textView.bounds.height + inset.bottom) | |
| 249 | let y = textView.contentOffset.y + CGFloat(count) * max(1, theme.font.lineHeight) | |
| 250 | textView.setContentOffset(CGPoint(x: textView.contentOffset.x, y: min(max(-inset.top, y), maxY)), animated: false) | |
| 251 | guard vim.mode == .normal, let visible = visibleText, !visible.isEmpty else { return } | |
| 252 | let caret = textView.selectedRange.location | |
| 253 | let ns = document.text as NSString | |
| 254 | // Without scrolling back to where the cursor was. | |
| 255 | if caret < visible.lowerBound { | |
| 256 | textView.selectedRange = NSRange(location: ns.lineRange(for: NSRange(location: visible.lowerBound, length: 0)).location, length: 0) | |
| 257 | } else if caret >= visible.upperBound { | |
| 258 | textView.selectedRange = NSRange(location: ns.lineRange(for: NSRange(location: visible.upperBound - 1, length: 0)).location, length: 0) | |
| 259 | } | |
| 260 | } | |
| 261 | ||
| 262 | /// `zl`, `zh`, `zL` and `zH`: the window right or left by columns or half its width, which | |
| 263 | /// moves nothing while lines wrap. | |
| 264 | private func scrollColumns(_ count: Int, halfWidths: Bool) { | |
| 265 | let step = halfWidths ? textView.bounds.width / 2 : (" " as NSString).size(withAttributes: [.font: theme.font]).width | |
| 266 | let maxX = max(0, textView.contentSize.width - textView.bounds.width) | |
| 267 | let x = textView.contentOffset.x + CGFloat(count) * step | |
| 268 | textView.setContentOffset(CGPoint(x: min(max(0, x), maxX), y: textView.contentOffset.y), animated: false) | |
| 269 | } | |
| 270 | ||
| 240 | 271 | /// `/`, `?` and `:`; with `history` (`q:`), the earlier ones to pick and edit. |
| 241 | 272 | private func prompt(_ kind: String, history: Bool = false) { |
| 242 | 273 | let earlier = Array((Self.promptHistory[kind] ?? []).reversed()) |
| @@ -262,6 +293,10 @@ extension MobileEditor { | ||
| 262 | 293 | switch trimmed { |
| 263 | 294 | case "w", "write", "wq", "x": onAppCommand?("app.save") |
| 264 | 295 | case "noh", "nohlsearch": break |
| 296 | case "s", "&", "&&", "%&&": | |
| 297 | // The last substitution again; `&&` keeps its flags. | |
| 298 | guard let last = Self.lastSubstitute else { return } | |
| 299 | substitute(whole: trimmed.hasPrefix("%"), pattern: last.pattern, replacement: last.replacement, flags: trimmed.hasSuffix("&&") ? last.flags : "") | |
| 265 | 300 | default: |
| 266 | 301 | if let line = Int(trimmed) { |
| 267 | 302 | let ns = document.text as NSString |
| @@ -275,6 +310,7 @@ extension MobileEditor { | ||
| 275 | 310 | return |
| 276 | 311 | } |
| 277 | 312 | if let m = trimmed.firstMatch(of: /^(%?)s\/((?:[^\/\\]|\\.)*)\/((?:[^\/\\]|\\.)*)\/?([gi]*)$/) { |
| 313 | Self.lastSubstitute = (String(m.2), String(m.3), String(m.4)) | |
| 278 | 314 | substitute(whole: !m.1.isEmpty, pattern: String(m.2), replacement: String(m.3), flags: String(m.4)) |
| 279 | 315 | return |
| 280 | 316 | } |
Sources/OrgstarMobile/MobileEditor.swift +7
| @@ -75,6 +75,10 @@ final class MobileEditor: NSObject, DocumentBuffer { | ||
| 75 | 75 | static var macros: [Character: [KeyChord]] = [:] |
| 76 | 76 | /// What `:`, `/` and `?` read, oldest first, for `q:`. |
| 77 | 77 | static var promptHistory: [String: [String]] = [:] |
| 78 | /// The last `:s`, for `&` and `g&`. | |
| 79 | static var lastSubstitute: (pattern: String, replacement: String, flags: String)? | |
| 80 | /// The file's path, for the `%` register. | |
| 81 | var fileName: String? | |
| 78 | 82 | var onChange: (() -> Void)? |
| 79 | 83 | var onMessage: ((String) -> Void)? |
| 80 | 84 | var onPrompt: ((Prompt, @escaping (String?) -> Void) -> Void)? |
| @@ -376,6 +380,7 @@ final class MobileEditor: NSObject, DocumentBuffer { | ||
| 376 | 380 | case "org.cycle": |
| 377 | 381 | if !cycleAtCaret() { onMessage?("Not on a heading, drawer or block") } |
| 378 | 382 | case "org.cycle-global": cycleGlobal() |
| 383 | case _ where id.hasPrefix("org.fold."): foldCommand(id) | |
| 379 | 384 | case "org.link.open": openLinkAtCaret() |
| 380 | 385 | case "org.toggle-inline-images": toggleImages() |
| 381 | 386 | case "org.latex-preview": toggleLatex() |
| @@ -411,6 +416,7 @@ final class MobileEditor: NSObject, DocumentBuffer { | ||
| 411 | 416 | switch id { |
| 412 | 417 | case "org.cycle": |
| 413 | 418 | return Presentation.heading(containing: context.caret, in: context.tree) != nil || Wrappers.toggleable(at: context.caret, in: context.tree) != nil |
| 419 | case _ where id.hasPrefix("org.fold."): return true | |
| 414 | 420 | case "org.cycle-global", "edit.undo", "edit.redo", "org.toggle-inline-images", "org.latex-preview", "editor.toggle-truncate-lines", |
| 415 | 421 | "editor.toggle-auto-fill", "edit.isearch-forward", "edit.isearch-backward", |
| 416 | 422 | "edit.isearch-forward-regexp", "edit.isearch-backward-regexp": return true |
| @@ -565,6 +571,7 @@ final class MobileEditor: NSObject, DocumentBuffer { | ||
| 565 | 571 | load(textView.textStorage.string) |
| 566 | 572 | return |
| 567 | 573 | } |
| 574 | vim.changed(edit) | |
| 568 | 575 | for table in shrunk.map(through: edit, in: textView.textStorage.string, command: commandEditing) { scheduleRestyle(table) } |
| 569 | 576 | fold = FoldState( |
| 570 | 577 | folds: Self.map(fold.folds, old, delta), bodyFolds: Self.map(fold.bodyFolds, old, delta), |
Tests/OrgCoreTests/KeymapTests.swift +4
| @@ -126,6 +126,10 @@ struct KeymapTests { | ||
| 126 | 126 | #expect(doom.keyLabels(for: "app.buffer.kill", modes: ["normal"], limit: 3) == ["C-x k", "SPC b d", "SPC b k"]) |
| 127 | 127 | #expect(doom.keyLabels(for: "app.buffer.next", modes: ["normal"]) == ["] b", "C-x <right>"]) |
| 128 | 128 | #expect(emacs.keyLabels(for: "app.buffer.switch") == ["C-x C-b", "C-x b"]) |
| 129 | for (keys, command) in [("z C", "org.fold.close"), ("z O", "org.fold.open-subtree"), ("z R", "org.fold.open-all"), ("z M", "org.fold.close-all"), | |
| 130 | ("z r", "org.fold.more"), ("z m", "org.fold.less")] { | |
| 131 | #expect(doom.candidates(for: KeySequence.parse(keys)!, mode: "normal").first?.command == command) | |
| 132 | } | |
| 129 | 133 | #expect(!emacs.keyLabels(for: "app.quick-open").contains("C-x b")) |
| 130 | 134 | } |
| 131 | 135 | |
Tests/OrgCoreTests/VimEvilTests.swift added +197
| @@ -0,0 +1,197 @@ | ||
| 1 | import Foundation | |
| 2 | import Testing | |
| 3 | @testable import OrgCore | |
| 4 | ||
| 5 | /// Evil's `gi`, `g;`, `g,`, `gJ`, `&`, the numbered and read-only registers, sentences, tags | |
| 6 | /// and scrolling by lines and columns. | |
| 7 | struct VimEvilTests { | |
| 8 | static let sentences = "One two. Three four! Five\nsix seven? Eight.\n\n\nNine ten. Eleven\n" | |
| 9 | static let lines = "One two.\nThree four. Five\n\nSix. Seven\n" | |
| 10 | static let tags = "<a><b>x y</b> z</a>\n<p class=\"k\">\nline\n</p>\n<br/> tail\n" | |
| 11 | static let joined = "a b\n c d\ne\n\nf\n" | |
| 12 | static let words = "alpha beta\ngamma delta\nepsilon zeta\neta theta\n" | |
| 13 | ||
| 14 | static let cases: [(String, Int, String)] = { | |
| 15 | var cases: [(String, Int, String)] = [] | |
| 16 | for point in [0, 4, 9, 12, 22, 30, 38, 45, 46, 47, 58] { | |
| 17 | cases.append((sentences, point, ")")) | |
| 18 | if point > 0 { cases.append((sentences, point, "(")) } | |
| 19 | } | |
| 20 | cases += [(sentences, 0, "2 )"), (sentences, 0, "5 )"), (sentences, 58, "3 ("), (sentences, 4, "v ) d"), (sentences, 30, "y ( P")] | |
| 21 | for point in [0, 8, 9, 20, 21, 22, 45, 47, 58] { | |
| 22 | cases.append((sentences, point, "d i s")) | |
| 23 | cases.append((sentences, point, "d a s")) | |
| 24 | } | |
| 25 | for point in [0, 9, 21, 26, 27, 32] { | |
| 26 | cases.append((lines, point, "d i s")) | |
| 27 | cases.append((lines, point, "d a s")) | |
| 28 | } | |
| 29 | cases += [ | |
| 30 | (sentences, 0, "d 2 a s"), (sentences, 0, "d 2 i s"), (sentences, 0, "d 3 i s"), (sentences, 12, "c a s X ESC"), | |
| 31 | (sentences, 12, "v i s d"), (sentences, 12, "y i s P"), | |
| 32 | (lines, 0, "d )"), (lines, 12, "d ("), (lines, 12, "d )"), (lines, 21, "d )"), (lines, 27, "d ("), (lines, 32, "d )"), | |
| 33 | ] | |
| 34 | for point in [0, 3, 6, 8, 10, 14, 18, 20, 34, 37, 46] { | |
| 35 | cases.append((tags, point, "d i t")) | |
| 36 | cases.append((tags, point, "d a t")) | |
| 37 | } | |
| 38 | cases += [(tags, 7, "d 2 i t"), (tags, 7, "d 2 a t"), (tags, 7, "c i t X ESC"), (tags, 7, "v a t d"), (tags, 7, "y i t P")] | |
| 39 | cases += ["g J", "3 g J", "V j g J", "j g J", "j j j g J", "g J .", "v j j g J"].map { (joined, 1, $0) } | |
| 40 | cases += [ | |
| 41 | "g i X ESC", "A X ESC g g g i Y ESC", "w i X Y ESC j j g i Z ESC", "A X ESC g g O n e w ESC j j g i Y ESC", | |
| 42 | "A X ESC g g g i Y ESC j .", | |
| 43 | "x j x j x g ;", "x j x j x g ; g ;", "x j x j x g ; g ; g ,", "x j x j x g ; g ; g ; g ;", "A a b c ESC g g g ;", | |
| 44 | "x w x w x j g ; g ;", "A 1 2 3 4 5 6 7 8 9 0 ESC j 0 x g g g ; g ;", "j d d j x g g g ; g ;", | |
| 45 | "y w j d w j d d g g \" 1 P", "y w j d w j d d g g \" 2 P", "y w j d w j d d g g \" 3 P", "y w j d w j d d g g \" 0 P", | |
| 46 | "y w j d w j d d g g \" - P", "d w j d d g g \" - P", "x j x j d w g g \" 1 P", "x j x j d w g g \" 3 p", | |
| 47 | "\" a y w j d w g g \" 1 P", "\" a y w j d w g g \" 0 P", "v e d j \" - P", "y y j \" 1 p", | |
| 48 | "A f o o ESC g g \" . P", "c w n e w ESC j 0 \" . P", | |
| 49 | ].map { (words, 0, $0) } | |
| 50 | return cases | |
| 51 | }() | |
| 52 | ||
| 53 | @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil)) | |
| 54 | func matchesEvil() throws { | |
| 55 | let repos = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".config/emacs/.local/straight/repos") | |
| 56 | guard FileManager.default.fileExists(atPath: repos.appendingPathComponent("goto-chg/goto-chg.el").path) else { return } | |
| 57 | let forms = Self.cases.map { c in | |
| 58 | EmacsOracle.Case(text: c.0, point: c.1 + 1, form: """ | |
| 59 | (progn | |
| 60 | (setq evil-want-Y-yank-to-eol t evil-undo-system 'undo-redo sentence-end-double-space nil) | |
| 61 | (dolist (d '("evil" "goto-chg")) (add-to-list 'load-path (concat \(lispString(repos.path)) "/" d))) | |
| 62 | (require 'evil) | |
| 63 | (require 'goto-chg) | |
| 64 | (setq kill-ring nil register-alist nil evil-last-small-deletion nil evil-last-insertion nil) | |
| 65 | (buffer-enable-undo) | |
| 66 | (setq buffer-undo-list nil) | |
| 67 | (switch-to-buffer (current-buffer)) | |
| 68 | (evil-local-mode 1) | |
| 69 | (evil-normal-state) | |
| 70 | (ignore-errors (execute-kbd-macro (kbd \(lispString(c.2.replacingOccurrences(of: "ESC", with: "<escape>")))))) | |
| 71 | (let ((p (point)) (s evil-state)) | |
| 72 | (goto-char (point-max)) | |
| 73 | (insert (format "\\n@@STATE %s" s)) | |
| 74 | (goto-char p))) | |
| 75 | """) | |
| 76 | } | |
| 77 | let results = try EmacsOracle.run(forms) | |
| 78 | for (c, result) in zip(Self.cases, results) { | |
| 79 | let (text, point, keys) = c | |
| 80 | var driver = VimDriver(text, caret: point) | |
| 81 | driver.type(KeySequence.parse(keys)!) | |
| 82 | guard let marker = result.text.range(of: "\n@@STATE ") else { | |
| 83 | Issue.record("\(keys): \(result.error)") | |
| 84 | continue | |
| 85 | } | |
| 86 | let emacsText = String(result.text[..<marker.lowerBound]) | |
| 87 | let state = String(result.text[marker.upperBound...]) | |
| 88 | let ours = driver.vim.mode == .insert ? "insert" : driver.vim.mode == .normal ? "normal" : "visual" | |
| 89 | let emacsCaret = EmacsOracle.offset(result.point, in: result.text) | |
| 90 | #expect(driver.text == emacsText && driver.caret == emacsCaret && ours == state, | |
| 91 | "\(keys.debugDescription) on \(text.debugDescription) at \(point)\nours: \(driver.text.debugDescription) @\(driver.caret) \(ours)\nevil: \(emacsText.debugDescription) @\(emacsCaret) \(state) \(result.error)") | |
| 92 | } | |
| 93 | } | |
| 94 | ||
| 95 | private func run(_ text: String, at caret: Int = 0, _ keys: String) -> VimDriver { | |
| 96 | var driver = VimDriver(text, caret: caret) | |
| 97 | driver.type(KeySequence.parse(keys)!) | |
| 98 | return driver | |
| 99 | } | |
| 100 | ||
| 101 | @Test func resumesInsertAtTheLastInsertion() { | |
| 102 | #expect(run(Self.words, "A X ESC g g g i Y ESC").text.hasPrefix("alpha betaXY\n")) | |
| 103 | // The mark moves with later edits. | |
| 104 | #expect(run(Self.words, "A X ESC 0 x j j g i Y ESC").text.hasPrefix("lpha betaXY\n")) | |
| 105 | #expect(run(Self.words, "g i X ESC").text.hasPrefix("Xalpha")) | |
| 106 | } | |
| 107 | ||
| 108 | @Test func goesThroughTheChangeList() { | |
| 109 | #expect(run(Self.words, "x j x j x g g g ;").caret == 21) | |
| 110 | #expect(run(Self.words, "x j x j x g g g ; g ;").caret == 10) | |
| 111 | #expect(run(Self.words, "x j x j x g g g ; g ; g ,").caret == 21) | |
| 112 | // A change within eight characters of a later one is passed over. | |
| 113 | #expect(run(Self.words, "x w x G g ;").caret == 5) | |
| 114 | #expect(run(Self.words, "x w x G g ; g ;").caret == 5) | |
| 115 | #expect(run(Self.words, "3 j g ;").caret == 36) | |
| 116 | // Another command starts over from the latest change. | |
| 117 | #expect(run(Self.words, "x j x j x g ; g ; j g ;").caret == 21) | |
| 118 | } | |
| 119 | ||
| 120 | @Test func joinsWithoutChangingBlanks() { | |
| 121 | #expect(run(Self.joined, at: 1, "g J").text == "a b c d\ne\n\nf\n") | |
| 122 | #expect(run(Self.joined, at: 1, "3 g J").text == "a b c de\n\nf\n") | |
| 123 | #expect(run(Self.joined, at: 1, "V j j g J").text == "a b c de\n\nf\n") | |
| 124 | #expect(run(Self.joined, at: 1, "g J").caret == 3) | |
| 125 | } | |
| 126 | ||
| 127 | @Test func repeatsTheLastSubstitution() { | |
| 128 | #expect(run(Self.words, "&").actions == [.ex("&")]) | |
| 129 | #expect(run(Self.words, "g &").actions == [.ex("%&&")]) | |
| 130 | } | |
| 131 | ||
| 132 | @Test func numberedRegistersHoldEarlierKills() { | |
| 133 | let keys = "y w j d w j d d g g " | |
| 134 | #expect(run(Self.words, keys + "\" 1 P").text.hasPrefix("epsilon zeta\nalpha beta\n")) | |
| 135 | #expect(run(Self.words, keys + "\" 2 P").text.hasPrefix("gamma alpha beta\n")) | |
| 136 | #expect(run(Self.words, keys + "\" 3 P").text.hasPrefix("alpha alpha beta\n")) | |
| 137 | #expect(run(Self.words, keys + "\" 0 P").text.hasPrefix("alpha alpha beta\n")) | |
| 138 | #expect(run(Self.words, keys + "\" - P").text.hasPrefix("gamma alpha beta\n")) | |
| 139 | var vim = Vim() | |
| 140 | let context = Vim.Context(text: "abcdefghijkl\n", caret: 0) | |
| 141 | for _ in 0..<11 { _ = vim.feed(KeyChord("x"), context) } | |
| 142 | #expect(vim.registers["9"]?.text == "a" && vim.registers["1"]?.text == "a" && vim.registers.keys.filter(\.isNumber).count == 9) | |
| 143 | } | |
| 144 | ||
| 145 | @Test func readOnlyRegisters() { | |
| 146 | #expect(run(Self.words, "A f o o ESC 0 \" . P").text.hasPrefix("fooalpha betafoo\n")) | |
| 147 | var driver = VimDriver(Self.words, caret: 0) | |
| 148 | driver.fileName = "/notes/todo.org" | |
| 149 | driver.lastEx = "s/a/b" | |
| 150 | driver.type(KeySequence.parse("\" % P")!) | |
| 151 | #expect(driver.text.hasPrefix("/notes/todo.orgalpha")) | |
| 152 | driver.type(KeySequence.parse("j 0 \" : P")!) | |
| 153 | #expect(driver.text.contains("\ns/a/bgamma")) | |
| 154 | _ = driver.vim.search("zeta", forward: true, Vim.Context(text: driver.text, caret: 0)) | |
| 155 | driver.type(KeySequence.parse("2 j 0 \" / P")!) | |
| 156 | #expect(driver.text.contains("\nzetaeta theta")) | |
| 157 | // Without a file, a command or a search there is nothing to put. | |
| 158 | #expect(run(Self.words, "\" % P \" : P \" / P \" . P").text == Self.words) | |
| 159 | } | |
| 160 | ||
| 161 | @Test func sentenceMotionsAndObjects() { | |
| 162 | #expect(run(Self.sentences, ")").caret == 9) | |
| 163 | #expect(run(Self.sentences, at: 38, ")").caret == 45) | |
| 164 | #expect(run(Self.sentences, at: 47, "(").caret == 46) | |
| 165 | #expect(run(Self.sentences, at: 12, "d i s").text.hasPrefix("One two. Five\n")) | |
| 166 | #expect(run(Self.sentences, at: 12, "d a s").text.hasPrefix("One two. Five\n")) | |
| 167 | #expect(run(Self.lines, at: 21, "d a s").text.hasPrefix("One two.\nThree four.\n\n")) | |
| 168 | #expect(run(Self.lines, "d a s").text.hasPrefix("\nThree four.")) | |
| 169 | #expect(run(Self.sentences, "d 2 a s").text.hasPrefix("Five\n")) | |
| 170 | // In Org, a heading and a list item begin sentences of their own. | |
| 171 | var driver = VimDriver("* Head\nBody one. Two\n- item\n", caret: 0) | |
| 172 | driver.org = true | |
| 173 | driver.type(KeySequence.parse(")")!) | |
| 174 | #expect(driver.caret == 7) | |
| 175 | driver.type(KeySequence.parse(") )")!) | |
| 176 | #expect(driver.caret == 21) | |
| 177 | } | |
| 178 | ||
| 179 | @Test func tagObjects() { | |
| 180 | #expect(run(Self.tags, at: 7, "d i t").text.hasPrefix("<a><b></b> z</a>\n")) | |
| 181 | #expect(run(Self.tags, at: 7, "d a t").text.hasPrefix("<a> z</a>\n")) | |
| 182 | #expect(run(Self.tags, at: 7, "d 2 i t").text.hasPrefix("<a></a>\n")) | |
| 183 | #expect(run(Self.tags, at: 35, "d i t").text.contains("<p class=\"k\"></p>")) | |
| 184 | #expect(run(Self.tags, at: 46, "d a t").text == Self.tags) | |
| 185 | // A pair that fills its lines goes with them. | |
| 186 | #expect(run(Self.tags, at: 35, "d a t").text == "<a><b>x y</b> z</a>\n<br/> tail\n") | |
| 187 | } | |
| 188 | ||
| 189 | @Test func scrollsByLinesAndColumns() { | |
| 190 | #expect(run(Self.words, "C-e").actions == [.scrollLines(1)]) | |
| 191 | #expect(run(Self.words, "3 C-y").actions == [.scrollLines(-3)]) | |
| 192 | #expect(run(Self.words, "z l").actions == [.scrollColumns(1, halfWidths: false)]) | |
| 193 | #expect(run(Self.words, "4 z h").actions == [.scrollColumns(-4, halfWidths: false)]) | |
| 194 | #expect(run(Self.words, "z L").actions == [.scrollColumns(1, halfWidths: true)]) | |
| 195 | #expect(run(Self.words, "z H").actions == [.scrollColumns(-1, halfWidths: true)]) | |
| 196 | } | |
| 197 | } | |
Tests/OrgCoreTests/VimTests.swift +21 −6
| @@ -13,38 +13,53 @@ struct VimDriver { | ||
| 13 | 13 | var halfPage = 15 |
| 14 | 14 | var visible: Range<Int>? |
| 15 | 15 | var org = false |
| 16 | var marks: [Character: Int] = [:] | |
| 17 | var fileName: String? | |
| 18 | var lastEx: String? | |
| 19 | var actions: [Vim.Action] = [] | |
| 16 | 20 | |
| 17 | 21 | init(_ text: String, caret: Int) { |
| 18 | 22 | self.text = text |
| 19 | 23 | self.caret = caret |
| 20 | 24 | } |
| 21 | 25 | |
| 26 | /// An edit as the editor makes it: the change list hears of it and the marks move. | |
| 27 | mutating func edit(_ edit: TextEdit) { | |
| 28 | text = edit.apply(to: text) | |
| 29 | vim.changed(edit) | |
| 30 | let delta = edit.replacement.utf16.count - edit.range.count | |
| 31 | for (name, mark) in marks where mark >= edit.range.lowerBound { | |
| 32 | marks[name] = mark >= edit.range.upperBound ? mark + delta : edit.range.lowerBound | |
| 33 | } | |
| 34 | } | |
| 35 | ||
| 22 | 36 | mutating func type(_ keys: [KeyChord]) { |
| 23 | 37 | for key in keys { |
| 24 | 38 | if vim.mode == .insert, vim.passesThrough(key) { |
| 25 | 39 | if key == KeyChord("DEL") { |
| 26 | 40 | if caret > 0 { |
| 27 | let ns = text as NSString | |
| 28 | text = ns.replacingCharacters(in: NSRange(location: caret - 1, length: 1), with: "") | |
| 41 | edit(TextEdit(range: (caret - 1)..<caret, replacement: "")) | |
| 29 | 42 | caret -= 1 |
| 30 | 43 | vim.deletedBackward() |
| 31 | 44 | } |
| 32 | 45 | } else { |
| 33 | 46 | let s = key.key == "SPC" ? " " : key.key == "RET" ? "\n" : key.key == "TAB" ? "\t" : key.key |
| 34 | 47 | guard key.modifiers.isEmpty, s.count == 1 else { continue } |
| 35 | let ns = text as NSString | |
| 36 | text = ns.replacingCharacters(in: NSRange(location: caret, length: 0), with: s) | |
| 48 | edit(TextEdit(range: caret..<caret, replacement: s)) | |
| 37 | 49 | caret += s.utf16.count |
| 38 | 50 | vim.inserted(s) |
| 39 | 51 | } |
| 40 | 52 | continue |
| 41 | 53 | } |
| 42 | let actions = vim.feed(key, Vim.Context(text: text, caret: caret, clipboard: clipboard, halfPage: halfPage, visible: visible, org: org)) | |
| 54 | let actions = vim.feed(key, Vim.Context(text: text, caret: caret, clipboard: clipboard, halfPage: halfPage, marks: marks, visible: visible, org: org, | |
| 55 | fileName: fileName, lastEx: lastEx)) | |
| 56 | self.actions += actions | |
| 43 | 57 | for action in actions { |
| 44 | 58 | switch action { |
| 45 | 59 | case .edit(let edits, let to): |
| 46 | for edit in edits.sorted(by: { $0.range.lowerBound > $1.range.lowerBound }) { text = edit.apply(to: text) } | |
| 60 | for edit in edits.sorted(by: { $0.range.lowerBound > $1.range.lowerBound }) { self.edit(edit) } | |
| 47 | 61 | caret = to |
| 62 | case .setMark(let name, let offset): marks[name] = offset | |
| 48 | 63 | case .move(let to): caret = to |
| 49 | 64 | case .setClipboard(let s): clipboard = s |
| 50 | 65 | case .command(let id): commands.append(id) |
Tests/OrgPresentationTests/FoldLevelTests.swift added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | import Foundation | |
| 2 | import Testing | |
| 3 | import OrgCore | |
| 4 | @testable import OrgPresentation | |
| 5 | ||
| 6 | /// The fold states behind Doom's `zO`, `zR`, `zM`, `zr` and `zm`. | |
| 7 | struct FoldLevelTests { | |
| 8 | static let text = "* A\nbody\n** B\ntext\n*** C\ndeep\n* D\n** E\n" | |
| 9 | let tree = OrgParser.parse(FoldLevelTests.text) | |
| 10 | ||
| 11 | private func at(_ heading: String) -> Int { | |
| 12 | (Self.text as NSString).range(of: heading).location | |
| 13 | } | |
| 14 | ||
| 15 | @Test func closesAndOpensEverything() { | |
| 16 | let wrappers: Set<Int> = [4] | |
| 17 | let closed = Presentation.hideSublevels(1, in: tree, FoldState(wrapperFolds: wrappers)) | |
| 18 | #expect(closed == FoldState(folds: [at("* A"), at("* D")], wrapperFolds: wrappers)) | |
| 19 | #expect(Presentation.showAllHeadings(closed) == FoldState(wrapperFolds: wrappers)) | |
| 20 | } | |
| 21 | ||
| 22 | @Test func stepsThroughLevels() { | |
| 23 | var state = Presentation.hideSublevels(1, in: tree, FoldState()) | |
| 24 | #expect(Presentation.foldLevel(in: tree, state) == 1) | |
| 25 | state = Presentation.hideSublevels(Presentation.foldLevel(in: tree, state) + 1, in: tree, state) | |
| 26 | #expect(state == FoldState(folds: [at("** B"), at("** E")], bodyFolds: [at("* A"), at("* D")])) | |
| 27 | #expect(Presentation.foldLevel(in: tree, state) == 2) | |
| 28 | state = Presentation.hideSublevels(Presentation.foldLevel(in: tree, state) + 1, in: tree, state) | |
| 29 | #expect(Presentation.foldLevel(in: tree, state) == 3) | |
| 30 | state = Presentation.hideSublevels(Presentation.foldLevel(in: tree, state) - 1, in: tree, state) | |
| 31 | #expect(state.folds == [at("** B"), at("** E")]) | |
| 32 | // A folded heading inside a folded subtree doesn't show, so it doesn't count. | |
| 33 | #expect(Presentation.foldLevel(in: tree, FoldState(folds: [at("* A"), at("*** C")])) == 1) | |
| 34 | #expect(Presentation.foldLevel(in: tree, FoldState()) == 1) | |
| 35 | } | |
| 36 | ||
| 37 | @Test func opensASubtree() { | |
| 38 | let state = FoldState(folds: [at("* A"), at("*** C"), at("* D")], bodyFolds: [at("** B"), at("** E")]) | |
| 39 | #expect(Presentation.showSubtree(at("* A"), in: tree, state) == FoldState(folds: [at("* D")], bodyFolds: [at("** E")])) | |
| 40 | #expect(Presentation.showSubtree(at("** B"), in: tree, state) == FoldState(folds: [at("* A"), at("* D")], bodyFolds: [at("** E")])) | |
| 41 | } | |
| 42 | } | |
docs/manual/guide/03-keys.org +32 −6
| @@ -343,10 +343,12 @@ Motions move the caret in normal state, extend the selection in visual states, a | ||
| 343 | 343 | | =s= /xy/, =S= /xy/ | evil-snipe: to the next or previous /xy/ on the line. Each character matches its variants as for =f=, and /xy/ without a capital matches case-insensitively. =SPC= and =TAB= are read as a space and a tab. Not available after an operator. | |
| 344 | 344 | | =%= | The bracket matching the next =()=, =[]= or ={}= on the line. | |
| 345 | 345 | | ={=, =}= | Previous, next blank line. | |
| 346 | | =(=, =)= | Previous, next beginning of a sentence. A sentence ends at =.=, =?= or =!=, with any closing quotes or brackets, before a blank or the line's end (Doom's =sentence-end-double-space= is off), and at a blank line. The blank line after a paragraph is a stop for =)= and the one before it for =(=. In Org files a heading and a list item begin sentences of their own. | | |
| 346 | 347 | | =/=, =?= | Searches forward or backward as you type a regular expression, the match selected and the others highlighted; =RET= goes there, wrapping around the file, and =Esc= goes back. On iOS, asks in the echo area instead. | |
| 347 | 348 | | =n=, =N= | Repeats the last search in the same or the opposite direction. | |
| 348 | 349 | | =*=, =#= | Searches forward or backward for the whole word under the caret. | |
| 349 | 350 | | =C-d=, =C-u= | Down, up half the window's height; with a count, that many lines. | |
| 351 | | =g;=, =g,= | =g;= goes to the place of the last change, and again to the one before it; =g,= comes back towards the latest (goto-chg, as evil binds it). A change within 8 characters of a later one is passed over, and any other command starts over from the latest change. Normal state only; counts are ignored. | | |
| 350 | 352 | | =H=, =M=, =L= | First non-blank of the top, middle or bottom line the window shows. With a count, =H= goes to that line from the top and =L= from the bottom. Lines are text lines, not wrapped screen lines. Linewise after an operator. | |
| 351 | 353 | | ='= /a/, =`= /a/ | To mark /a/: its line's first non-blank, or its exact position. See [[*Marks and jumps][Marks and jumps]]. | |
| 352 | 354 | |
| @@ -378,11 +380,16 @@ Single-key changes: | ||
| 378 | 380 | | =Y= | Yanks to the end of the line (=evil-want-Y-yank-to-eol=, as Doom sets it). | |
| 379 | 381 | | =p=, =P= | Pastes after or before the caret; whole lines go below or above the current line. A count pastes that many times. | |
| 380 | 382 | | =J= | Joins the next line (count: that many lines) with one space. | |
| 383 | | =gJ= | Joins the next line (count: that many lines) without adding or removing blanks. Also in visual state. | | |
| 384 | | =gi= | Enters insert state where insert state was last left (the =^= mark, which moves with the text as you edit). | | |
| 385 | | =&=, =g&= | =&= repeats the last =:s= on the caret's line, without its flags; =g&= repeats it on every line, with its flags. | | |
| 381 | 386 | | =~= | Toggles the case of the character under the caret and moves right. | |
| 382 | 387 | | =r= /x/ | Replaces the character under the caret (count: that many) with /x/; =r RET= splits the line. | |
| 383 | 388 | | =R= | Replace state: what you type overwrites the line's characters, and past the line's end adds to it. =RET= breaks the line, =DEL= gives back what was overwritten, =ESC= returns to normal state. A count types the text that many times. | |
| 384 | 389 | | =g==, =g-=, =C-a= | Adds the count (1) to the number at or after the caret on its line, or with =g-= takes it away, as evil-numbers does on Doom's =g== and =g-=: decimal, =0x= hex and =0b= binary numbers, keeping leading zeros and the hex digits' case. In visual state =g== and =g-= change every number in the selection, the nth by n times the count; =g+= and =C-a= by the count. =C-x= stays the Emacs prefix, as in Doom. | |
| 385 | 390 | | =zz=, =zt=, =zb= | Scrolls the caret's line to the middle, top or bottom of the window. =z.=, =z RET= and =z-= do the same and go to its first non-blank. A count names the line. | |
| 391 | | =C-e=, =C-y= | Scrolls the window down or up a line (count: that many). The caret moves only to stay in the window. Also in visual state, where the caret stays put. | | |
| 392 | | =zl=, =zh=, =zL=, =zH= | Scrolls the window right or left a column (count: that many), or with =zL= and =zH= half its width. This needs Truncate or Wrap Long Lines to be truncating: nothing moves while lines wrap. | | |
| 386 | 393 | | =u=, =C-r= | Undo, redo, with counts. | |
| 387 | 394 | | =.= | Repeats the last change. | |
| 388 | 395 | | =ZZ= | Saves the file and closes the window, as =:wq=. | |
| @@ -403,13 +410,13 @@ After an operator, or in visual state to select, =i= takes the inner object and | ||
| 403 | 410 | | =i{=, =a{=, =i}=, =a}=, =iB=, =aB= | Braces. | |
| 404 | 411 | | =i<=, =a<=, =i>=, =a>= | Angle brackets. | |
| 405 | 412 | | =ip=, =ap= | Paragraph: lines up to a blank line. | |
| 413 | | =is=, =as= | Sentence, as =(= and =)= find them. For =is= the blanks between two sentences are an object too. =as= takes the sentence with the blanks after it on its line, or else those before it; on blanks, it takes them and the sentence after. | | |
| 414 | | =it=, =at= | XML tags: the text between the nearest =<tag>= and its =</tag>= around the caret, or with =at= the tags as well. A count takes that many pairs outward. The caret on a tag counts as inside its pair, and self-closing tags are skipped. =at= on a pair that fills two or more whole lines takes the lines. | | |
| 406 | 415 | | =ie=, =ae= | Org object at the caret: emphasis, a link, a timestamp, a footnote reference, an entity, a macro and the like (=evil-org-inner-object=, =evil-org-an-object=). =ie= on emphasis takes the text inside the markers, on a link its description. With no object at the caret, the element. | |
| 407 | 416 | | =iE=, =aE= | Org element: a paragraph, a list, a table, a block, a drawer (=evil-org-inner-element=, =evil-org-an-element=). | |
| 408 | 417 | | =ir=, =ar= | Org greater element: the list, table, drawer, block or section that contains the element (=evil-org-inner-greater-element=, =evil-org-a-greater-element=). | |
| 409 | 418 | | =iR=, =aR= | Org subtree: =aR= is the heading and its subtree, =iR= its contents without the heading line (=evil-org-inner-subtree=, =evil-org-a-subtree=). | |
| 410 | 419 | |
| 411 | Tag objects (=it=, =at=) and sentence objects (=is=, =as=) are not available. | |
| 412 | ||
| 413 | 420 | ** Counts and registers |
| 414 | 421 | |
| 415 | 422 | A count is digits before a command; =0= only counts after another digit. A register is ="= and a name before the count and command: ="ayy=, ="a3dd=, ="ap=. |
| @@ -418,10 +425,16 @@ A count is digits before a command; =0= only counts after another digit. A regis | ||
| 418 | 425 | |-+-| |
| 419 | 426 | | ="a= to ="z= | Named registers. Yanking or deleting into =A= to =Z= appends to the lowercase one. Writing to a named register leaves the clipboard alone. | |
| 420 | 427 | | ="0= | The last yank. | |
| 428 | | ="1= to ="9= | The last nine yanks, deletes and changes made without a register, ="1= the latest. Evil reads these from the kill ring, so yanks are in them and small deletes too. | | |
| 429 | | ="-= | The last delete within a line made without a register. | | |
| 430 | | =".= | The text last typed in insert state. Read-only. | | |
| 431 | | =":= | The last ex command. Read-only. | | |
| 432 | | ="%= | The file's path. Read-only. | | |
| 433 | | ="/= | The last search pattern. Read-only. | | |
| 421 | 434 | | =""=, ="+=, ="*= | The system clipboard. This is the unnamed register: every yank, delete and change without a register goes to the clipboard, and =p= without a register pastes from it. | |
| 422 | 435 | | ="_= | The black hole: deletes without saving the text. | |
| 423 | 436 | |
| 424 | Pasting from the clipboard is linewise when its text is what the last linewise yank or delete put there; text copied in another app pastes as characters. Numbered registers ="1= to ="9=, and the read-only registers such as ="%=, are not available. | |
| 437 | Pasting from the clipboard is linewise when its text is what the last linewise yank or delete put there; text copied in another app pastes as characters. Pasting from an empty register does nothing. | |
| 425 | 438 | |
| 426 | 439 | Registers and macros are shared by every buffer, as in evil: a yank into ="a= in one file pastes with ="ap= in another. Lowercase marks and the jump list belong to the buffer and are gone when it closes. Nothing is kept when orgstar quits. |
| 427 | 440 | |
| @@ -446,7 +459,7 @@ A macro replays the keys you typed, including keymap commands, leader keys and i | ||
| 446 | 459 | |
| 447 | 460 | =m= /a/ sets mark /a/ (any letter) at the caret. Marks move with the text as you edit. ='= /a/ goes to the first non-blank of the mark's line, =`= /a/ to its exact position. =''= and =``= go back to where the last jump started. |
| 448 | 461 | |
| 449 | Jumps are =G=, =gg=, =%=, ={=, =}=, =n=, =N=, =*=, =#=, ='=, =`=, =H=, =M=, =L=, the snipes =s=, =S=, =f=, =F=, =t= and =T=, and searches with =/= and =?=. Each jump adds its starting point to the jump list, which keeps the last 100. =C-o= goes back through the list and =C-i= forward again. A new jump after =C-o= drops the places you went back past. | |
| 462 | Jumps are =G=, =gg=, =%=, ={=, =}=, =(=, =)=, =gi=, =g;=, =g,=, =n=, =N=, =*=, =#=, ='=, =`=, =H=, =M=, =L=, the snipes =s=, =S=, =f=, =F=, =t= and =T=, and searches with =/= and =?=. Each jump adds its starting point to the jump list, which keeps the last 100. =C-o= goes back through the list and =C-i= forward again. A new jump after =C-o= drops the places you went back past. | |
| 450 | 463 | |
| 451 | 464 | Lowercase marks belong to the buffer, and so do =C-o= and =C-i=. Uppercase marks (=mA= to =mZ=) are file marks, shared by every buffer: ='A= or =`A= in another buffer shows the buffer the mark was set in, at the mark. A file mark goes away when its buffer closes. |
| 452 | 465 | |
| @@ -531,6 +544,12 @@ Besides the leader, the preset binds these evil-org and Doom keys in normal stat | ||
| 531 | 544 | | =z a= | Toggle Fold (=+org/toggle-fold=). On a heading line: a folded heading opens one level, showing its body and its child headings folded; an open one folds. | |
| 532 | 545 | | =z o= | Open Fold (=+org/open-fold=). On a heading line, a folded heading opens one level; an open one stays as it is. | |
| 533 | 546 | | =z c= | Close Fold (=outline-hide-subtree=). Folds the subtree the caret is in, from anywhere inside it. | |
| 547 | | =z C= | Close Fold, as =z c=. | | |
| 548 | | =z O= | Open Subtree Folds (=outline-show-subtree=). Opens the whole subtree the caret is in. | | |
| 549 | | =z R= | Open All Folds (=+org/open-all-folds=). Every heading opens; folded drawers and blocks stay folded. | | |
| 550 | | =z M= | Close All Folds (=+org/close-all-folds=). Only top-level headings show. | | |
| 551 | | =z r= | Show Next Fold Level (=+org/show-next-fold-level=). Headings one level deeper than the deepest folded heading that shows, without bodies. | | |
| 552 | | =z m= | Hide Next Fold Level (=+org/hide-next-fold-level=). Headings one level less deep, without bodies. | | |
| 534 | 553 | | =z A= | Cycle Global Visibility. | |
| 535 | 554 | | =g h= | Up to Parent Heading. | |
| 536 | 555 | | =] h=, =[ h= | Next or previous heading at the same level. | |
| @@ -657,6 +676,8 @@ Besides the leader, the preset binds these evil-org and Doom keys in normal stat | ||
| 657 | 676 | | =:= /N/ | Goes to line /N/. | |
| 658 | 677 | | =:s/= /pattern/ =/= /replacement/ =/= /flags/ | Replaces on the current line. Flags: =g= for every match on the line, =i= to ignore case. =\1= in the replacement is the first group. | |
| 659 | 678 | | =:%s/= /pattern/ =/= /replacement/ =/= /flags/ | The same on every line. | |
| 679 | | =:s=, =:&= | Repeats the last substitution on the current line, without its flags. | | |
| 680 | | =:&&=, =:%&&= | Repeats it with its flags, on the current line or on every line. | | |
| 660 | 681 | | =:noh=, =:nohlsearch= | Accepted; does nothing. | |
| 661 | 682 | |
| 662 | 683 | =q:= opens the ex prompt with your earlier commands listed, most recent first, to pick and edit; =q/= and =q?= do the same for searches. |
| @@ -665,7 +686,7 @@ Anything else shows =Not an editor command=. Ranges other than =%=, the =c= flag | ||
| 665 | 686 | |
| 666 | 687 | ** Not available |
| 667 | 688 | |
| 668 | Things evil users may reach for that orgstar does not have: the fold =z= commands other than =za=, =zc=, =zo= and =zA=, and scrolling by lines (=zh=, =zl=, =C-e=, =C-y=); =gi=, =g;=, =gJ=; =&=; the numbered and read-only registers; tag and sentence text objects. | |
| 689 | Things evil users may reach for that orgstar does not have: counts before the fold =z= keys, Doom's =zn=, =zN=, =zi=, =zx=, =zj= and =zk=, and the vimish-fold keys (=zf=, =zF=, =zd=, =zE=); the scrolls =z+=, =z^=, =ze= and =zs=; counts for =gi=, =g;= and =&=; the ="#= and ="== registers, and =C-r= /register/ in insert state. | |
| 669 | 690 | |
| 670 | 691 | * Keys in other windows |
| 671 | 692 | |
| @@ -789,7 +810,12 @@ When a key appears in several rows, it runs the command whose condition holds at | ||
| 789 | 810 | | Cycle Visibility (=org.cycle=) | =TAB= | =⇥= | =TAB= (N, V) | On a heading, cycles its subtree through folded, children and everything; on the first or last line of a drawer or block, folds or unfolds it (=org-cycle=). Elsewhere, =TAB= types a tab in the Emacs and Mac presets. | |
| 790 | 811 | | Toggle Fold (=org.fold.toggle=) | — | — | =z a= (N) | On a heading line, opens a folded heading one level or folds an open one (=+org/toggle-fold=). | |
| 791 | 812 | | Open Fold (=org.fold.open=) | — | — | =z o= (N) | On a heading line, opens a folded heading one level (=+org/open-fold=). | |
| 792 | | Close Fold (=org.fold.close=) | — | — | =z c= (N) | Folds the subtree the caret is in (=outline-hide-subtree=). | | |
| 813 | | Close Fold (=org.fold.close=) | — | — | =z c=, =z C= (N) | Folds the subtree the caret is in (=outline-hide-subtree=). | | |
| 814 | | Open Subtree Folds (=org.fold.open-subtree=) | — | — | =z O= (N) | Opens the whole subtree the caret is in (=outline-show-subtree=). | | |
| 815 | | Open All Folds (=org.fold.open-all=) | — | — | =z R= (N) | Opens every heading; folded drawers and blocks stay folded (=+org/open-all-folds=). | | |
| 816 | | Close All Folds (=org.fold.close-all=) | — | — | =z M= (N) | Shows only top-level headings (=+org/close-all-folds=). | | |
| 817 | | Show Next Fold Level (=org.fold.more=) | — | — | =z r= (N) | Shows headings one level deeper than the deepest folded heading that shows, without bodies (=+org/show-next-fold-level=). | | |
| 818 | | Hide Next Fold Level (=org.fold.less=) | — | — | =z m= (N) | Shows headings one level less deep, without bodies (=+org/hide-next-fold-level=). | | |
| 793 | 819 | | Cycle Global Visibility (=org.cycle-global=) | =S-TAB= | =⇧⇥= | =S-TAB=, =z A= (N) | Cycles the whole file through overview, contents and everything (=org-global-cycle=). | |
| 794 | 820 | | Narrow to Subtree (=org.narrow.subtree=) | =C-x n s= | — | =SPC m s n= (N) | Shows only the current subtree (=org-narrow-to-subtree=). | |
| 795 | 821 | | Narrow to Block (=org.narrow.block=) | =C-x n b= | — | — | Shows only the current block (=org-narrow-to-block=). | |
l10n/Localizable.xcstrings +175
| @@ -7615,6 +7615,41 @@ | ||
| 7615 | 7615 | } |
| 7616 | 7616 | } |
| 7617 | 7617 | }, |
| 7618 | "Close All Folds": { | |
| 7619 | "comment": "Command title", | |
| 7620 | "localizations": { | |
| 7621 | "de": { | |
| 7622 | "stringUnit": { | |
| 7623 | "state": "translated", | |
| 7624 | "value": "Alles einklappen" | |
| 7625 | } | |
| 7626 | }, | |
| 7627 | "es": { | |
| 7628 | "stringUnit": { | |
| 7629 | "state": "translated", | |
| 7630 | "value": "Cerrar todos los pliegues" | |
| 7631 | } | |
| 7632 | }, | |
| 7633 | "fr": { | |
| 7634 | "stringUnit": { | |
| 7635 | "state": "translated", | |
| 7636 | "value": "Fermer tous les plis" | |
| 7637 | } | |
| 7638 | }, | |
| 7639 | "ja": { | |
| 7640 | "stringUnit": { | |
| 7641 | "state": "translated", | |
| 7642 | "value": "すべて折りたたむ" | |
| 7643 | } | |
| 7644 | }, | |
| 7645 | "pt-BR": { | |
| 7646 | "stringUnit": { | |
| 7647 | "state": "translated", | |
| 7648 | "value": "Recolher Todas as Dobras" | |
| 7649 | } | |
| 7650 | } | |
| 7651 | } | |
| 7652 | }, | |
| 7618 | 7653 | "Close Buffer": { |
| 7619 | 7654 | "comment": "Command title", |
| 7620 | 7655 | "localizations": { |
| @@ -14924,6 +14959,41 @@ | ||
| 14924 | 14959 | } |
| 14925 | 14960 | } |
| 14926 | 14961 | }, |
| 14962 | "Hide Next Fold Level": { | |
| 14963 | "comment": "Command title", | |
| 14964 | "localizations": { | |
| 14965 | "de": { | |
| 14966 | "stringUnit": { | |
| 14967 | "state": "translated", | |
| 14968 | "value": "Nächste Gliederungsebene ausblenden" | |
| 14969 | } | |
| 14970 | }, | |
| 14971 | "es": { | |
| 14972 | "stringUnit": { | |
| 14973 | "state": "translated", | |
| 14974 | "value": "Ocultar el siguiente nivel de pliegue" | |
| 14975 | } | |
| 14976 | }, | |
| 14977 | "fr": { | |
| 14978 | "stringUnit": { | |
| 14979 | "state": "translated", | |
| 14980 | "value": "Masquer le niveau de pli suivant" | |
| 14981 | } | |
| 14982 | }, | |
| 14983 | "ja": { | |
| 14984 | "stringUnit": { | |
| 14985 | "state": "translated", | |
| 14986 | "value": "次の階層を隠す" | |
| 14987 | } | |
| 14988 | }, | |
| 14989 | "pt-BR": { | |
| 14990 | "stringUnit": { | |
| 14991 | "state": "translated", | |
| 14992 | "value": "Ocultar Próximo Nível de Dobra" | |
| 14993 | } | |
| 14994 | } | |
| 14995 | } | |
| 14996 | }, | |
| 14927 | 14997 | "Hide Outline": { |
| 14928 | 14998 | "localizations": { |
| 14929 | 14999 | "de": { |
| @@ -22259,6 +22329,41 @@ | ||
| 22259 | 22329 | } |
| 22260 | 22330 | } |
| 22261 | 22331 | }, |
| 22332 | "Open All Folds": { | |
| 22333 | "comment": "Command title", | |
| 22334 | "localizations": { | |
| 22335 | "de": { | |
| 22336 | "stringUnit": { | |
| 22337 | "state": "translated", | |
| 22338 | "value": "Alles aufklappen" | |
| 22339 | } | |
| 22340 | }, | |
| 22341 | "es": { | |
| 22342 | "stringUnit": { | |
| 22343 | "state": "translated", | |
| 22344 | "value": "Abrir todos los pliegues" | |
| 22345 | } | |
| 22346 | }, | |
| 22347 | "fr": { | |
| 22348 | "stringUnit": { | |
| 22349 | "state": "translated", | |
| 22350 | "value": "Ouvrir tous les plis" | |
| 22351 | } | |
| 22352 | }, | |
| 22353 | "ja": { | |
| 22354 | "stringUnit": { | |
| 22355 | "state": "translated", | |
| 22356 | "value": "すべて展開" | |
| 22357 | } | |
| 22358 | }, | |
| 22359 | "pt-BR": { | |
| 22360 | "stringUnit": { | |
| 22361 | "state": "translated", | |
| 22362 | "value": "Expandir Todas as Dobras" | |
| 22363 | } | |
| 22364 | } | |
| 22365 | } | |
| 22366 | }, | |
| 22262 | 22367 | "Open Attachment…": { |
| 22263 | 22368 | "comment": "Command title", |
| 22264 | 22369 | "localizations": { |
| @@ -22364,6 +22469,41 @@ | ||
| 22364 | 22469 | } |
| 22365 | 22470 | } |
| 22366 | 22471 | }, |
| 22472 | "Open Subtree Folds": { | |
| 22473 | "comment": "Command title", | |
| 22474 | "localizations": { | |
| 22475 | "de": { | |
| 22476 | "stringUnit": { | |
| 22477 | "state": "translated", | |
| 22478 | "value": "Teilbaum aufklappen" | |
| 22479 | } | |
| 22480 | }, | |
| 22481 | "es": { | |
| 22482 | "stringUnit": { | |
| 22483 | "state": "translated", | |
| 22484 | "value": "Abrir pliegues del subárbol" | |
| 22485 | } | |
| 22486 | }, | |
| 22487 | "fr": { | |
| 22488 | "stringUnit": { | |
| 22489 | "state": "translated", | |
| 22490 | "value": "Ouvrir les plis du sous-arbre" | |
| 22491 | } | |
| 22492 | }, | |
| 22493 | "ja": { | |
| 22494 | "stringUnit": { | |
| 22495 | "state": "translated", | |
| 22496 | "value": "サブツリーを展開" | |
| 22497 | } | |
| 22498 | }, | |
| 22499 | "pt-BR": { | |
| 22500 | "stringUnit": { | |
| 22501 | "state": "translated", | |
| 22502 | "value": "Expandir Dobras da Subárvore" | |
| 22503 | } | |
| 22504 | } | |
| 22505 | } | |
| 22506 | }, | |
| 22367 | 22507 | "Open after export": { |
| 22368 | 22508 | "localizations": { |
| 22369 | 22509 | "de": { |
| @@ -28904,6 +29044,41 @@ | ||
| 28904 | 29044 | } |
| 28905 | 29045 | } |
| 28906 | 29046 | }, |
| 29047 | "Show Next Fold Level": { | |
| 29048 | "comment": "Command title", | |
| 29049 | "localizations": { | |
| 29050 | "de": { | |
| 29051 | "stringUnit": { | |
| 29052 | "state": "translated", | |
| 29053 | "value": "Nächste Gliederungsebene einblenden" | |
| 29054 | } | |
| 29055 | }, | |
| 29056 | "es": { | |
| 29057 | "stringUnit": { | |
| 29058 | "state": "translated", | |
| 29059 | "value": "Mostrar el siguiente nivel de pliegue" | |
| 29060 | } | |
| 29061 | }, | |
| 29062 | "fr": { | |
| 29063 | "stringUnit": { | |
| 29064 | "state": "translated", | |
| 29065 | "value": "Afficher le niveau de pli suivant" | |
| 29066 | } | |
| 29067 | }, | |
| 29068 | "ja": { | |
| 29069 | "stringUnit": { | |
| 29070 | "state": "translated", | |
| 29071 | "value": "次の階層を表示" | |
| 29072 | } | |
| 29073 | }, | |
| 29074 | "pt-BR": { | |
| 29075 | "stringUnit": { | |
| 29076 | "state": "translated", | |
| 29077 | "value": "Mostrar Próximo Nível de Dobra" | |
| 29078 | } | |
| 29079 | } | |
| 29080 | } | |
| 29081 | }, | |
| 28907 | 29082 | "Show Node Graph": { |
| 28908 | 29083 | "localizations": { |
| 28909 | 29084 | "de": { |