Fixed an issue in the query tool where using multiple cursors to copy text resulted in only the first line being copied. #8691
parent
63f2c7fe00
commit
3286b4e32f
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
];
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue