From e91cd00a2f4312274ae7f909e0d4938c8d7a7f50 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 5 Jul 2013 22:12:39 +0200 Subject: [PATCH] Make all annotations additive Any annotation could have a style attribute which has a compound effect, and this also prevents roundtrip errors. Button tool logic should prevent any annotation from being applied twice which shouldn't be. Bug: 49755 Change-Id: I8502a55cd2b195d28d0e2ecd63f15de670f80d60 --- modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js | 4 ---- modules/ve/dm/ve.dm.Annotation.js | 9 --------- modules/ve/dm/ve.dm.AnnotationSet.js | 6 +----- modules/ve/test/dm/ve.dm.AnnotationSet.test.js | 4 +--- modules/ve/test/dm/ve.dm.example.js | 7 +++++-- 5 files changed, 7 insertions(+), 23 deletions(-) diff --git a/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js b/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js index e94e19a584..67d22baf9d 100644 --- a/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js +++ b/modules/ve/dm/annotations/ve.dm.TextStyleAnnotation.js @@ -157,7 +157,6 @@ ve.dm.TextStyleSmallAnnotation = function VeDmTextStyleSmallAnnotation( element ve.inheritClass( ve.dm.TextStyleSmallAnnotation, ve.dm.TextStyleAnnotation ); ve.dm.TextStyleSmallAnnotation.static.name = 'textStyle/small'; ve.dm.TextStyleSmallAnnotation.static.matchTagNames = ['small']; -ve.dm.TextStyleSmallAnnotation.static.isAdditive = true; ve.dm.modelRegistry.register( ve.dm.TextStyleSmallAnnotation ); /** @@ -174,7 +173,6 @@ ve.dm.TextStyleBigAnnotation = function VeDmTextStyleBigAnnotation( element ) { ve.inheritClass( ve.dm.TextStyleBigAnnotation, ve.dm.TextStyleAnnotation ); ve.dm.TextStyleBigAnnotation.static.name = 'textStyle/big'; ve.dm.TextStyleBigAnnotation.static.matchTagNames = ['big']; -ve.dm.TextStyleBigAnnotation.static.isAdditive = true; ve.dm.modelRegistry.register( ve.dm.TextStyleBigAnnotation ); /** @@ -239,7 +237,6 @@ ve.dm.TextStyleSuperScriptAnnotation = function VeDmTextStyleSuperScriptAnnotati ve.inheritClass( ve.dm.TextStyleSuperScriptAnnotation, ve.dm.TextStyleAnnotation ); ve.dm.TextStyleSuperScriptAnnotation.static.name = 'textStyle/superScript'; ve.dm.TextStyleSuperScriptAnnotation.static.matchTagNames = ['sup']; -ve.dm.TextStyleSuperScriptAnnotation.static.isAdditive = true; ve.dm.modelRegistry.register( ve.dm.TextStyleSuperScriptAnnotation ); /** @@ -256,5 +253,4 @@ ve.dm.TextStyleSubScriptAnnotation = function VeDmTextStyleSubScriptAnnotation( ve.inheritClass( ve.dm.TextStyleSubScriptAnnotation, ve.dm.TextStyleAnnotation ); ve.dm.TextStyleSubScriptAnnotation.static.name = 'textStyle/subScript'; ve.dm.TextStyleSubScriptAnnotation.static.matchTagNames = ['sub']; -ve.dm.TextStyleSubScriptAnnotation.static.isAdditive = true; ve.dm.modelRegistry.register( ve.dm.TextStyleSubScriptAnnotation ); diff --git a/modules/ve/dm/ve.dm.Annotation.js b/modules/ve/dm/ve.dm.Annotation.js index c2d220d686..305b3a935d 100644 --- a/modules/ve/dm/ve.dm.Annotation.js +++ b/modules/ve/dm/ve.dm.Annotation.js @@ -32,15 +32,6 @@ ve.inheritClass( ve.dm.Annotation, ve.dm.Model ); /* Static properties */ -/** - * Allow annotation to be applied additively, e.g. Foo - * - * @static - * @type {boolean} - * @inheritable - */ -ve.dm.Annotation.static.isAdditive = false; - /** * About grouping is not supported for annotations; setting this to true has no effect. * diff --git a/modules/ve/dm/ve.dm.AnnotationSet.js b/modules/ve/dm/ve.dm.AnnotationSet.js index 80d244087b..0a7eb79ba8 100644 --- a/modules/ve/dm/ve.dm.AnnotationSet.js +++ b/modules/ve/dm/ve.dm.AnnotationSet.js @@ -359,16 +359,12 @@ ve.dm.AnnotationSet.prototype.addSet = function ( set ) { /** * Add an annotation at the end of the set. * - * If the annotation is already present in the set, nothing happens. - * * @method * @param {ve.dm.Annotation} annotation Annotation to add */ ve.dm.AnnotationSet.prototype.push = function ( annotation ) { var storeIndex = this.getStore().index( annotation ); - if ( annotation.constructor.static.isAdditive || !this.containsIndex( storeIndex ) ) { - this.storeIndexes.push( storeIndex ); - } + this.storeIndexes.push( storeIndex ); }; /** diff --git a/modules/ve/test/dm/ve.dm.AnnotationSet.test.js b/modules/ve/test/dm/ve.dm.AnnotationSet.test.js index 5da9d29687..4f49719e3e 100644 --- a/modules/ve/test/dm/ve.dm.AnnotationSet.test.js +++ b/modules/ve/test/dm/ve.dm.AnnotationSet.test.js @@ -9,7 +9,7 @@ QUnit.module( 've.dm.AnnotationSet' ); /* Tests */ -QUnit.test( 'Basic usage', 33, function ( assert ) { +QUnit.test( 'Basic usage', 32, function ( assert ) { var annotationSet3, store = new ve.dm.IndexValueStore(), bold = new ve.dm.TextStyleBoldAnnotation(), @@ -59,8 +59,6 @@ QUnit.test( 'Basic usage', 33, function ( assert ) { annotationSet2.push( bold ); annotationSet2.push( italic ); assert.deepEqual( annotationSet2.get(), [bold, italic], 'set2 contains bold then italic after two pushes' ); - annotationSet2.push( italic ); - assert.deepEqual( annotationSet2.getLength(), 2, 'pushing existing annotation doesn\'t change length' ); annotationSet2 = new ve.dm.AnnotationSet( store, store.indexes( [ italic, underline ] ) ); annotationSet2.removeNotInSet( annotationSet ); diff --git a/modules/ve/test/dm/ve.dm.example.js b/modules/ve/test/dm/ve.dm.example.js index a76c441e5b..2d68a12cba 100644 --- a/modules/ve/test/dm/ve.dm.example.js +++ b/modules/ve/test/dm/ve.dm.example.js @@ -868,18 +868,21 @@ ve.dm.example.domToDataCases = { ] }, 'additive annotations': { - 'html': '

abc

', + 'html': '

abcdef

', 'data': [ { 'type': 'paragraph' }, ['a', [ ve.dm.example.big ]], ['b', [ ve.dm.example.big, ve.dm.example.big ]], ['c', [ ve.dm.example.big ]], + ['d', [ ve.dm.example.bold ]], + ['e', [ ve.dm.example.bold, ve.dm.example.bold ]], + ['f', [ ve.dm.example.bold ]], { 'type': '/paragraph' }, { 'type': 'internalList' }, { 'type': '/internalList' } ] }, - 'additive annotations overlapping basic annotations': { + 'additive annotations overlapping other annotations': { 'html': '

abc

', 'data': [ { 'type': 'paragraph' },