Commit 4c5cffea2e
4c5cffea2ef818579742f4e22c1374ee3d5d615e
parent: a0be649141
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-13 00:45 UTC
Tabs stop every 8 columns from the line's start, as in Emacs
Layout: unified · split
Sources/OrgEditorAppKit/Theme.swift
+3
| @@ -68,6 +68,9 @@ struct Theme { |
| 68 | 68 | style.firstLineHeadIndent = CGFloat(firstLine) * column |
| 69 | 69 | style.headIndent = CGFloat(wrapped) * column |
| 70 | 70 | style.lineSpacing = CGFloat(max(0, spec.lineSpacing)) |
| 71 | // `tab-width` 8, counted from the line's own start, past org-indent's indentation. |
| 72 | style.defaultTabInterval = 8 * column |
| 73 | style.tabStops = (1...32).map { NSTextTab(textAlignment: .left, location: style.firstLineHeadIndent + CGFloat($0 * 8) * column) } |
| 71 | 74 | return style |
| 72 | 75 | } |
| 73 | 76 | |
Sources/OrgstarMobile/MobileTheme.swift
+3
| @@ -74,6 +74,9 @@ struct MobileTheme { |
| 74 | 74 | style.firstLineHeadIndent = CGFloat(firstLine) * column |
| 75 | 75 | style.headIndent = CGFloat(wrapped) * column |
| 76 | 76 | style.lineSpacing = CGFloat(max(0, spec.lineSpacing)) |
| 77 | // `tab-width` 8, counted from the line's own start, past org-indent's indentation. |
| 78 | style.defaultTabInterval = 8 * column |
| 79 | style.tabStops = (1...32).map { NSTextTab(textAlignment: .left, location: style.firstLineHeadIndent + CGFloat($0 * 8) * column) } |
| 77 | 80 | return style |
| 78 | 81 | } |
| 79 | 82 | |
Tests/OrgEditorAppKitTests/TabTests.swift
added
+26
| @@ -0,0 +1,26 @@ |
| 1 | import AppKit |
| 2 | import OrgDocument |
| 3 | import Testing |
| 4 | @testable import OrgEditorAppKit |
| 5 | |
| 6 | /// Tabs stop every 8 columns from the line's start, as `tab-width` 8 does in Emacs, so text |
| 7 | /// aligned with spaces under a tab-indented line stays aligned. |
| 8 | @MainActor |
| 9 | struct TabTests { |
| 10 | static let text = "* Lists\n\t1. Spelling and\n vice-versa.\n\t\ta. Design\n should\n" |
| 11 | |
| 12 | func x(_ h: Harness, _ needle: String) -> CGFloat { |
| 13 | h.layout() |
| 14 | let offset = (Self.text as NSString).range(of: needle).location |
| 15 | return h.textView.firstRect(forCharacterRange: NSRange(location: offset, length: 1), actualRange: nil).minX |
| 16 | } |
| 17 | |
| 18 | @Test(arguments: [true, false]) func tabsAreEightColumns(indented: Bool) { |
| 19 | let h = Harness(DocumentState(bytes: Array(Self.text.utf8)), layout: false) |
| 20 | h.editor.indented = indented |
| 21 | h.editor.restyleOutsideEditing(0..<(Self.text as NSString).length) |
| 22 | h.drainStyling() |
| 23 | #expect(abs(x(h, "Spelling") - x(h, "vice")) < 1) |
| 24 | #expect(abs(x(h, "Design") - x(h, "should")) < 1) |
| 25 | } |
| 26 | } |