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() {
|
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) {
|
replaceSelection(newValue) {
|
||||||
|
|
|
@ -157,10 +157,7 @@ const defaultExtensions = [
|
||||||
}),
|
}),
|
||||||
autoCompleteCompartment.of([]),
|
autoCompleteCompartment.of([]),
|
||||||
EditorView.clipboardOutputFilter.of((text, state)=>{
|
EditorView.clipboardOutputFilter.of((text, state)=>{
|
||||||
const lineSep = state.facet(eol);
|
return CustomEditorView.getSelectionFromState(state);
|
||||||
// Fetch the primary selection from the editor's current state.
|
|
||||||
const selection = state.selection.main;
|
|
||||||
return state.doc.sliceString(selection.from, selection.to, lineSep);
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ export default function CodeMirror({className, currEditor, showCopyBtn=false, cu
|
||||||
if (!onTextSelect) return;
|
if (!onTextSelect) return;
|
||||||
|
|
||||||
const handleSelection = () => {
|
const handleSelection = () => {
|
||||||
const selectedText = window.getSelection().toString();
|
const selectedText = editor.current?.getSelection();
|
||||||
if (selectedText) {
|
if (selectedText) {
|
||||||
onTextSelect(selectedText);
|
onTextSelect(selectedText);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue