Skip to content

Commit a2ae4bb

Browse files
committed
fix(menu): remove unused code in Context Menu to select cell
- the call to the `setActiveCell()` is actually not working there, it should be called after the menu is shown, not after doing the action which is too late
1 parent d0b4820 commit a2ae4bb

File tree

2 files changed

+1
-11
lines changed

2 files changed

+1
-11
lines changed

src/app/modules/angular-slickgrid/extensions/__tests__/contextMenuExtension.spec.ts

-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import { Column, DelimiterType, FileType, GridOption, MenuCommandItem, MenuComma
99
import { Formatters } from '../../formatters';
1010

1111
declare var Slick: any;
12-
13-
const gridId = 'grid1';
1412
const gridUid = 'slickgrid_124343';
15-
const containerId = 'demo-container';
1613

1714
const excelExportServiceStub = {
1815
exportToExcel: jest.fn(),
@@ -546,7 +543,6 @@ describe('contextMenuExtension', () => {
546543
});
547544

548545
it('should call "copyToClipboard", without export formatter, when the command triggered is "copy"', () => {
549-
const setActiveCellSpy = jest.spyOn(SharedService.prototype.grid, 'setActiveCell');
550546
const copyGridOptionsMock = { ...gridOptionsMock, enableExcelExport: false, enableExport: false, contextMenu: { hideCopyCellValueCommand: false } } as GridOption;
551547
const columnMock = { id: 'firstName', name: 'First Name', field: 'firstName' } as Column;
552548
const dataContextMock = { id: 123, firstName: 'John', lastName: 'Doe', age: 50 };
@@ -567,12 +563,10 @@ describe('contextMenuExtension', () => {
567563
value: 'John'
568564
});
569565

570-
expect(setActiveCellSpy).toHaveBeenCalledWith(5, 2, false);
571566
expect(execSpy).toHaveBeenCalledWith('copy', false, 'John');
572567
});
573568

574569
it('should call "copyToClipboard", WITH export formatter, when the command triggered is "copy"', () => {
575-
const setActiveCellSpy = jest.spyOn(SharedService.prototype.grid, 'setActiveCell');
576570
const copyGridOptionsMock = { ...gridOptionsMock, enableExcelExport: false, enableExport: false, exportOptions: { exportWithFormatter: true } } as GridOption;
577571
const columnMock = { id: 'firstName', name: 'First Name', field: 'firstName', formatter: Formatters.uppercase } as Column;
578572
const dataContextMock = { id: 123, firstName: 'John', lastName: 'Doe', age: 50 };
@@ -592,7 +586,6 @@ describe('contextMenuExtension', () => {
592586
value: 'John'
593587
});
594588

595-
expect(setActiveCellSpy).toHaveBeenCalledWith(5, 2, false);
596589
expect(execSpy).toHaveBeenCalledWith('copy', false, 'JOHN');
597590
});
598591

src/app/modules/angular-slickgrid/extensions/contextMenuExtension.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,7 @@ export class ContextMenuExtension implements Extension {
181181
command: commandName,
182182
positionOrder: 50,
183183
action: (e: Event, args: MenuCommandItemCallbackArgs) => {
184-
if (args && args.hasOwnProperty('cell') && args.hasOwnProperty('row')) {
185-
this.sharedService.grid.setActiveCell(args.row, args.cell, false); // select the cell that the click originated
186-
this.copyToClipboard(args);
187-
}
184+
this.copyToClipboard(args);
188185
},
189186
itemUsabilityOverride: (args: MenuCallbackArgs) => {
190187
// make sure there's an item to copy before enabling this command

0 commit comments

Comments
 (0)