Commit 745599e8e9
Copy SHA
745599e8e905766da00da4d49c9b867ba4d6efb5
parent: 4c75f0eea5
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-09 01:09 UTC
Highlight src blocks in the iOS editor
OrgstarMobile depends on OrgHighlight; the tree-sitter targets build for
iOS as they are. The syntax category to theme key mapping moves to
OrgPresentation for both editors.
Changed files (5)
Package.swift
+1 −1 · view
@@ -84,7 +84,7 @@ let package = Package(
84 . target ( name : " OrgApp " , dependencies : [ " OrgWorkspace " , " OrgDocument " , " OrgPresentation " ] ) ,
84 . target ( name : " OrgApp " , dependencies : [ " OrgWorkspace " , " OrgDocument " , " OrgPresentation " ] ) ,
85 . executableTarget ( name : " Orgstar " , dependencies : [ " OrgApp " , " OrgEditorAppKit " , " OrgHighlight " ] ) ,
85 . executableTarget ( name : " Orgstar " , dependencies : [ " OrgApp " , " OrgEditorAppKit " , " OrgHighlight " ] ) ,
86 // T h e i O S a p p , b u n d l e d b y s c r i p t s / b u i l d - i o s - a p p . s h .
86 // T h e i O S a p p , b u n d l e d b y s c r i p t s / b u i l d - i o s - a p p . s h .
87 . executableTarget ( name : " OrgstarMobile " , dependencies : [ " OrgApp " ] ) ,
87 . executableTarget ( name : " OrgstarMobile " , dependencies : [ " OrgApp " , " OrgHighlight " ] ) ,
88 // A p p e x t e n s i o n s , b u n d l e d i n t o O r g s t a r . a p p b y s c r i p t s / b u i l d - a p p . s h .
88 // A p p e x t e n s i o n s , b u n d l e d i n t o O r g s t a r . a p p b y s c r i p t s / b u i l d - a p p . s h .
89 . executableTarget ( name : " OrgstarQuickLook " , dependencies : [ " OrgCore " ] , linkerSettings : extensionEntry ) ,
89 . executableTarget ( name : " OrgstarQuickLook " , dependencies : [ " OrgCore " ] , linkerSettings : extensionEntry ) ,
90 . executableTarget ( name : " OrgstarSpotlight " , dependencies : [ " OrgCore " ] , linkerSettings : extensionEntry ) ,
90 . executableTarget ( name : " OrgstarSpotlight " , dependencies : [ " OrgCore " ] , linkerSettings : extensionEntry ) ,
Sources/OrgEditorAppKit/Theme.swift
+1 −15 · view
@@ -118,21 +118,7 @@ struct Theme {
118 case . block :
118 case . block :
119 break
119 break
120 case . syntax ( let category ) :
120 case . syntax ( let category ) :
121 if let key = Self . slot ( category ) { fg ( key ) }
121 if let key = category . themeKey { fg ( key ) }
122 }
123 }
124
125 static func slot ( _ category : SyntaxCategory ) -> String ? {
126 switch category {
127 case . keyword : " syntax-keyword "
128 case . string : " syntax-string "
129 case . comment : " syntax-comment "
130 case . function : " syntax-function "
131 case . type : " syntax-type "
132 case . number , . constant , . escape : " syntax-number "
133 case . property , . attribute , . tag : " syntax-property "
134 case . label : " syntax-label "
135 case . variable , . operator , . punctuation : nil
136 }
122 }
137 }
123 }
138
124
Sources/OrgPresentation/Presentation.swift
+18 −1 · view
@@ -51,7 +51,24 @@ public enum SyntaxCategory: String, Hashable, Sendable, CaseIterable {
51 }
51 }
52 }
52 }
53
53
54 // / H i g h l i g h t s s o u r c e c o d e ; t h e p l a t f o r m s u p p l i e s o n e ( t r e e - s i t t e r o n m a c O S ; i O S s u p p l i e s n o n e ) .
54 extension SyntaxCategory {
55 // / T h e t h e m e c o l o r f o r t h i s k i n d o f t o k e n ; n i l f o r t h o s e d r a w n i n t h e t e x t c o l o r .
56 public var themeKey : String ? {
57 switch self {
58 case . keyword : " syntax-keyword "
59 case . string : " syntax-string "
60 case . comment : " syntax-comment "
61 case . function : " syntax-function "
62 case . type : " syntax-type "
63 case . number , . constant , . escape : " syntax-number "
64 case . property , . attribute , . tag : " syntax-property "
65 case . label : " syntax-label "
66 case . variable , . operator , . punctuation : nil
67 }
68 }
69 }
70
71 // / H i g h l i g h t s s o u r c e c o d e ; t h e a p p s s u p p l y t r e e - s i t t e r ' s ( O r g H i g h l i g h t ) .
55 public protocol CodeHighlighter : Sendable {
72 public protocol CodeHighlighter : Sendable {
56 // / C a t e g o r i e s f o r r a n g e s o f ` c o d e ` , i n U T F - 1 6 o f f s e t s ; l a t e r r u n s w i n o v e r e a r l i e r o n e s .
73 // / C a t e g o r i e s f o r r a n g e s o f ` c o d e ` , i n U T F - 1 6 o f f s e t s ; l a t e r r u n s w i n o v e r e a r l i e r o n e s .
57 // / E m p t y f o r l a n g u a g e s i t d o e s n ' t k n o w .
74 // / E m p t y f o r l a n g u a g e s i t d o e s n ' t k n o w .
Sources/OrgstarMobile/MobileEditor.swift
+4 −1 · view
@@ -1,6 +1,7 @@
1 #if os ( iOS )
1 #if os ( iOS )
2 import OrgCore
2 import OrgCore
3 import OrgDocument
3 import OrgDocument
4 import OrgHighlight
4 import OrgPresentation
5 import OrgPresentation
5 import UIKit
6 import UIKit
6
7
@@ -96,6 +97,8 @@ final class KeyedTextView: UITextView {
96 // / f o l d a s T A B c y c l e s t h e m .
97 // / f o l d a s T A B c y c l e s t h e m .
97 @ MainActor
98 @ MainActor
98 final class MobileEditor : NSObject , DocumentBuffer {
99 final class MobileEditor : NSObject , DocumentBuffer {
100 // / O n e h i g h l i g h t e r f o r e v e r y e d i t o r a n d t h e r e a d e r : i t c a c h e s c o m p i l e d g r a m m a r s a n d r e s u l t s .
101 static let highlighter = TreeSitterHighlighter ( )
99 private ( set ) var document : DocumentState
102 private ( set ) var document : DocumentState
100 let textView : UITextView
103 let textView : UITextView
101 var options : EditingOptions = . org {
104 var options : EditingOptions = . org {
@@ -555,7 +558,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
555 }
558 }
556 let revealed = caretLine
559 let revealed = caretLine
557 var scriptExclusions : [ Range < Int > ] = [ ]
560 var scriptExclusions : [ Range < Int > ] = [ ]
558 for run in Presentation . styles ( document . tree , in : whole ) {
561 for run in Presentation . styles ( document . tree , in : whole , highlighter : Self . highlighter ) {
559 let clipped = NSIntersectionRange ( NSRange ( run . range ) , lines )
562 let clipped = NSIntersectionRange ( NSRange ( run . range ) , lines )
560 guard clipped . length > 0 else { continue }
563 guard clipped . length > 0 else { continue }
561 if Presentation . skipsLeadingStars ( run . role , indented : indented , hideStars : hideStars ) { continue }
564 if Presentation . skipsLeadingStars ( run . role , indented : indented , hideStars : hideStars ) { continue }
Sources/OrgstarMobile/MobileTheme.swift
+2 −1 · view
@@ -115,7 +115,8 @@ struct MobileTheme {
115 case . footnote , . cookie , . target , . macro , . latex : fg ( " special " )
115 case . footnote , . cookie , . target , . macro , . latex : fg ( " special " )
116 case . table , . rule : fg ( " table " )
116 case . table , . rule : fg ( " table " )
117 case . block : break
117 case . block : break
118 case . syntax : break
118 case . syntax ( let category ) :
119 if let key = category . themeKey { fg ( key ) }
119 }
120 }
120 }
121 }
121
122