From 40fc1b1bed93b92528600142196d832c2ebd15df Mon Sep 17 00:00:00 2001 From: Jforrester Date: Mon, 19 Aug 2013 22:27:32 +0000 Subject: [PATCH] Revert "Don't emit Surface changes back to the Surface" This reverts commit 1987d3aa2bd97a6ea9961f4909103165c03634b5. Change-Id: I5aaa6b0c743fbf6292030f566b6f7d993de740a7 --- modules/ve/ce/ve.ce.Surface.js | 42 +++++++++++------------ modules/ve/ce/ve.ce.SurfaceObserver.js | 46 +++++++++++--------------- modules/ve/test/ve.test.js | 8 ++--- modules/ve/ui/ve.ui.Surface.js | 2 +- 4 files changed, 46 insertions(+), 52 deletions(-) diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index 48a58e4618..3c554f4162 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -292,7 +292,7 @@ ve.ce.Surface.prototype.documentOnFocus = function () { 'compositionstart.ve-ce-Surface': ve.bind( this.onDocumentCompositionStart, this ), 'compositionend.ve-ce-Surface': ve.bind( this.onDocumentCompositionEnd, this ) } ); - this.surfaceObserver.start( true, true ); + this.surfaceObserver.start( true ); }; /** @@ -303,7 +303,7 @@ ve.ce.Surface.prototype.documentOnFocus = function () { */ ve.ce.Surface.prototype.documentOnBlur = function () { this.$document.off( '.ve-ce-Surface' ); - this.surfaceObserver.stop( true, true ); + this.surfaceObserver.stop( true ); this.dragging = false; }; @@ -323,7 +323,7 @@ ve.ce.Surface.prototype.onDocumentMouseDown = function ( e ) { // this.$$( e.target ).closest( '.ve-ce-documentNode' ).length === 0 if ( e.which === 1 ) { - this.surfaceObserver.stop( true, true ); + this.surfaceObserver.stop( true ); } // Handle triple click @@ -349,7 +349,7 @@ ve.ce.Surface.prototype.onDocumentMouseDown = function ( e ) { * @emits selectionEnd */ ve.ce.Surface.prototype.onDocumentMouseUp = function ( e ) { - this.surfaceObserver.start( false, true ); + this.surfaceObserver.start(); if ( !e.shiftKey && this.selecting ) { this.emit( 'selectionEnd' ); this.selecting = false; @@ -467,7 +467,7 @@ ve.ce.Surface.prototype.onDocumentKeyDown = function ( e ) { return; } - this.surfaceObserver.stop( false, true ); + this.surfaceObserver.stop( true ); switch ( e.keyCode ) { case ve.Keys.LEFT: case ve.Keys.RIGHT: @@ -502,7 +502,7 @@ ve.ce.Surface.prototype.onDocumentKeyDown = function ( e ) { } break; } - this.surfaceObserver.start( false, false ); + this.surfaceObserver.start(); }; /** @@ -540,7 +540,7 @@ ve.ce.Surface.prototype.onDocumentKeyPress = function ( e ) { this.handleInsertion(); setTimeout( ve.bind( function () { - this.surfaceObserver.start( false, true ); + this.surfaceObserver.start(); }, this ) ); }; @@ -566,7 +566,7 @@ ve.ce.Surface.prototype.onDocumentKeyUp = function ( e ) { * @param {jQuery.Event} e Cut event */ ve.ce.Surface.prototype.onCut = function ( e ) { - this.surfaceObserver.stop( false, true ); + this.surfaceObserver.stop(); this.onCopy( e ); setTimeout( ve.bind( function () { var selection, tx; @@ -580,7 +580,7 @@ ve.ce.Surface.prototype.onCut = function ( e ) { this.model.change( tx, new ve.Range( selection.start ) ); this.surfaceObserver.clear(); - this.surfaceObserver.start( false, true ); + this.surfaceObserver.start(); }, this ) ); }; @@ -627,7 +627,7 @@ ve.ce.Surface.prototype.onPaste = function () { view = this, selection = this.model.getSelection(); - this.surfaceObserver.stop( false, true ); + this.surfaceObserver.stop(); // Pasting into a range? Remove first. if ( !rangy.getSelection( this.$document[0] ).isCollapsed ) { @@ -708,7 +708,7 @@ ve.ce.Surface.prototype.onDocumentCompositionStart = function () { */ ve.ce.Surface.prototype.onDocumentCompositionEnd = function () { this.inIme = false; - this.surfaceObserver.start( false, false ); + this.surfaceObserver.start(); }; /*! Custom Events */ @@ -942,7 +942,7 @@ ve.ce.Surface.prototype.onContentChange = function ( node, previous, next ) { * @method */ ve.ce.Surface.prototype.onLock = function () { - this.surfaceObserver.stop( false, true ); + this.surfaceObserver.stop(); }; /** @@ -952,7 +952,7 @@ ve.ce.Surface.prototype.onLock = function () { */ ve.ce.Surface.prototype.onUnlock = function () { this.surfaceObserver.clear( this.model.getSelection() ); - this.surfaceObserver.start( false, true ); + this.surfaceObserver.start(); }; /*! Relocation */ @@ -1000,7 +1000,7 @@ ve.ce.Surface.prototype.handleLeftOrRightArrowKey = function ( e ) { // Selection is going to be displayed programmatically so prevent default browser behaviour e.preventDefault(); // Stop with final poll cycle so we have correct information in model - this.surfaceObserver.stop( true, false ); + this.surfaceObserver.stop( true ); selection = this.model.getSelection(); if ( this.$$( e.target ).css( 'direction' ) === 'rtl' ) { // If the language direction is RTL, switch left/right directions: @@ -1017,7 +1017,7 @@ ve.ce.Surface.prototype.handleLeftOrRightArrowKey = function ( e ) { ); this.model.change( null, range ); - this.surfaceObserver.start( false, true ); + this.surfaceObserver.start(); }; /** @@ -1034,7 +1034,7 @@ ve.ce.Surface.prototype.handleUpOrDownArrowKey = function ( e ) { nativeSel.modify( 'extend', 'left', 'character' ); return; } - this.surfaceObserver.stop( true, true ); + this.surfaceObserver.stop( true ); selection = this.model.getSelection(); rangySelection = rangy.getSelection( this.$document[0] ); // Perform programatic handling only for selection that is expanded and backwards according to @@ -1058,18 +1058,18 @@ ve.ce.Surface.prototype.handleUpOrDownArrowKey = function ( e ) { if ( !$element.hasClass( 've-ce-branchNode-slug' ) ) { $element.remove(); } - this.surfaceObserver.start( false, true ); - this.surfaceObserver.stop( false, true ); + this.surfaceObserver.start(); + this.surfaceObserver.stop( false ); if ( e.shiftKey === true ) { // expanded range range = new ve.Range( selection.from, this.model.getSelection().to ); } else { // collapsed range (just a cursor) range = new ve.Range( this.model.getSelection().to ); } this.model.change( null, range ); - this.surfaceObserver.start( false, true ); + this.surfaceObserver.start(); }, this ), 0 ); } else { - this.surfaceObserver.start( false, true ); + this.surfaceObserver.start(); } }; @@ -1125,7 +1125,7 @@ ve.ce.Surface.prototype.handleInsertion = function () { } } - this.surfaceObserver.stop( true, true ); + this.surfaceObserver.stop( true ); }; /** diff --git a/modules/ve/ce/ve.ce.SurfaceObserver.js b/modules/ve/ce/ve.ce.SurfaceObserver.js index 972fee9442..1124813ba9 100644 --- a/modules/ve/ce/ve.ce.SurfaceObserver.js +++ b/modules/ve/ce/ve.ce.SurfaceObserver.js @@ -86,12 +86,11 @@ ve.ce.SurfaceObserver.prototype.clear = function ( range ) { * * @method * @param {boolean} async Poll the first time asynchronously - * @param {boolean} emitChangeEvents Allow change events to be emitted */ -ve.ce.SurfaceObserver.prototype.start = function ( async, emitChangeEvents ) { +ve.ce.SurfaceObserver.prototype.start = function ( async ) { this.domDocument = this.documentView.getDocumentNode().getElementDocument(); this.polling = true; - this.poll( async, emitChangeEvents ); + this.poll( async ); }; /** @@ -102,12 +101,11 @@ ve.ce.SurfaceObserver.prototype.start = function ( async, emitChangeEvents ) { * * @method * @param {boolean} poll Poll one last time before stopping future polling - * @param {boolean} emitChangeEvents Allow change events to be emitted */ -ve.ce.SurfaceObserver.prototype.stop = function ( poll, emitChangeEvents ) { +ve.ce.SurfaceObserver.prototype.stop = function ( poll ) { if ( this.polling === true ) { if ( poll === true ) { - this.poll( false, emitChangeEvents ); + this.poll(); } this.polling = false; clearTimeout( this.timeoutId ); @@ -127,11 +125,10 @@ ve.ce.SurfaceObserver.prototype.stop = function ( poll, emitChangeEvents ) { * * @method * @param {boolean} async Poll asynchronously - * @param {boolean} emitChangeEvents If false, don't emit change events * @emits contentChange * @emits selectionChange */ -ve.ce.SurfaceObserver.prototype.poll = function ( async, emitChangeEvents ) { +ve.ce.SurfaceObserver.prototype.poll = function ( async ) { var delayPoll, $nodeOrSlug, node, text, hash, range, rangyRange; if ( this.polling === false ) { @@ -143,16 +140,15 @@ ve.ce.SurfaceObserver.prototype.poll = function ( async, emitChangeEvents ) { this.timeoutId = null; } - delayPoll = ve.bind( function ( async, emitChangeEvents ) { + delayPoll = ve.bind( function ( async ) { this.timeoutId = setTimeout( ve.bind( this.poll, this ), - async === true ? 0 : this.frequency, - emitChangeEvents + async === true ? 0 : this.frequency ); }, this ); if ( async === true ) { - delayPoll( true, emitChangeEvents ); + delayPoll( true ); return; } @@ -182,32 +178,30 @@ ve.ce.SurfaceObserver.prototype.poll = function ( async, emitChangeEvents ) { this.hash = ve.ce.getDomHash( node.$[0] ); this.node = node; } - } else if ( node !== null ) { - text = ve.ce.getDomText( node.$[0] ); - hash = ve.ce.getDomHash( node.$[0] ); - if ( this.text !== text || this.hash !== hash ) { - if ( emitChangeEvents ) { + } else { + if ( node !== null ) { + text = ve.ce.getDomText( node.$[0] ); + hash = ve.ce.getDomHash( node.$[0] ); + if ( this.text !== text || this.hash !== hash ) { this.emit( 'contentChange', node, { 'text': this.text, 'hash': this.hash, 'range': this.range }, { 'text': text, 'hash': hash, 'range': range } ); + this.text = text; + this.hash = hash; } - this.text = text; - this.hash = hash; } } // Only emit selectionChange event if there's a meaningful range difference if ( ( this.range && range ) ? !this.range.equals( range ) : ( this.range !== range ) ) { - if ( emitChangeEvents ) { - this.emit( - 'selectionChange', - this.range, - range - ); - } + this.emit( + 'selectionChange', + this.range, + range + ); this.range = range; } diff --git a/modules/ve/test/ve.test.js b/modules/ve/test/ve.test.js index a48a1d0100..c87ba9c7ee 100644 --- a/modules/ve/test/ve.test.js +++ b/modules/ve/test/ve.test.js @@ -454,18 +454,18 @@ QUnit.test( 'createDocumentFromHtml', function ( assert ) { // TODO: ve.getCharacterOffset QUnit.test( 'graphemeSafeSubstring', function ( assert ) { - var i, text = '12\ud860\udee245\ud860\udee2789\ud860\udee2bc', cases = [ + var i, text = '12𨋢45𨋢789𨋢bc', cases = [ { 'msg': 'start and end inside multibyte', 'start': 3, 'end': 12, - 'expected': [ '\ud860\udee245\ud860\udee2789\ud860\udee2', '45\ud860\udee2789' ] + 'expected': [ '𨋢45𨋢789𨋢', '45𨋢789' ] }, { 'msg': 'start and end next to multibyte', 'start': 4, 'end': 11, - 'expected': [ '45\ud860\udee2789', '45\ud860\udee2789' ] + 'expected': [ '45𨋢789', '45𨋢789' ] }, { 'msg': 'complete string', @@ -477,7 +477,7 @@ QUnit.test( 'graphemeSafeSubstring', function ( assert ) { 'msg': 'collapsed selection inside multibyte', 'start': 3, 'end': 3, - 'expected': [ '\ud860\udee2', '' ] + 'expected': [ '𨋢', '' ] } ]; QUnit.expect( cases.length * 2 ); diff --git a/modules/ve/ui/ve.ui.Surface.js b/modules/ve/ui/ve.ui.Surface.js index 1510eff8be..e31ab14407 100644 --- a/modules/ve/ui/ve.ui.Surface.js +++ b/modules/ve/ui/ve.ui.Surface.js @@ -82,7 +82,7 @@ ve.ui.Surface.prototype.initialize = function () { // By re-asserting the current selection and forcing a poll we force selection to be something // reasonable - otherwise in Firefox, the initial selection is (0,0), causing bug 42277 this.model.getFragment().select(); - this.view.surfaceObserver.poll( false, true ); + this.view.surfaceObserver.poll(); this.model.startHistoryTracking(); };