-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cool#8648 clipboard: try to use navigator.clipboard.write()
For one, getting the selection HTML all the time when we create a text selection is a waste of resources, since only a subsequent copy needs that HTML. For another, the complex selection case required a confusing "two step copy" workflow, where first you press Ctrl-C, then you download the large selection, finally you press Ctrl-C again. The underlying problem is the same: the document.execCommand() API for copy (and cut) is synchronous, but network operations are async, which don't play well together. Fix the problem by trying to use navigator.clipboard.write() instead: the write() call still has to happen inside a magic security context (keyboard used, click happened), but it can take a callback as a parameter, and inside that callback it's fine to perform async network operations, which allows both using a one-step copy and getting rid of the HTML download on text selection change (when most of the time we don't need it). Tested: - Chrome and Safari; the behavior for Firefox is unchanged, unless about:config opts in to expose the new Clipboard API. - HTML, plain text and image copy. - Cut, not only copy. - Doing this with the notebookbar button & keyboard. - A single cypress test now uses a fake clipboard to assert copy. The rest of the tests are left unchanged for now, but likely we need to get rid of this implicit assumption that the copy container is updated on selection change: different behavior for automated vs manual testing is ugly. Signed-off-by: Miklos Vajna <vmiklos@collabora.com> Change-Id: Ifcf16474a339f3f1dae3dc99181836e645340048
- Loading branch information
Showing
3 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters