Explorar el Código

Merge pull request #10 from ckeditor/t/8

Fix: The selection attribute is not updated on consecutive `HighlightCommand#execute()` calls. Closes #8.
Aleksander Nowodzinski hace 8 años
padre
commit
e88f96a818

+ 1 - 0
packages/ckeditor5-highlight/src/highlightcommand.js

@@ -84,6 +84,7 @@ export default class HighlightCommand extends Command {
 					} else {
 					} else {
 						// ...update `highlight` value.
 						// ...update `highlight` value.
 						writer.setAttribute( 'highlight', highlighter, highlightRange );
 						writer.setAttribute( 'highlight', highlighter, highlightRange );
+						writer.setSelectionAttribute( 'highlight', highlighter );
 					}
 					}
 				} else if ( highlighter ) {
 				} else if ( highlighter ) {
 					writer.setSelectionAttribute( 'highlight', highlighter );
 					writer.setSelectionAttribute( 'highlight', highlighter );

+ 17 - 0
packages/ckeditor5-highlight/tests/highlightcommand.js

@@ -172,6 +172,23 @@ describe( 'HighlightCommand', () => {
 					expect( command.value ).to.be.undefined;
 					expect( command.value ).to.be.undefined;
 					expect( doc.selection.hasAttribute( 'highlight' ) ).to.be.false;
 					expect( doc.selection.hasAttribute( 'highlight' ) ).to.be.false;
 				} );
 				} );
+
+				// https://github.com/ckeditor/ckeditor5-highlight/issues/8
+				it( 'should change selection attribute on consecutive calls', () => {
+					setData( model, '<p>abcfoobar[] foobar</p>' );
+
+					expect( command.value ).to.be.undefined;
+
+					command.execute( { value: 'greenMarker' } );
+
+					expect( command.value ).to.equal( 'greenMarker' );
+					expect( doc.selection.getAttribute( 'highlight' ) ).to.equal( 'greenMarker' );
+
+					command.execute( { value: 'pinkMarker' } );
+
+					expect( command.value ).to.equal( 'pinkMarker' );
+					expect( doc.selection.getAttribute( 'highlight' ) ).to.equal( 'pinkMarker' );
+				} );
 			} );
 			} );
 
 
 			describe( 'on not collapsed range', () => {
 			describe( 'on not collapsed range', () => {