Skip to content

Commit

Permalink
Fixed an issue where the copy shortcut was not working in the Query T…
Browse files Browse the repository at this point in the history
…ool data grid. #7920
  • Loading branch information
RohitBhati8269 authored Oct 9, 2024
1 parent 866db40 commit 509c696
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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>
);
}
Expand All @@ -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();
Expand Down

0 comments on commit 509c696

Please sign in to comment.