mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
* Split the result of getAnnotationsFromRange to provide full, partial and all lists
* Fixed tools to use this data correctly
This commit is contained in:
parent
2686b383d9
commit
380f016840
|
@ -700,24 +700,14 @@ es.DocumentModel.prototype.getAnnotationsFromOffset = function( offset ) {
|
|||
*/
|
||||
es.DocumentModel.prototype.getAnnotationsFromRange = function( range ) {
|
||||
range.normalize();
|
||||
// First pass - check that [0] and [n) characters are annotated
|
||||
if ( !es.isArray( this.data[range.start] ) || !es.isArray( this.data[range.end - 1] ) ) {
|
||||
// Range starts/ends on a non-annotated character, range can not have any common annotations
|
||||
return [];
|
||||
}
|
||||
// Second pass - check that [1..n-1) characters are annotated
|
||||
var i;
|
||||
for ( i = range.start + 1, end = range.end - 1; i < end; i++ ) {
|
||||
if ( !es.isArray( this.data[i] ) ) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
// Third pass - collect annotations common amung all characters
|
||||
var map = {},
|
||||
j,
|
||||
hash;
|
||||
for ( i = range.start, end = range.end; i < end; i++ ) {
|
||||
for ( j = 1; j < this.data[i].length; j++ ) {
|
||||
var annotations = {
|
||||
'full': [],
|
||||
'partial': [],
|
||||
'all': []
|
||||
},
|
||||
map = {};
|
||||
for ( var i = range.start; i < range.end; i++ ) {
|
||||
for ( var j = 1; j < this.data[i].length; j++ ) {
|
||||
hash = this.data[i][j].hash;
|
||||
if ( hash in map ) {
|
||||
map[hash][1]++;
|
||||
|
@ -726,14 +716,16 @@ es.DocumentModel.prototype.getAnnotationsFromRange = function( range ) {
|
|||
}
|
||||
}
|
||||
}
|
||||
var length = range.getLength(),
|
||||
annotations = [];
|
||||
for ( hash in map ) {
|
||||
var length = range.getLength();
|
||||
for ( var hash in map ) {
|
||||
if ( map[hash][1] === length ) {
|
||||
annotations.push( map[hash][0] );
|
||||
annotations.full.push( map[hash][0] );
|
||||
} else {
|
||||
annotations.partial.push( map[hash][0] );
|
||||
}
|
||||
annotations.all.push( map[hash][0] );
|
||||
}
|
||||
return es.copyArray( annotations );
|
||||
return annotations;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,8 +22,8 @@ es.AnnotationButtonTool.prototype.onClick = function() {
|
|||
};
|
||||
|
||||
es.AnnotationButtonTool.prototype.updateState = function( annotations ) {
|
||||
for ( var i = 0; i < annotations.length; i++ ) {
|
||||
if ( annotations[i].type === this.data.type ) {
|
||||
for ( var i = 0; i < annotations.full.length; i++ ) {
|
||||
if ( annotations.full[i].type === this.data.type ) {
|
||||
this.$.addClass( 'es-toolbarButtonTool-down' );
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ es.ClearButtonTool.prototype.onClick = function() {
|
|||
};
|
||||
|
||||
es.ClearButtonTool.prototype.updateState = function( annotations ) {
|
||||
var matchingAnnotations = es.DocumentModel.getMatchingAnnotations( annotations, this.pattern );
|
||||
var matchingAnnotations = es.DocumentModel.getMatchingAnnotations(
|
||||
annotations.all, this.pattern
|
||||
);
|
||||
if ( matchingAnnotations.length === 0 ) {
|
||||
this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
||||
} else {
|
||||
|
|
|
@ -59,7 +59,12 @@ es.ToolbarView.prototype.updateState = function() {
|
|||
annotations;
|
||||
|
||||
if( selection.from === selection.to ) {
|
||||
annotations = this.surfaceView.getInsertionAnnotations();
|
||||
var insertionAnnotations = this.surfaceView.getInsertionAnnotations();
|
||||
annotations = {
|
||||
'full': insertionAnnotations,
|
||||
'partial': [],
|
||||
'all': insertionAnnotations
|
||||
};
|
||||
} else {
|
||||
annotations = this.surfaceView.documentView.model.getAnnotationsFromRange( selection );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue