Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix right click copy issue in data grid #17722

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Changes from 2 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
20 changes: 20 additions & 0 deletions src/views/htmlcontent/src/js/components/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,31 @@ export class AppComponent implements OnInit, AfterViewChecked {
openContextMenu(event: MouseEvent, batchId, resultId, index): void {
let selection: ISlickRange[] = this.slickgrids.toArray()[index].getSelectedRanges();
selection = this.tryCombineSelectionsForResults(selection);

let grid = this.slickgrids.toArray()[index]._grid;
let contextMenuCell = grid.getCellFromEvent(event);
if (contextMenuCell || grid.canCellBeActive(contextMenuCell.row, contextMenuCell.cell)) {
if (selection.length === 0 || !this.isContextMenuCellWIthinSelection(selection, contextMenuCell)) {
selection = [new Slick.Range(contextMenuCell.row, contextMenuCell.cell - 1, contextMenuCell.row, contextMenuCell.cell - 1)];
grid.setActiveCell(contextMenuCell.row, contextMenuCell.cell)
lewis-sanchez marked this conversation as resolved.
Show resolved Hide resolved
}
}

this.contextMenu.show(event.clientX, event.clientY, batchId, resultId, index, selection);
event.preventDefault();
event.stopPropagation();
}

private isContextMenuCellWIthinSelection(selections: ISlickRange[], contextMenuCell: {row: number, cell: number}): boolean {
for (const selection of selections) {
if (selection.fromRow <= contextMenuCell.row && selection.toRow >= contextMenuCell.row && selection.fromCell <= contextMenuCell.cell - 1 && selection.toCell >= contextMenuCell.cell - 1) {
return true;
}
}

return false;
}

private tryCombineSelectionsForResults(selections: ISlickRange[]): ISlickRange[] {
// need to take row number column in to consideration.
return this.tryCombineSelections(selections).map(range => {
Expand Down