Skip to content

Commit 717e64c

Browse files
committed
Update view when value in text binding changes
1 parent 1fa4d3c commit 717e64c

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

Sources/CodeEditSourceEditor/SourceEditor/SourceEditor.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ public struct SourceEditor: NSViewControllerRepresentable {
155155
controller.configuration = configuration
156156
updateHighlighting(controller, coordinator: context.coordinator)
157157

158+
switch text {
159+
case .storage:
160+
break
161+
case let .binding(text):
162+
controller.textView.setText(text.wrappedValue)
163+
}
164+
158165
controller.reloadUI()
159166
return
160167
}
@@ -204,9 +211,17 @@ public struct SourceEditor: NSViewControllerRepresentable {
204211
/// - Parameter controller: The controller to check.
205212
/// - Returns: True, if the controller's parameters should be updated.
206213
func paramsAreEqual(controller: NSViewControllerType, coordinator: Coordinator) -> Bool {
207-
controller.language.id == language.id &&
208-
controller.configuration == configuration &&
209-
areHighlightProvidersEqual(controller: controller, coordinator: coordinator)
214+
if controller.language.id != language.id ||
215+
controller.configuration != configuration ||
216+
!areHighlightProvidersEqual(controller: controller, coordinator: coordinator) {
217+
return false
218+
}
219+
switch text {
220+
case .storage:
221+
return true
222+
case let .binding(text):
223+
return controller.text == text.wrappedValue
224+
}
210225
}
211226

212227
private func areHighlightProvidersEqual(controller: TextViewController, coordinator: Coordinator) -> Bool {

0 commit comments

Comments
 (0)