mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fixed an issue where the copy shortcut was not working in the Query Tool data grid. #7920
This commit is contained in:
parent
866db40f48
commit
509c696aa3
@ -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);
|
||||
})
|
||||
];
|
||||
|
||||
|
@ -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 (
|
||||
<RowInfoContext.Provider value={rowInfoValue}>
|
||||
<Row ref={rowRef} onKeyDown={openEditorOnEnter} {...props} />
|
||||
<Row ref={rowRef} onKeyDown={handleKeyDown} {...props} />
|
||||
</RowInfoContext.Provider>
|
||||
);
|
||||
}
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user