Преглед на файлове

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

Maciej Gołaszewski преди 7 години
родител
ревизия
2f351476f9
променени са 2 файла, в които са добавени 17 реда и са изтрити 0 реда
  1. 1 0
      packages/ckeditor5-highlight/src/highlightcommand.js
  2. 16 0
      packages/ckeditor5-highlight/tests/highlightcommand.js

+ 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', () => {