diff --git a/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx b/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx index 1c27170a2b2..c581f943c36 100644 --- a/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx +++ b/web/pgadmin/static/js/components/ReactCodeMirror/components/Editor.jsx @@ -150,7 +150,9 @@ const defaultExtensions = [ autoCompleteCompartment.of([]), EditorView.clipboardOutputFilter.of((text, state)=>{ const lineSep = state.facet(eol); - return state.doc.sliceString(0, text.length, lineSep); + // Fetch the primary selection from the editor's current state. + const selection = state.selection.main; + return state.doc.sliceString(selection.from, selection.to, lineSep); }) ]; diff --git a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx index 6c3be1e6e1a..1ecb657e320 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/index.jsx @@ -89,6 +89,15 @@ const StyledPgReactDataGrid = styled(PgReactDataGrid)(({theme})=>({ export const RowInfoContext = React.createContext(); export const DataGridExtrasContext = React.createContext(); +function getCopyShortcutHandler(handleCopy) { + return (e)=>{ + if((e.ctrlKey || e.metaKey) && e.key !== 'Control' && e.keyCode == 67) { + e.preventDefault(); + handleCopy(); + } + }; +} + function CustomRow(props) { const rowRef = useRef(); const dataGridExtras = useContext(DataGridExtrasContext); @@ -104,14 +113,17 @@ function CustomRow(props) { } else if(props.selectedCellIdx == 0) { dataGridExtras.onSelectedCellChange?.(null); } - const openEditorOnEnter = (e)=>{ + const handleKeyDown = (e)=>{ + const handleCopyShortcut = getCopyShortcutHandler(dataGridExtras.handleCopy); + // Invokes the copy handler. + handleCopyShortcut(e); if(e.code === 'Enter' && !props.isRowSelected && props.selectedCellIdx > 0) { props.selectCell(props.row, props.viewportColumns?.find(columns => columns.idx === props.selectedCellIdx), true); } }; return ( - + ); } @@ -125,14 +137,6 @@ CustomRow.propTypes = { selectCell: PropTypes.func, }; -function getCopyShortcutHandler(handleCopy) { - return (e)=>{ - if((e.ctrlKey || e.metaKey) && e.key !== 'Control' && e.keyCode == 67) { - handleCopy(); - } - }; -} - function SelectAllHeaderRenderer({isCellSelected}) { const [isRowSelected, onRowSelectionChange] = useRowSelection(); const cellRef = useRef();