Procházet zdrojové kódy

Fix: Selection attribute is not updated on consecutive `HighlightCommand#execute()` calls.

Maciej Gołaszewski před 7 roky
rodič
revize
2f351476f9

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

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

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

@@ -172,6 +172,22 @@ describe( 'HighlightCommand', () => {
 					expect( command.value ).to.be.undefined;
 					expect( doc.selection.hasAttribute( 'highlight' ) ).to.be.false;
 				} );
+
+				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.hasAttribute( 'highlight' ) ).to.be.true;
+
+					command.execute( { value: 'pinkMarker' } );
+
+					expect( command.value ).to.equal( 'pinkMarker' );
+					expect( doc.selection.hasAttribute( 'highlight' ) ).to.be.true;
+				} );
 			} );
 
 			describe( 'on not collapsed range', () => {