Fixed an issue in the query tool where using multiple cursors to copy text resulted in only the first line being copied. #8691

pull/8812/head
Pravesh Sharma 2025-05-30 14:45:48 +05:30 committed by GitHub
parent 63f2c7fe00
commit 3286b4e32f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View File

@ -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) {

View File

@ -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);
})
];

View File

@ -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 {