From 333166e818ca949763136296fc78f8eadf348542 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Tue, 10 Dec 2013 19:15:04 +0000 Subject: [PATCH] Fix paste sequence in Firefox It appears that if the pasteTarget is given focus too close to the range being set it may not take effect in time. Moving up to before any of the selection setting logic seems to fix the issue. Bug: 58283 Change-Id: I9bfb0ab6952863496fb3548e6804cb347d52cc57 --- modules/ve/ce/ve.ce.Surface.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index ee1095ed0d..c9b6f78810 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -839,6 +839,10 @@ ve.ce.Surface.prototype.beforePaste = function ( e ) { ve.dm.converter.internalList = doc.getInternalList(); ve.dm.converter.getDomSubtreeFromData( context, this.$pasteTarget[0] ); + // Giving the paste target focus too late can cause problems in FF (!?) + // so do it up here. + this.$pasteTarget[0].focus(); + rangyRange = rangy.createRange( this.getElementDocument() ); // Assume that the DM node only generated one child textNode = this.$pasteTarget.children().contents()[0]; @@ -847,7 +851,6 @@ ve.ce.Surface.prototype.beforePaste = function ( e ) { rangyRange.setEnd( textNode, textEnd ); sel = rangy.getSelection( this.getElementDocument() ); sel.removeAllRanges(); - this.$pasteTarget[0].focus(); sel.addRange( rangyRange, false ); this.beforePasteData.context = context;