Fixed an issue where the copy shortcut was not working in the Query Tool data grid. #7920

This commit is contained in:
Rohit Bhati 2024-10-09 17:06:51 +05:30 committed by GitHub
parent 866db40f48
commit 509c696aa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 11 deletions

View File

@ -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);
})
];

View File

@ -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();