8
0
Просмотр исходного кода

Temp: Added a quick fix for integration with Track Changes.

Aleksander Nowodzinski 5 лет назад
Родитель
Сommit
005a5d2931

+ 31 - 0
packages/ckeditor5-widget/src/widgettypearound/widgettypearound.js

@@ -90,6 +90,9 @@ export default class WidgetTypeAround extends Plugin {
 		this._enableTypeAroundUIInjection();
 		this._enableDetectionOfTypeAroundWidgets();
 		this._enableInsertingParagraphsOnButtonClick();
+
+		// TODO: This is a quick fix and it should be removed the proper integration arrives.
+		this._enableTemporaryTrackChangesIntegration();
 	}
 
 	/**
@@ -212,6 +215,34 @@ export default class WidgetTypeAround extends Plugin {
 			evt.stop();
 		} );
 	}
+
+	/**
+	 * A quick fix for the integration with features requiring custom handling of the `insertParagraph`
+	 * command such as Track Changes. When the `insertParagraph` command is disabled, this fix adds
+	 * a CSS class to editor roots that makes the UI disappear.
+	 *
+	 * TODO: This is a quick fix and it should be replaced by a proper integration.
+	 *
+	 * @private
+	 */
+	_enableTemporaryTrackChangesIntegration() {
+		const editor = this.editor;
+		const editingView = editor.editing.view;
+		const insertParagraphCommand = this.editor.commands.get( 'insertParagraph' );
+		const className = 'ck-widget_type-around_temp-disabled';
+
+		this.listenTo( insertParagraphCommand, 'change:isEnabled', ( evt, name, isEnabled ) => {
+			editingView.change( writer => {
+				for ( const root of editingView.document.roots ) {
+					if ( isEnabled ) {
+						writer.removeClass( className, root );
+					} else {
+						writer.addClass( className, root );
+					}
+				}
+			} );
+		} );
+	}
 }
 
 // Injects the type around UI into a view widget instance.

+ 15 - 0
packages/ckeditor5-widget/tests/widgettypearound/widgettypearound.js

@@ -308,6 +308,21 @@ describe( 'WidgetTypeAround', () => {
 		} );
 	} );
 
+	describe( '(TEMP) "Integration" with Track Changes using CSS class on roots', () => {
+		it( 'should toggle the CSS class when the InsertParagraphCommand#isEnabled changes', () => {
+			const command = editor.commands.get( 'insertParagraph' );
+
+			expect( command.isEnabled ).to.be.true;
+			expect( viewRoot.hasClass( 'ck-widget_type-around_temp-disabled' ) ).to.be.false;
+
+			command.isEnabled = false;
+			expect( viewRoot.hasClass( 'ck-widget_type-around_temp-disabled' ) ).to.be.true;
+
+			command.isEnabled = true;
+			expect( viewRoot.hasClass( 'ck-widget_type-around_temp-disabled' ) ).to.be.false;
+		} );
+	} );
+
 	function assertIsTypeAroundBefore( viewWidget, expected ) {
 		expect( viewWidget.hasClass( 'ck-widget_can-type-around_before' ) ).to.equal( expected );
 	}

+ 9 - 0
packages/ckeditor5-widget/theme/widgettypearound.css

@@ -89,3 +89,12 @@
 .ck.ck-editor__editable.ck-restricted-editing_mode_restricted .ck-widget__type-around {
 	display: none;
 }
+
+/*
+ * A quick fix for integration with track changes.
+ *
+ * TODO: To be removed when the proper integration arrives.
+ */
+.ck.ck-editor__editable.ck-widget_type-around_temp-disabled .ck-widget__type-around {
+	display: none;
+}