r104919 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104918‎ | r104919 | r104920 >
Date:23:25, 1 December 2011
Author:tparscal
Status:deferred
Tags:
Comment:
* Split the result of getAnnotationsFromRange to provide full, partial and all lists
* Fixed tools to use this data correctly
Modified paths:
  • /trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/tools/es.ClearButtonTool.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/es/tools/es.ClearButtonTool.js
@@ -15,7 +15,9 @@
1616 };
1717
1818 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+ );
2022 if ( matchingAnnotations.length === 0 ) {
2123 this.$.addClass( 'es-toolbarButtonTool-disabled' );
2224 } else {
Index: trunk/extensions/VisualEditor/modules/es/tools/es.AnnotationButtonTool.js
@@ -22,8 +22,8 @@
2323 };
2424
2525 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 ) {
2828 this.$.addClass( 'es-toolbarButtonTool-down' );
2929 return;
3030 }
Index: trunk/extensions/VisualEditor/modules/es/models/es.DocumentModel.js
@@ -700,24 +700,14 @@
701701 */
702702 es.DocumentModel.prototype.getAnnotationsFromRange = function( range ) {
703703 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++ ) {
722712 hash = this.data[i][j].hash;
723713 if ( hash in map ) {
724714 map[hash][1]++;
@@ -726,14 +716,16 @@
727717 }
728718 }
729719 }
730 - var length = range.getLength(),
731 - annotations = [];
732 - for ( hash in map ) {
 720+ var length = range.getLength();
 721+ for ( var hash in map ) {
733722 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] );
735726 }
 727+ annotations.all.push( map[hash][0] );
736728 }
737 - return es.copyArray( annotations );
 729+ return annotations;
738730 };
739731
740732 /**
Index: trunk/extensions/VisualEditor/modules/es/views/es.ToolbarView.js
@@ -59,7 +59,12 @@
6060 annotations;
6161
6262 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+ };
6469 } else {
6570 annotations = this.surfaceView.documentView.model.getAnnotationsFromRange( selection );
6671 }

Status & tagging log