@@ -16,7 +16,6 @@ import WebKit
16
16
public struct CodeMirrorView : NativeView {
17
17
@ObservedObject public var vm : CodeMirrorVM
18
18
@Binding var value : String
19
- var prevValue : String = " "
20
19
public init (
21
20
_ viewModel: CodeMirrorVM ,
22
21
value: Binding < String >
@@ -124,14 +123,12 @@ public struct CodeMirrorView: NativeView {
124
123
args: [ : ]
125
124
)
126
125
)
127
- if prevValue != value {
128
- context. coordinator. queueJavascriptFunction (
129
- JavascriptFunction (
130
- functionString: " CodeMirror.setContent(value) " ,
131
- args: [ " value " : value]
132
- )
126
+ context. coordinator. queueJavascriptFunction (
127
+ JavascriptFunction (
128
+ functionString: " CodeMirror.setContent(value) " ,
129
+ args: [ " value " : value]
133
130
)
134
- }
131
+ )
135
132
}
136
133
public func makeCoordinator( ) -> Coordinator {
137
134
let coordinator = Coordinator ( parent: self , viewModel: vm)
@@ -218,10 +215,9 @@ extension Coordinator: WKScriptMessageHandler {
218
215
pageLoaded = true
219
216
callPendingFunctions ( )
220
217
case ScriptMessageName . codeMirrorContentDidChange:
221
- parent. vm. onContentChange ? ( )
222
218
if let messageBody = message. body as? String {
223
219
parent. value = messageBody
224
- parent. prevValue = messageBody
220
+ parent. vm . onContentChange ? ( messageBody)
225
221
}
226
222
default :
227
223
print ( " CodeMirrorWebView receive \( message. name) \( message. body) " )
0 commit comments