Skip to content

Commit 3286b4e

Browse files
Fixed an issue in the query tool where using multiple cursors to copy text resulted in only the first line being copied. #8691
1 parent 63f2c7f commit 3286b4e

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,13 @@ export default class CustomEditorView extends EditorView {
201201
}
202202

203203
getSelection() {
204-
return this.state.selection.ranges.map((range)=>this.state.sliceDoc(range.from, range.to)).join('') ?? '';
204+
return CustomEditorView.getSelectionFromState(this.state);
205+
}
206+
207+
static getSelectionFromState(state) {
208+
// function to get selection from EditorState
209+
const lineSep = state.facet(eol);
210+
return state.selection.ranges.map((range)=>state.sliceDoc(range.from, range.to)).join(lineSep) ?? '';
205211
}
206212

207213
replaceSelection(newValue) {

web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,7 @@ const defaultExtensions = [
157157
}),
158158
autoCompleteCompartment.of([]),
159159
EditorView.clipboardOutputFilter.of((text, state)=>{
160-
const lineSep = state.facet(eol);
161-
// Fetch the primary selection from the editor's current state.
162-
const selection = state.selection.main;
163-
return state.doc.sliceString(selection.from, selection.to, lineSep);
160+
return CustomEditorView.getSelectionFromState(state);
164161
})
165162
];
166163

web/pgadmin/static/js/components/ReactCodeMirror/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu
110110
if (!onTextSelect) return;
111111

112112
const handleSelection = () => {
113-
const selectedText = window.getSelection().toString();
113+
const selectedText = editor.current?.getSelection();
114114
if (selectedText) {
115115
onTextSelect(selectedText);
116116
} else {

0 commit comments

Comments
 (0)