mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-28 16:20:52 +00:00
adding clearState function for tools and using clearState if no selection exists
Originally committed in SVN as r114418 by Christian, missed the git conversion Change-Id: I56e91c170670519fa2b482a4b7f30cdcbc8ff163
This commit is contained in:
parent
7b20509b78
commit
826437950c
|
@ -22,3 +22,7 @@ ve.ui.Tool.tools = {};
|
|||
ve.ui.Tool.prototype.updateState = function() {
|
||||
throw 'Tool.updateState not implemented in this subclass:' + this.constructor;
|
||||
};
|
||||
|
||||
ve.ui.Tool.prototype.clearState = function() {
|
||||
this.$.removeClass( 'es-toolbarButtonTool-down' );
|
||||
}
|
|
@ -17,31 +17,35 @@ ve.ui.Toolbar = function( $container, surfaceView, config ) {
|
|||
this.tools = [];
|
||||
|
||||
this.surfaceView.surfaceObserver.on( 'select', function ( selection ) {
|
||||
var annotations = _this.surfaceView.getAnnotations(),
|
||||
nodes = [],
|
||||
model = _this.surfaceView.documentView.model;
|
||||
|
||||
if ( selection.from === selection.to ) {
|
||||
nodes.push( model.getNodeFromOffset( selection.from ) );
|
||||
} else {
|
||||
var startNode = model.getNodeFromOffset( selection.start ),
|
||||
endNode = model.getNodeFromOffset( selection.end );
|
||||
if ( startNode === endNode ) {
|
||||
nodes.push( startNode );
|
||||
} else {
|
||||
model.traverseLeafNodes( function( node ) {
|
||||
nodes.push( node );
|
||||
if( node === endNode ) {
|
||||
return false;
|
||||
}
|
||||
}, startNode );
|
||||
}
|
||||
}
|
||||
|
||||
if ( selection !== null ) {
|
||||
var annotations = _this.surfaceView.getAnnotations(),
|
||||
nodes = [],
|
||||
model = _this.surfaceView.documentView.model;
|
||||
|
||||
if ( selection.from === selection.to ) {
|
||||
nodes.push( model.getNodeFromOffset( selection.from ) );
|
||||
} else {
|
||||
var startNode = model.getNodeFromOffset( selection.start ),
|
||||
endNode = model.getNodeFromOffset( selection.end );
|
||||
if ( startNode === endNode ) {
|
||||
nodes.push( startNode );
|
||||
} else {
|
||||
model.traverseLeafNodes( function( node ) {
|
||||
nodes.push( node );
|
||||
if( node === endNode ) {
|
||||
return false;
|
||||
}
|
||||
}, startNode );
|
||||
}
|
||||
}
|
||||
|
||||
for( var i = 0; i < _this.tools.length; i++ ) {
|
||||
_this.tools[i].updateState( annotations, nodes );
|
||||
}
|
||||
} else {
|
||||
for( var i = 0; i < _this.tools.length; i++ ) {
|
||||
_this.tools[i].clearState();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue