CodeMirror-SwiftUI is a lightweight wrapper of CodeMirror for macOS and iOS packaged for SwiftUI.
CodeMirror-SwiftUI is a lightweight wrapper of CodeMirror for macOS and iOS packaged for SwiftUI.
This package is a fork from CodeMirror-Swift
CodeMirror-SwiftUI is available via Swift Package Manager
Using Xcode 12, go to File -> Swift Packages -> Add Package Dependency
and enter https://github.com/Pictarine/CodeMirror-SwiftUI
CodeMirror
gives you access to a new view called CodeView
. It can be integrated within your view body
like this :
CodeView(theme: themes[selectedTheme],
code: $codeBlock,
mode: codeMode,
fontSize: fontSize,
showInvisibleCharacters: showInvisibleCharacters,
lineWrapping: lineWrapping)
.onLoadSuccess {
print("Loaded")
}
.onContentChange { newCodeBlock in
print("Content Change")
}
.onLoadFail { error in
print("Load failed : \(error.localizedDescription)")
}
CodeView has multiple params:
Parameter name | Optional | Type | Default |
---|---|---|---|
code | false | Binding<String> | |
mode | false | Mode | |
theme | true | CodeViewTheme | .materialPalenight |
fontSize | true | Int | 12 (px) |
showInvisibleCharacters | true | Bool | true |
lineWrapping | true | Bool | true |
CodeView comes with three modifiers
onLoadSuccess { ... }
onLoadFail { ... }
onContentChange { ... }
macOS Demo and iOS Demo are available
Snip, a snippet manager for macOS is also using CodeMirror-SwiftUI
CodeMirror-SwiftUI is available under the MIT license. See the LICENSE file for more info.