Adityab has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/156593

Change subject: Avoid undo when processing a cut event.
......................................................................

Avoid undo when processing a cut event.

The previous cut handler ran an undo using execCommand, to
counteract the browser-issued text deletion on the cut event.

Unfortunately in Chromium 36.x, the cut event handler is processed
(even within the zero-timeout block) before the browser deletes the
selection. This results in the undesirable removal of previously
typed text.

To avoid this, simply prevent the browser from cutting using
preventDefault(), and remove the selection using a transaction.

This removes the need for having a zero-timeout as well.

Bug: 58724

Change-Id: I8f3f608e3f0c1bbfd2cda9543bcf7eeea6fa7c37
---
M src/ce/ve.ce.Surface.js
1 file changed, 15 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor 
refs/changes/93/156593/1

diff --git a/src/ce/ve.ce.Surface.js b/src/ce/ve.ce.Surface.js
index 0728fd9..d79d64d 100644
--- a/src/ce/ve.ce.Surface.js
+++ b/src/ce/ve.ce.Surface.js
@@ -825,27 +825,28 @@
  * @param {jQuery.Event} e Cut event
  */
 ve.ce.Surface.prototype.onCut = function ( e ) {
+       var selection, tx;
+
        // TODO: no pollOnce here: but should we add one?
        this.surfaceObserver.stopTimerLoop();
+
+       // Process the cut event like a copy first
        this.onCopy( e );
-       setTimeout( ve.bind( function () {
-               var selection, tx;
 
-               // We don't like how browsers cut, so let's undo it and do it 
ourselves.
-               this.$document[0].execCommand( 'undo', false, false );
-               selection = this.model.getSelection();
+       // We don't like how browsers cut, so disallow that.
+       e.preventDefault();
 
-               // Transact
-               tx = ve.dm.Transaction.newFromRemoval( this.documentView.model, 
selection );
+       // Read the selection information and generate a removal transaction
+       selection = this.model.getSelection();
+       tx = ve.dm.Transaction.newFromRemoval( this.documentView.model, 
selection );
 
-               // Document may not have had real focus (e.g. with a 
FocusableNode)
-               this.documentView.getDocumentNode().$element[0].focus();
+       // Document may not have had real focus (e.g. with a FocusableNode)
+       this.documentView.getDocumentNode().$element[0].focus();
 
-               this.model.change( tx, new ve.Range( selection.start ) );
-               this.surfaceObserver.clear();
-               this.surfaceObserver.startTimerLoop();
-               this.surfaceObserver.pollOnce();
-       }, this ) );
+       this.model.change( tx, new ve.Range( selection.start ) );
+       this.surfaceObserver.clear();
+       this.surfaceObserver.startTimerLoop();
+       this.surfaceObserver.pollOnce();
 };
 
 /**

-- 
To view, visit https://gerrit.wikimedia.org/r/156593
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f3f608e3f0c1bbfd2cda9543bcf7eeea6fa7c37
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Adityab <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to