File tree Expand file tree Collapse file tree 7 files changed +37
-3
lines changed
Expand file tree Collapse file tree 7 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ struct ContentView: View {
1818 @State var value : String = jsonString
1919 @State var lineWrapping = false
2020 @State var lineNumber = true
21+ @State var highlightActiveLine = true
2122 @State var foldGutter = false
2223 @State var readOnly = false
2324 @State var language : Language = . html
@@ -43,6 +44,7 @@ struct ContentView: View {
4344 . cmReadOnly ( $readOnly)
4445 . cmLanguage ( $language)
4546 . cmEnabledSearch ( $enabledSearch)
47+ . cmHighlightActiveLine ( $highlightActiveLine)
4648 . cmTheme ( $theme)
4749 . onLoadSuccess ( ) {
4850 print ( " Hello! " )
@@ -68,6 +70,8 @@ struct ContentView: View {
6870 . toggleStyle ( . checkbox)
6971 Toggle ( isOn: $enabledSearch, label: { Text ( " Enabled Search " ) } )
7072 . toggleStyle ( . checkbox)
73+ Toggle ( isOn: $highlightActiveLine, label: { Text ( " Highlight Active Line " ) } )
74+ . toggleStyle ( . checkbox)
7175 } label: {
7276 Image ( systemName: " gearshape.fill " )
7377 . font ( . system( size: 18 ) )
Original file line number Diff line number Diff line change @@ -149,11 +149,19 @@ struct ContentView: View {
149149 @State var value: String = " "
150150 var body: some View {
151151 CodeMirror (value : $value)
152- .cmEnabledSearch ($enabledSearch )
152+ .cmEnabledSearch (. constant ( false ) )
153153 }
154154}
155155```
156156
157+
158+ ** Set enabled search**
159+
160+ ``` swift
161+ CodeMirror (value : $value)
162+ .cmHighlightActiveLine (.constant (false ))
163+ ```
164+
157165** Set Programming Language**
158166
159167``` swift
Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ public struct CodeMirror: View {
2525 }
2626 }
2727 /// Set Line Wrapping
28+ public func cmHighlightActiveLine( _ value: Binding < Bool > ) -> CodeMirror {
29+ vm. highlightActiveLine = value. wrappedValue
30+ return self as CodeMirror
31+ }
32+ /// Set Line Wrapping
2833 public func cmLineWrapping( _ value: Binding < Bool > ) -> CodeMirror {
2934 vm. lineWrapping = value. wrappedValue
3035 return self as CodeMirror
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import UIKit // iOS / iPadOS
1717public class CodeMirrorVM : ObservableObject {
1818 @Published public var lineWrapping = false
1919 @Published public var lineNumber = true
20+ @Published public var highlightActiveLine = true
2021 @Published public var foldGutter = false
2122 @Published public var readOnly = false
2223 @Published public var enabledSearch = false
@@ -35,6 +36,7 @@ public class CodeMirrorVM: ObservableObject {
3536 public init (
3637 lineWrapping: Bool = false ,
3738 lineNumber: Bool = true ,
39+ highlightActiveLine: Bool = true ,
3840 foldGutter: Bool = false ,
3941 readOnly: Bool = false ,
4042 enabledSearch: Bool = false ,
@@ -44,6 +46,7 @@ public class CodeMirrorVM: ObservableObject {
4446 ) {
4547 self . lineWrapping = lineWrapping
4648 self . lineNumber = lineNumber
49+ self . highlightActiveLine = highlightActiveLine
4750 self . foldGutter = foldGutter
4851 self . readOnly = readOnly
4952 self . enabledSearch = enabledSearch
Original file line number Diff line number Diff line change @@ -99,6 +99,12 @@ public struct CodeMirrorView: NativeView {
9999 args: [ " value " : vm. readOnly]
100100 )
101101 )
102+ context. coordinator. queueJavascriptFunction (
103+ JavascriptFunction (
104+ functionString: " CodeMirror.setHighlightActiveLine(value) " ,
105+ args: [ " value " : vm. highlightActiveLine]
106+ )
107+ )
102108 context. coordinator. queueJavascriptFunction (
103109 JavascriptFunction (
104110 functionString: " CodeMirror.setEnabledSearch(value) " ,
Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ const lineNumber = new Compartment();
141141const foldGutterComp = new Compartment ( ) ;
142142const searchKeymapComp = new Compartment ( ) ;
143143const placeholderComp = new Compartment ( ) ;
144+ const highlightActiveLineComp = new Compartment ( ) ;
144145
145146const editorView = new CodeMirror . EditorView ( {
146147 doc : "" ,
@@ -157,7 +158,6 @@ const editorView = new CodeMirror.EditorView({
157158 autocompletion ( ) ,
158159 rectangularSelection ( ) ,
159160 crosshairCursor ( ) ,
160- highlightActiveLine ( ) ,
161161 highlightSelectionMatches ( ) ,
162162 keymap . of ( [
163163 ...closeBracketsKeymap ,
@@ -167,6 +167,7 @@ const editorView = new CodeMirror.EditorView({
167167 ...completionKeymap ,
168168 indentWithTab ,
169169 ] ) ,
170+ highlightActiveLineComp . of ( [ ] ) ,
170171 placeholderComp . of ( [ ] ) ,
171172 searchKeymapComp . of ( [ ] ) ,
172173 foldGutterComp . of ( [ ] ) ,
@@ -259,6 +260,12 @@ function setEnabledSearch(enabled) {
259260 } ) ;
260261}
261262
263+ function setHighlightActiveLine ( enabled ) {
264+ editorView . dispatch ( {
265+ effects : highlightActiveLineComp . reconfigure ( enabled ? [ highlightActiveLine ( ) ] : [ ] ) ,
266+ } ) ;
267+ }
268+
262269function setFoldGutter ( enabled ) {
263270 editorView . dispatch ( {
264271 effects : foldGutterComp . reconfigure ( enabled ? foldGutter ( ) : [ ] ) ,
@@ -284,6 +291,7 @@ export {
284291 setTheme ,
285292 setLineWrapping ,
286293 setLineNumber ,
294+ setHighlightActiveLine ,
287295 setFoldGutter ,
288296 setEnabledSearch ,
289297 setFocus ,
You can’t perform that action at this time.
0 commit comments