rusackas commented on code in PR #44858:
URL: https://github.com/apache/superset/pull/44858#discussion_r4153128587


##########
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:
   Same fix as the other `editorRef` thread, split into separate inline/modal 
refs.



##########
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 &&

Review Comment:
   Fixed, `onEditorLoad` now seeds the last-known value from 
`editor.getValue()` instead of the snapshot taken before the async load, so 
that case is not missed.



-- 
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]

Reply via email to