Skip to content

Commit d1132c9

Browse files
authored
Fix: CellExternalCopyManager plugin restores focus on paste (#1011)
* fix: SlickCellExternalCopyManager plugin restores focus on paste
1 parent ee22b59 commit d1132c9

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
describe('Example - Excel-compatible spreadsheet and Cell Selection', { retries: 0 }, () => {
2+
const cellHeight = 25;
3+
4+
it('should load Example', () => {
5+
cy.visit(`${Cypress.config('baseUrl')}/examples/example-excel-compatible-spreadsheet.html`);
6+
});
7+
8+
it('should click on cell B2, copy value, ArrowDown, paste value, ArrowRight, and expect to be in column C', () => {
9+
cy.getCell(2, 2, '', { parentSelector: "#myGrid", rowHeight: cellHeight })
10+
.as('cell_B2')
11+
.click();
12+
13+
cy.get(".slick-cell.active")
14+
.realPress(["Control", "C"]);
15+
16+
cy.get(".slick-cell.active")
17+
.type('{downarrow}');
18+
19+
cy.get(".slick-cell.active")
20+
.realPress(["Control", "V"]);
21+
22+
cy.get(".slick-cell.active")
23+
.type('{rightarrow}');
24+
25+
cy.get('#myGrid .slick-cell.l3.r3.selected')
26+
.should('have.length', 1);
27+
28+
cy.getCell(3, 2, '', { parentSelector: "#myGrid", rowHeight: cellHeight })
29+
.should('have.text', '3');
30+
});
31+
});

cypress/support/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// -- This will overwrite an existing command --
2525
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
2626
import '@4tw/cypress-drag-drop';
27+
import "cypress-real-events";
2728
import { convertPosition } from './common';
2829

2930
declare global {

cypress/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"allowSyntheticDefaultImports": true,
55
"esModuleInterop": true,
66
"lib": ["es5", "dom"],
7-
"types": ["@4tw/cypress-drag-drop", "cypress", "node"],
7+
"types": ["@4tw/cypress-drag-drop", "cypress", "node", "cypress-real-events"],
88
"jsx": "preserve"
99
},
1010
"include": ["**/*.ts"]

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"cssnano": "^6.1.2",
8181
"cssnano-preset-lite": "^3.1.0",
8282
"cypress": "^13.7.2",
83+
"cypress-real-events": "^1.12.0",
8384
"dotenv": "^16.4.5",
8485
"esbuild": "^0.20.2",
8586
"eslint": "^8.57.0",

src/plugins/slick.cellexternalcopymanager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,13 @@ export class SlickCellExternalCopyManager implements SlickPlugin {
449449
(e.which === this.keyCodes.V && (e.ctrlKey || e.metaKey) && !e.shiftKey)
450450
|| (e.which === this.keyCodes.INSERT && e.shiftKey && !e.ctrlKey)
451451
)) { // CTRL+V or Shift+INS
452+
const focusEl = document.activeElement as HTMLElement;
452453
const ta = this._createTextBox('');
453-
setTimeout(() => this._decodeTabularData(this._grid, ta), 100);
454+
setTimeout(() => {
455+
this._decodeTabularData(this._grid, ta);
456+
// restore focus when possible
457+
focusEl?.focus();
458+
}, this._options?.clipboardPasteDelay ?? CLIPBOARD_PASTE_DELAY);
454459
return false;
455460
}
456461
}

0 commit comments

Comments
 (0)