Index: trunk/extensions/VisualEditor/modules/es/views/es.SurfaceView.js |
— | — | @@ -671,9 +671,25 @@ |
672 | 672 | es.SurfaceView.prototype.insertFromInput = function() { |
673 | 673 | var selection = this.currentSelection.clone(), |
674 | 674 | val = this.$input.val(); |
675 | | - this.$input.val( '' ); |
676 | 675 | 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 |
678 | 694 | var tx; |
679 | 695 | if ( selection.from != selection.to ) { |
680 | 696 | tx = this.model.getDocument().prepareRemoval( selection ); |
— | — | @@ -683,10 +699,10 @@ |
684 | 700 | } |
685 | 701 | var data = val.split(''); |
686 | 702 | es.DocumentModel.addAnnotationsToData( data, this.getInsertionAnnotations() ); |
687 | | - |
688 | 703 | tx = this.model.getDocument().prepareInsertion( selection.from, data ); |
689 | 704 | this.model.transact( tx, true ); |
690 | 705 | |
| 706 | + // Move the selection |
691 | 707 | selection.from += val.length; |
692 | 708 | selection.to += val.length; |
693 | 709 | this.model.select( selection ); |