Index: trunk/extensions/VisualEditor/modules/es/tools/es.ClearButtonTool.js |
— | — | @@ -15,7 +15,9 @@ |
16 | 16 | };
|
17 | 17 |
|
18 | 18 | es.ClearButtonTool.prototype.updateState = function( annotations ) {
|
19 | | - var matchingAnnotations = es.DocumentModel.getMatchingAnnotations( annotations, this.pattern );
|
| 19 | + var matchingAnnotations = es.DocumentModel.getMatchingAnnotations(
|
| 20 | + annotations.all, this.pattern
|
| 21 | + );
|
20 | 22 | if ( matchingAnnotations.length === 0 ) {
|
21 | 23 | this.$.addClass( 'es-toolbarButtonTool-disabled' );
|
22 | 24 | } else {
|
Index: trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js |
— | — | @@ -22,8 +22,8 @@ |
23 | 23 | };
|
24 | 24 |
|
25 | 25 | es.AnnotationButtonTool.prototype.updateState = function( annotations ) {
|
26 | | - for ( var i = 0; i < annotations.length; i++ ) {
|
27 | | - if ( annotations[i].type === this.data.type ) {
|
| 26 | + for ( var i = 0; i < annotations.full.length; i++ ) {
|
| 27 | + if ( annotations.full[i].type === this.data.type ) {
|
28 | 28 | this.$.addClass( 'es-toolbarButtonTool-down' );
|
29 | 29 | return;
|
30 | 30 | }
|
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js |
— | — | @@ -700,24 +700,14 @@ |
701 | 701 | */ |
702 | 702 | es.DocumentModel.prototype.getAnnotationsFromRange = function( range ) { |
703 | 703 | range.normalize(); |
704 | | - // First pass - check that [0] and [n) characters are annotated |
705 | | - if ( !es.isArray( this.data[range.start] ) || !es.isArray( this.data[range.end - 1] ) ) { |
706 | | - // Range starts/ends on a non-annotated character, range can not have any common annotations |
707 | | - return []; |
708 | | - } |
709 | | - // Second pass - check that [1..n-1) characters are annotated |
710 | | - var i; |
711 | | - for ( i = range.start + 1, end = range.end - 1; i < end; i++ ) { |
712 | | - if ( !es.isArray( this.data[i] ) ) { |
713 | | - return []; |
714 | | - } |
715 | | - } |
716 | | - // Third pass - collect annotations common amung all characters |
717 | | - var map = {}, |
718 | | - j, |
719 | | - hash; |
720 | | - for ( i = range.start, end = range.end; i < end; i++ ) { |
721 | | - for ( j = 1; j < this.data[i].length; j++ ) { |
| 704 | + var annotations = { |
| 705 | + 'full': [], |
| 706 | + 'partial': [], |
| 707 | + 'all': [] |
| 708 | + }, |
| 709 | + map = {}; |
| 710 | + for ( var i = range.start; i < range.end; i++ ) { |
| 711 | + for ( var j = 1; j < this.data[i].length; j++ ) { |
722 | 712 | hash = this.data[i][j].hash; |
723 | 713 | if ( hash in map ) { |
724 | 714 | map[hash][1]++; |
— | — | @@ -726,14 +716,16 @@ |
727 | 717 | } |
728 | 718 | } |
729 | 719 | } |
730 | | - var length = range.getLength(), |
731 | | - annotations = []; |
732 | | - for ( hash in map ) { |
| 720 | + var length = range.getLength(); |
| 721 | + for ( var hash in map ) { |
733 | 722 | if ( map[hash][1] === length ) { |
734 | | - annotations.push( map[hash][0] ); |
| 723 | + annotations.full.push( map[hash][0] ); |
| 724 | + } else { |
| 725 | + annotations.partial.push( map[hash][0] ); |
735 | 726 | } |
| 727 | + annotations.all.push( map[hash][0] ); |
736 | 728 | } |
737 | | - return es.copyArray( annotations ); |
| 729 | + return annotations; |
738 | 730 | }; |
739 | 731 | |
740 | 732 | /** |
Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js |
— | — | @@ -59,7 +59,12 @@ |
60 | 60 | annotations; |
61 | 61 | |
62 | 62 | if( selection.from === selection.to ) { |
63 | | - annotations = this.surfaceView.getInsertionAnnotations(); |
| 63 | + var insertionAnnotations = this.surfaceView.getInsertionAnnotations(); |
| 64 | + annotations = { |
| 65 | + 'full': insertionAnnotations, |
| 66 | + 'partial': [], |
| 67 | + 'all': insertionAnnotations |
| 68 | + }; |
64 | 69 | } else { |
65 | 70 | annotations = this.surfaceView.documentView.model.getAnnotationsFromRange( selection ); |
66 | 71 | } |