diff --git a/modules/ve/ce/ve.ce.Surface.js b/modules/ve/ce/ve.ce.Surface.js index b471dae5b1..513b9bebf2 100644 --- a/modules/ve/ce/ve.ce.Surface.js +++ b/modules/ve/ce/ve.ce.Surface.js @@ -95,6 +95,17 @@ ve.ce.Surface = function( $container, model ) { _this.onTextChange( e ); } ); + this.on( 'rangeChange', function( e ) { + if ( e.new !== null ) { + _this.model.setSelection( e.new ); + if ( e.new.getLength() === 0 ) { + _this.loadInsertionAnnotations(); + } else { + _this.clearInsertionAnnotations(); + } + } + } ); + //Prevent native contentedtiable tools try { document.execCommand("enableInlineTableEditing", false, false); @@ -176,8 +187,10 @@ ve.ce.Surface.prototype.onTextChange = function( e ) { * @method */ ve.ce.Surface.prototype.startPolling = function( async ) { - this.poll.polling = true; - this.pollChanges( async ); + if ( this.poll.polling === false ) { + this.poll.polling = true; + this.pollChanges( async ); + } }; /** @@ -289,6 +302,7 @@ ve.ce.Surface.prototype.pollChanges = function( async ) { } delay(); + return; }; ve.ce.Surface.prototype.annotate = function( method, annotation ) { @@ -343,9 +357,8 @@ ve.ce.Surface.prototype.addInsertionAnnotation = function( annotation ) { this.insertionAnnotations.push( annotation ); }; -ve.ce.Surface.prototype.loadInsertionAnnotations = function( annotation ) { - this.insertionAnnotations = - this.model.getDocument().getAnnotationsFromOffset( this.currentSelection.to - 1 ); +ve.ce.Surface.prototype.loadInsertionAnnotations = function() { + this.insertionAnnotations = this.model.getDocument().getAnnotationsFromOffset( this.model.getSelection().to - 1 ); // Filter out annotations that aren't textStyles or links for ( var i = 0; i < this.insertionAnnotations.length; i++ ) { if ( !this.insertionAnnotations[i].type.match( /(textStyle\/|link\/)/ ) ) { @@ -439,7 +452,8 @@ ve.ce.Surface.prototype.getModel = function() { return this.model; }; -ve.ce.Surface.prototype.updateSelection = function( delay ) { +ve.ce.Surface.prototype. +Selection = function( delay ) { var _this = this; function update() { /* @@ -467,12 +481,10 @@ ve.ce.Surface.prototype.updateSelection = function( delay ) { }; ve.ce.Surface.prototype.documentOnFocus = function() { - console.log( 'documentOnFocus' ); this.startPolling( true ); }; ve.ce.Surface.prototype.documentOnBlur = function() { - console.log( 'documentOnBlur' ); this.stopPolling(); }; @@ -489,12 +501,12 @@ ve.ce.Surface.prototype.clearPollData = function() { ve.ce.Surface.prototype.onMouseDown = function( e ) { //this.pollChanges(); - this.pollChanges( true ); + //this.pollChanges( true ); return; }; ve.ce.Surface.prototype.onKeyDown = function( e ) { - this.pollChanges(); + //this.pollChanges(); //this.pollChanges( true ); return; diff --git a/modules/ve/dm/ve.dm.Surface.js b/modules/ve/dm/ve.dm.Surface.js index c8eb36524e..5a15983046 100644 --- a/modules/ve/dm/ve.dm.Surface.js +++ b/modules/ve/dm/ve.dm.Surface.js @@ -61,6 +61,15 @@ ve.dm.Surface.prototype.getSelection = function() { return this.selection; }; +/** + * Sets the selection + * + * @method + */ +ve.dm.Surface.prototype.setSelection = function( selection ) { + this.selection = selection; +}; + /** * Changes the selection. * diff --git a/modules/ve/ui/ve.ui.Toolbar.js b/modules/ve/ui/ve.ui.Toolbar.js index ccaf614cc2..56b5468665 100644 --- a/modules/ve/ui/ve.ui.Toolbar.js +++ b/modules/ve/ui/ve.ui.Toolbar.js @@ -16,19 +16,18 @@ ve.ui.Toolbar = function( $container, surfaceView, config ) { this.$groups = $( '
' ).prependTo( this.$ ); this.tools = []; - /* - this.surfaceView.surfaceObserver.on( 'select', function ( selection ) { - var i; - if ( selection !== null ) { + + this.surfaceView.on( 'rangeChange', function( e ) { + if ( e.new !== null ) { var annotations = _this.surfaceView.getAnnotations(), nodes = [], model = _this.surfaceView.documentView.model; - - if ( selection.from === selection.to ) { - nodes.push( model.getNodeFromOffset( selection.from ) ); + + if ( e.new.from === e.new.to ) { + nodes.push( model.getNodeFromOffset( e.new.from ) ); } else { - var startNode = model.getNodeFromOffset( selection.start ), - endNode = model.getNodeFromOffset( selection.end ); + var startNode = model.getNodeFromOffset( e.new.start ), + endNode = model.getNodeFromOffset( e.new.end ); if ( startNode === endNode ) { nodes.push( startNode ); } else { @@ -49,9 +48,7 @@ ve.ui.Toolbar = function( $container, surfaceView, config ) { _this.tools[i].clearState(); } } - - }); - */ + } ); this.config = config || [ { 'name': 'history', 'items' : ['undo', 'redo'] },