From af6a9f9cccb752feafb1764654eb272e269e1443 Mon Sep 17 00:00:00 2001 From: Inez Korczynski Date: Fri, 27 Apr 2012 15:26:38 -0700 Subject: [PATCH] Created a named method inside a Surface (instead of anonymouse one) to handle logic for rangeChange event handler. Change-Id: Ief32e647f9399e3ea47c5613902cebcbaaf4874c --- modules/ve/ce/ve.ce.Surface.js | 53 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index a4e8b027ca..5533d6ff9f 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -78,34 +78,8 @@ ve.ce.Surface = function( $container, model ) { end: null } }; - this.on( 'textChange', this.proxy( this.onTextChange ) ); - - this.on( 'rangeChange', function( e ) { - - /* Save selection direction only - if selection start and end have changed */ - if( e.new && e.old ) { - if( e.new.start !== e.old.start || e.new.end !== e.old.end ) { - this.selectionDirection = ( e.new.to < e.new.from ) ? -1 : 1; - } - } - - if ( e.new !== null ) { - /* Set selection in the model */ - _this.model.setSelection( e.new ); - - /* Hide or show context view icon */ - _this.toggleContextView(); - - /* Load or clear annotations */ - if ( e.new.getLength() === 0 ) { - _this.loadInsertionAnnotations(); - } else { - _this.clearInsertionAnnotations(); - } - } - } ); + this.on( 'rangeChange', this.proxy( this.onRangeChange ) ); //Prevent native contentedtiable tools try { @@ -134,6 +108,31 @@ ve.ce.Surface.prototype.onCompositionEnd = function( e ) { this.poll.composition.end = this.getOffset( rangySel.anchorNode, rangySel.anchorOffset ); }; +ve.ce.Surface.prototype.onRangeChange = function( e ) { + /* Save selection direction only + if selection start and end have changed */ + if( e.new && e.old ) { + if( e.new.start !== e.old.start || e.new.end !== e.old.end ) { + this.selectionDirection = ( e.new.to < e.new.from ) ? -1 : 1; + } + } + + if ( e.new !== null ) { + /* Set selection in the model */ + this.model.setSelection( e.new ); + + /* Hide or show context view icon */ + this.toggleContextView(); + + /* Load or clear annotations */ + if ( e.new.getLength() === 0 ) { + this.loadInsertionAnnotations(); + } else { + this.clearInsertionAnnotations(); + } + } +}; + ve.ce.Surface.prototype.onTextChange = function( e ) { var oldOffset = null, newOffset = null;