Description
Programmatic updates to SourceEditorState.cursorPositions are never applied to the underlying TextViewController.
In SourceEditor.updateControllerWithState(_:controller:), the new cursor positions are compared with the same state value:
if let cursorPositions = state.cursorPositions, cursorPositions != state.cursorPositions {
controller.setCursorPositions(cursorPositions)
}
Because cursorPositions was just unwrapped from state.cursorPositions, the comparison is always false.
To Reproduce
- Create a
SourceEditor with a binding to SourceEditorState.
- After the editor appears, programmatically assign a different value to
state.cursorPositions.
- Observe that the editor cursor does not move to the requested position.
Expected Behavior
Changing SourceEditorState.cursorPositions should update the cursor positions in the underlying controller.
The comparison likely needs to use the controller's current state:
if let cursorPositions = state.cursorPositions,
cursorPositions != controller.cursorPositions {
controller.setCursorPositions(cursorPositions)
}
Version Information
CodeEditSourceEditor: main, revision 1fa4d3c
macOS: 15.7.9
Xcode: 26.3 (17C529)
Additional Context
No matching open or closed issue was found before filing this report.
Screenshots
Not applicable.
Description
Programmatic updates to
SourceEditorState.cursorPositionsare never applied to the underlyingTextViewController.In
SourceEditor.updateControllerWithState(_:controller:), the new cursor positions are compared with the same state value:Because
cursorPositionswas just unwrapped fromstate.cursorPositions, the comparison is always false.To Reproduce
SourceEditorwith a binding toSourceEditorState.state.cursorPositions.Expected Behavior
Changing
SourceEditorState.cursorPositionsshould update the cursor positions in the underlying controller.The comparison likely needs to use the controller's current state:
Version Information
CodeEditSourceEditor: main, revision 1fa4d3c
macOS: 15.7.9
Xcode: 26.3 (17C529)
Additional Context
No matching open or closed issue was found before filing this report.
Screenshots
Not applicable.