6pac / SlickGrid

A lightning fast JavaScript grid/spreadsheet
https://github.com/6pac/SlickGrid/wiki
MIT License
1.82k stars 424 forks source link

Fix: CellExternalCopyManager plugin restores focus on paste #1011

Closed PierreYvesR closed 5 months ago

PierreYvesR commented 5 months ago

When using doing copy-paste with CellExternalCopyManager, the grid loses focus after Ctrl-V.

The issue can be seen on example-excel-compatible-spreadsheet by playing with the arrow keys and doing some copy/paste.

The commit reuses the code found some 20 lines before in the same function to restore the focus.

ghiscoding commented 5 months ago

hmm I would say that I don't want any new console log, I assume you mainly added it for testing so please remove it. Also the 100ms seems like a lot, can't you go with a much smaller number? @6pac what do you think about this PR?

PierreYvesR commented 5 months ago

I've removed the console log. I had put it in as there's already one at Line 430, FWIW I've actually never seen those logs in my console ;-)

As for the 100ms delay, it was already there before this commit, so I can't really comment. Happy to change it though.

PierreYvesR commented 5 months ago

On a closer look, I'm wondering whether 100ms should be replaced with

this._options?.clipboardPasteDelay ?? CLIPBOARD_PASTE_DELAY

ghiscoding commented 5 months ago

On a closer look, I'm wondering whether 100ms should be replaced with

this._options?.clipboardPasteDelay ?? CLIPBOARD_PASTE_DELAY

yeah sure if you want to add an extra config option for it, that should be ok but please update the associated TypeScript interface for it too

PierreYvesR commented 5 months ago

The option is already in there, I would just use it for both delays (delay on paste and delay on copy).

ghiscoding commented 5 months ago

if it's the same kind of topic, then I guess it's ok

ghiscoding commented 5 months ago

@PierreYvesR before I merged this, can I assume that you tried it after the latest code change?

PierreYvesR commented 5 months ago

Yes I did. I also played with the timeout delay, and it does work. I can even set it to 0 without issues.

I've written a Cypress test for this (I had never used Cypress, so I was intrigued). However it seems I would need to add cypress-real-events plugin to be able to send Copy and Paste keyboard event.

ghiscoding commented 5 months ago

you can add it if you want, just make sure that it's for devDependencies. I added Cypress because that's a good way to make sure everything is working and new PRs aren't causing regressions. It would not have been possible to remove jQuery/jQueryUI and migrate to TypeScript without such tests in place... well I mean we could have but we would have certainly faced a lot more bugs on new releases, so as you can see, these E2E tests are really important to make sure any new PRs aren't introducing new regressions and we fix bugs early :)

For Copy+Paste, these 2 articles seems interesting, I used the invoke in a few tests

PierreYvesR commented 5 months ago

https://egghead.io/blog/handling-copy-and-paste-in-cypress

That's where I found cypress-real-events (at the very end of the article)

ghiscoding commented 5 months ago

great thanks for the contribution and new Cypress test :) Does that complete your code change?

Merci :)

PierreYvesR commented 5 months ago

Yes, but I guess I should squash it all into one commit, right?

Merci :) Thank you for all the work on SlickGrid.

ghiscoding commented 5 months ago

no need GitHub has a "Squash and Merge" that I use most often, thanks again for the contribution. However note that since I already published a new release just couple days ago, I will probably wait a few more days to release this, maybe next weekend. Remind me if I forget, cheers

6pac commented 4 months ago

All looks good to me :-)

zewa666 commented 4 months ago

@PierreYvesR thanks for mentioning cypress-real-events. Thats a real gamechanger to test copy&paste events properly

ghiscoding commented 4 months ago

Thanks for the contribution, this was released in v5.9.1.