bito-code-review[bot] commented on code in PR #44858:
URL: https://github.com/apache/superset/pull/44858#discussion_r4152092436
##########
superset-frontend/src/explore/components/controls/TextAreaControl.tsx:
##########
@@ -157,6 +175,27 @@ function TextAreaControl({
[hotkeys],
);
+ // Pick up an `initialValue` change that didn't originate from this
+ // editor's own typing (handleChange above would have already updated
+ // lastEditorValueRef for that case), without remounting the Ace instance
+ // or losing the user's current cursor position.
+ useEffect(() => {
+ const nextValue = initialValue ?? value;
+ const editor = editorRef.current;
+ if (
+ editor &&
+ nextValue !== undefined &&
+ nextValue !== lastEditorValueRef.current &&
+ nextValue !== editor.getValue()
+ ) {
+ const cursorPos = editor.getCursorPosition();
+ editor.setValue(nextValue, 1);
+ editor.clearSelection();
+ editor.moveCursorToPosition(cursorPos);
+ lastEditorValueRef.current = nextValue;
+ }
+ }, [initialValue, value]);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>shared editorRef syncs wrong editor</b></div>
<div id="fix">
`onEditorLoad` (line 166) sets the single `editorRef.current`, but both the
main editor (line 307) and the modal editor (line 298) pass it. antd `Modal`
mounts children lazily, so after the user opens 'Edit in modal' once, the modal
editor's `onLoad` overwrites `editorRef`. The new sync `useEffect` then calls
`setValue` on the hidden modal editor, leaving the visible main editor stale.
Track the two editors separately and sync the main one.
</div>
</div>
<small><i>Code Review Run #6ca0d0</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]