Selaa lähdekoodia

Renamed paragraph's command method _updateValue to refreshValue and changed its visibility.

Szymon Kupś 8 vuotta sitten
vanhempi
sitoutus
9e1a2faf83

+ 2 - 4
packages/ckeditor5-paragraph/src/paragraphcommand.js

@@ -37,7 +37,7 @@ export default class ParagraphCommand extends Command {
 
 		// Update current value each time changes are done on document.
 		this.listenTo( editor.document, 'changesDone', () => {
-			this._updateValue();
+			this.refreshValue();
 			this.refreshState();
 		} );
 	}
@@ -70,10 +70,8 @@ export default class ParagraphCommand extends Command {
 
 	/**
 	 * Updates command's {@link #value value} based on current selection.
-	 *
-	 * @private
 	 */
-	_updateValue() {
+	refreshValue() {
 		const block = first( this.editor.document.selection.getSelectedBlocks() );
 
 		this.value = !!block && block.is( 'paragraph' );

+ 12 - 0
packages/ckeditor5-paragraph/tests/paragraphcommand.js

@@ -85,6 +85,18 @@ describe( 'ParagraphCommand', () => {
 
 			expect( command.value ).to.be.false;
 		} );
+
+		it( 'should be refreshed after calling refreshValue()', () => {
+			setData( document, '<paragraph>[foo]</paragraph><notBlock>foo</notBlock>' );
+			const element = document.getRoot().getChild( 1 );
+
+			// Purposely not putting it in `document.enqueueChanges` to update command manually.
+			document.selection.setRanges( [ Range.createIn( element ) ] );
+
+			expect( command.value ).to.be.true;
+			command.refreshValue();
+			expect( command.value ).to.be.false;
+		} );
 	} );
 
 	describe( '_doExecute', () => {