瀏覽代碼

Fix: Fixed NaN value in a case of missing line-height property.

Oskar Wróbel 7 年之前
父節點
當前提交
02f2605121

+ 1 - 1
packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.js

@@ -267,7 +267,7 @@ export default class BlockToolbar extends Plugin {
 
 		const editableRect = new Rect( this.editor.ui.view.editableElement );
 		const contentPaddingTop = parseInt( contentComputedStyles.paddingTop );
-		const contentLineHeight = parseInt( contentComputedStyles.lineHeight );
+		const contentLineHeight = parseInt( contentComputedStyles.lineHeight ) || parseInt( contentComputedStyles.fontSize );
 
 		const position = getOptimalPosition( {
 			element: this.buttonView.element,

+ 33 - 1
packages/ckeditor5-ui/tests/toolbar/block/blocktoolbar.js

@@ -255,7 +255,7 @@ describe( 'BlockToolbar', () => {
 	} );
 
 	describe( 'attaching button to the content', () => {
-		it( 'should attach button to the left side of selected content and center with the first line on view#render', () => {
+		it( 'should attach button to the left side of selected content and center with the first line on view#render #1', () => {
 			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
 
 			const target = editor.ui.view.editableElement.querySelector( 'p' );
@@ -287,6 +287,38 @@ describe( 'BlockToolbar', () => {
 			buttonRectSpy.restore();
 		} );
 
+		it( 'should attach button to the left side of selected content and center with the first line on view#render #2', () => {
+			setData( editor.model, '<paragraph>foo[]bar</paragraph>' );
+
+			const target = editor.ui.view.editableElement.querySelector( 'p' );
+
+			target.style.fontSize = '20px';
+			target.style.paddingTop = '10px';
+
+			const editableRectSpy = sinon.stub( editor.ui.view.editableElement, 'getBoundingClientRect' ).returns( {
+				left: 100
+			} );
+
+			const targetRectSpy = sinon.stub( target, 'getBoundingClientRect' ).returns( {
+				top: 500,
+				left: 300
+			} );
+
+			const buttonRectSpy = sinon.stub( blockToolbar.buttonView.element, 'getBoundingClientRect' ).returns( {
+				width: 100,
+				height: 100
+			} );
+
+			editor.editing.view.fire( 'render' );
+
+			expect( blockToolbar.buttonView.top ).to.equal( 470 );
+			expect( blockToolbar.buttonView.left ).to.equal( 100 );
+
+			editableRectSpy.restore();
+			targetRectSpy.restore();
+			buttonRectSpy.restore();
+		} );
+
 		it( 'should reposition panelView when is opened on view#render', () => {
 			blockToolbar.panelView.isVisible = false;