r105220 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105219‎ | r105220 | r105221 >
Date:20:40, 5 December 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Prevent inserting unless there was an effective input, such as text being typed - this is done by checking the length of the range of the selection - if it's non-zero then there wasn't any input (because selecting text in the editor fill the input and selects it)
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js
@@ -671,9 +671,25 @@
672672 es.SurfaceView.prototype.insertFromInput = function() {
673673 var selection = this.currentSelection.clone(),
674674 val = this.$input.val();
675 - this.$input.val( '' );
676675 if ( val.length > 0 ) {
677 - //debugger;
 676+ // Check if there was any effective input
 677+ var input = this.$input[0],
 678+ // Internet Explorer
 679+ range = document.selection && document.selection.createRange();
 680+ if (
 681+ // DOM 3.0
 682+ ( 'selectionStart' in input && input.selectionEnd - input.selectionStart ) ||
 683+ // Internet Explorer
 684+ ( range && range.text.length )
 685+ ) {
 686+ // The input is still selected, so the key must not have inserted anything
 687+ return;
 688+ }
 689+
 690+ // Clear the value for more input
 691+ this.$input.val( '' );
 692+
 693+ // Prepare and process a transaction
678694 var tx;
679695 if ( selection.from != selection.to ) {
680696 tx = this.model.getDocument().prepareRemoval( selection );
@@ -683,10 +699,10 @@
684700 }
685701 var data = val.split('');
686702 es.DocumentModel.addAnnotationsToData( data, this.getInsertionAnnotations() );
687 -
688703 tx = this.model.getDocument().prepareInsertion( selection.from, data );
689704 this.model.transact( tx, true );
690705
 706+ // Move the selection
691707 selection.from += val.length;
692708 selection.to += val.length;
693709 this.model.select( selection );

Status & tagging log