mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 15:33:30 +00:00
copy/paste: Try to fix Casper flake and add comments.
I think this will fix a Casper flake where there was a race window with multiple temp DOM elements holding copied text. I also add a comment to the code I think causes this race for the tests.
This commit is contained in:
@@ -63,6 +63,11 @@ function copy_messages(start_message, end_message) {
|
|||||||
window.getSelection().removeAllRanges();
|
window.getSelection().removeAllRanges();
|
||||||
window.getSelection().addRange(selectedRange);
|
window.getSelection().addRange(selectedRange);
|
||||||
|
|
||||||
|
// Remove existing copy/paste divs, which may linger from the previous
|
||||||
|
// example. (The code clears these out with a zero-second timeout, which
|
||||||
|
// is probably sufficient for human users, but which causes problems here.)
|
||||||
|
$('#copytempdiv').remove();
|
||||||
|
|
||||||
// emulate copy event
|
// emulate copy event
|
||||||
var event = document.createEvent('Event');
|
var event = document.createEvent('Event');
|
||||||
event.initEvent('copy', true, true);
|
event.initEvent('copy', true, true);
|
||||||
|
|||||||
@@ -141,8 +141,23 @@ function copy_handler() {
|
|||||||
$('body').append(div);
|
$('body').append(div);
|
||||||
selection.selectAllChildren(div[0]);
|
selection.selectAllChildren(div[0]);
|
||||||
|
|
||||||
// After the copy has happened, delete the div and
|
/*
|
||||||
// change the selection back to the original selection
|
The techniques we use in this code date back to
|
||||||
|
2013 and may be obsolete today (and may not have
|
||||||
|
been even the best workaround back then).
|
||||||
|
|
||||||
|
https://github.com/zulip/zulip/commit/fc0b7c00f16316a554349f0ad58c6517ebdd7ac4
|
||||||
|
|
||||||
|
The idea is that we build a temp div, return from
|
||||||
|
this function, let jQuery process the selection,
|
||||||
|
then restore the selection on a zero-second timer
|
||||||
|
back to the original selection.
|
||||||
|
|
||||||
|
Do not be afraid to change this code if you understand
|
||||||
|
how modern browsers deal with copy/paste. Just test
|
||||||
|
your changes carefully.
|
||||||
|
*/
|
||||||
|
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
selection = window.getSelection();
|
selection = window.getSelection();
|
||||||
selection.removeAllRanges();
|
selection.removeAllRanges();
|
||||||
|
|||||||
Reference in New Issue
Block a user