Skip to content

Commit

Permalink
feat: support readOnly option of CodeMirror
Browse files Browse the repository at this point in the history
close #7
  • Loading branch information
makhocheung committed Mar 11, 2022
1 parent 91eb30d commit 1acbd51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Sources/CodeMirror-SwiftUI/Representables/CodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public struct CodeView: RepresentableView {
var fontSize: Int
var showInvisibleCharacters: Bool
var lineWrapping: Bool
var readOnly: String

var onLoadSuccess: (() -> ())?
var onLoadFail: ((Error) -> ())?
Expand All @@ -41,13 +42,16 @@ public struct CodeView: RepresentableView {
mode: Mode,
fontSize: Int = 12,
showInvisibleCharacters: Bool = true,
lineWrapping: Bool = true) {
lineWrapping: Bool = true,
readOnly: String = "false"
) {
self._code = code
self.mode = mode
self.theme = theme
self.fontSize = fontSize
self.showInvisibleCharacters = showInvisibleCharacters
self.lineWrapping = lineWrapping
self.readOnly = readOnly
}


Expand Down Expand Up @@ -150,7 +154,7 @@ extension CodeView {
context.coordinator.setFontSize(fontSize)
context.coordinator.setShowInvisibleCharacters(showInvisibleCharacters)
context.coordinator.setLineWrapping(lineWrapping)

context.coordinator.setReadonly(readOnly)
return webView
}

Expand All @@ -163,6 +167,7 @@ extension CodeView {
context.coordinator.setFontSize(fontSize)
context.coordinator.setShowInvisibleCharacters(showInvisibleCharacters)
context.coordinator.setLineWrapping(lineWrapping)
context.coordinator.setReadonly(readOnly)
}

func updateWhatsNecessary(elementGetter: (JavascriptCallback?) -> Void,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extension CodeViewController {
setMimeType("application/json")
}

func setReadonly(_ value: Bool) {
func setReadonly(_ value: String) {
callJavascript(javascriptString: "SetReadOnly(\(value));")
}

Expand Down

0 comments on commit 1acbd51

Please sign in to comment.