From 3286b4e32faa6770e1699bd30d0a8dd4f47bd72e Mon Sep 17 00:00:00 2001 From: Pravesh Sharma Date: Fri, 30 May 2025 14:45:48 +0530 Subject: [PATCH] Fixed an issue in the query tool where using multiple cursors to copy text resulted in only the first line being copied. #8691 --- .../js/components/ReactCodeMirror/CustomEditorView.js | 8 +++++++- .../js/components/ReactCodeMirror/components/Editor.jsx | 5 +---- .../static/js/components/ReactCodeMirror/index.jsx | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js b/web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js index 5708e1fe5..9144a54cb 100644 --- a/web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js +++ b/web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js @@ -201,7 +201,13 @@ export default class CustomEditorView extends EditorView { } getSelection() { - return this.state.selection.ranges.map((range)=>this.state.sliceDoc(range.from, range.to)).join('') ?? ''; + return CustomEditorView.getSelectionFromState(this.state); + } + + static getSelectionFromState(state) { + // function to get selection from EditorState + const lineSep = state.facet(eol); + return state.selection.ranges.map((range)=>state.sliceDoc(range.from, range.to)).join(lineSep) ?? ''; } replaceSelection(newValue) { diff --git a/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx b/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx index ab8827f62..9676aa1c9 100644 --- a/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx +++ b/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx @@ -157,10 +157,7 @@ const defaultExtensions = [ }), autoCompleteCompartment.of([]), EditorView.clipboardOutputFilter.of((text, state)=>{ - const lineSep = state.facet(eol); - // Fetch the primary selection from the editor's current state. - const selection = state.selection.main; - return state.doc.sliceString(selection.from, selection.to, lineSep); + return CustomEditorView.getSelectionFromState(state); }) ]; diff --git a/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx b/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx index 05615e293..85861db3a 100644 --- a/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx +++ b/web/pgadmin/static/js/components/ReactCodeMirror/index.jsx @@ -110,7 +110,7 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu if (!onTextSelect) return; const handleSelection = () => { - const selectedText = window.getSelection().toString(); + const selectedText = editor.current?.getSelection(); if (selectedText) { onTextSelect(selectedText); } else {