bito-code-review[bot] commented on code in PR #44858:
URL: https://github.com/apache/superset/pull/44858#discussion_r4153129901
##########
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:
<!-- Bito Reply -->
The suggestion to track the main and modal editors separately is
appropriate. It prevents the modal editor's `onLoad` from overwriting the
`editorRef` used by the main editor, which currently causes the main editor to
become stale when the modal is closed. Applying this change will ensure that
`setValue` calls are correctly routed to the intended editor instance.
--
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]