re: AnnotationSet, annotationButtonTool properly clears annotation.

Surface model annotate method previously cleared basic tool annotation objects.
Now that bold and other annotations have htmlAttributes from parsoid,
we must gather annotations by type from selection and iterate through
to properly clear.

Change-Id: Id53bf5733078524ae5aac376e01b9679eb8c32df
This commit is contained in:
Rob Moen 2012-09-24 12:52:49 -07:00
parent db2c44ef2d
commit 7be9f92de7

View file

@ -35,13 +35,30 @@ ve.inheritClass( ve.ui.AnnotationButtonTool, ve.ui.ButtonTool );
ve.ui.AnnotationButtonTool.prototype.onClick = function () {
var surfaceView = this.toolbar.getSurfaceView(),
surfaceModel = surfaceView.model,
selection = surfaceModel.getSelection();
documentModel = surfaceModel.getDocument(),
selection = surfaceModel.getSelection(),
annotations,
i;
if ( this.inspector ) {
if ( selection && selection.getLength() ) {
surfaceView.contextView.openInspector( this.inspector );
}
} else {
surfaceModel.annotate( this.active ? 'clear' : 'set', this.annotation );
if ( this.active ) {
// Get all annotations by type.
annotations = documentModel
.getAnnotationsFromRange( surfaceModel.getSelection() )
.getAnnotationsOfType( this.annotation.type )
.get();
// Clear each selected annotation.
for( i = 0; i < annotations.length; i++ ) {
surfaceModel.annotate( 'clear', annotations[i] );
}
} else {
// Set annotation.
surfaceModel.annotate( 'set', this.annotation );
}
}
};