From e840233a4f950d0180333c213fa8b6478b391852 Mon Sep 17 00:00:00 2001
From: Romeo Van Snick <romeo@romeovansnick.be>
Date: Tue, 5 Nov 2024 18:00:10 +1100
Subject: [PATCH] Add custom selectionchange handler (#49511)

---
 .../components/NativeQueryEditor/NativeQueryEditor.tsx    | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx
index 9ce8f70a843..98492cd54b0 100644
--- a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx
+++ b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx
@@ -360,6 +360,12 @@ export class NativeQueryEditor extends Component<
     100,
   );
 
+  handleSelectionChange = () => {
+    if (this._editor && this.props.setNativeEditorSelectedRange) {
+      this.props.setNativeEditorSelectedRange(this._editor.getSelectionRange());
+    }
+  };
+
   handleKeyDown = (e: KeyboardEvent) => {
     const { isRunning, cancelQuery, enableRun } = this.props;
 
@@ -421,7 +427,7 @@ export class NativeQueryEditor extends Component<
     // listen to onChange events
     editor.getSession().on("change", this.onChange);
     editor.getSelection().on("changeCursor", this.handleCursorChange);
-    editor.getSelection().on("changeSelection", this.handleCursorChange);
+    editor.getSelection().on("changeSelection", this.handleSelectionChange);
 
     const minLineNumberWidth = 20;
     editor.getSession().gutterRenderer = {
-- 
GitLab