Skip to content

Commit 4ee6bd6

Browse files
Update text in updateNSViewController when binding changes externally
1 parent 6f32016 commit 4ee6bd6

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Sources/CodeEditSourceEditor/SourceEditor/SourceEditor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ public struct SourceEditor: NSViewControllerRepresentable {
138138
if context.coordinator.isUpdateFromTextView {
139139
context.coordinator.isUpdateFromTextView = false
140140
} else {
141+
// Update text if it changed externally (e.g. switching files)
142+
if case .binding(let binding) = text, controller.textView.string != binding.wrappedValue {
143+
controller.textView.setText(binding.wrappedValue)
144+
}
141145
context.coordinator.isUpdatingFromRepresentable = true
142146
updateControllerWithState(state, controller: controller)
143147
context.coordinator.isUpdatingFromRepresentable = false

0 commit comments

Comments
 (0)