Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
];

Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/static/js/components/ReactCodeMirror/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading