diff --git a/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx b/frontend/src/metabase/query_builder/components/NativeQueryEditor/NativeQueryEditor.tsx
index 9ce8f70a8438455a7fcffb086d728edd5af7f20c..98492cd54b096ea659f8f743072807b94209fca1 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 = {