浏览代码

Merge branch 'master' into t/27

# Conflicts:
#	src/mentionui.js
#	tests/mentionui.js
Maciej Gołaszewski 6 年之前
父节点
当前提交
76c4a8d52e

+ 11 - 0
packages/ckeditor5-mention/src/mentionui.js

@@ -448,6 +448,17 @@ export default class MentionUI extends Plugin {
 
 				return rangeRects.pop();
 			},
+			limiter: () => {
+				const view = this.editor.editing.view;
+				const viewDocument = view.document;
+				const editableElement = viewDocument.selection.editableElement;
+
+				if ( editableElement ) {
+					return view.domConverter.mapViewToDom( editableElement.root );
+				}
+
+				return null;
+			},
 			positions: getBalloonPanelPositions( preferredPosition )
 		};
 	}

文件差异内容过多而无法显示
+ 0 - 12
packages/ckeditor5-mention/tests/manual/mention-custom-renderer.html


文件差异内容过多而无法显示
+ 0 - 12
packages/ckeditor5-mention/tests/manual/mention-custom-view.html


文件差异内容过多而无法显示
+ 0 - 12
packages/ckeditor5-mention/tests/manual/mention.html


+ 34 - 8
packages/ckeditor5-mention/tests/mentionui.js

@@ -145,6 +145,8 @@ describe( 'MentionUI', () => {
 		} );
 
 		it( 'should properly calculate position data', () => {
+			const editableElement = editingView.document.selection.editableElement;
+
 			setData( model, '<paragraph>foo []</paragraph>' );
 			stubSelectionRects( [ caretRect ] );
 
@@ -157,11 +159,13 @@ describe( 'MentionUI', () => {
 			return waitForDebounce()
 				.then( () => {
 					const pinArgument = pinSpy.firstCall.args[ 0 ];
-					const { target, positions } = pinArgument;
+					const { target, positions, limiter, fitInViewport } = pinArgument;
 
 					expect( positions ).to.have.length( 4 );
 
-					expect( pinArgument.fitInViewport ).to.be.undefined;
+					// Mention UI should set limiter to the editable area.
+					expect( limiter() ).to.equal( editingView.domConverter.mapViewToDom( editableElement ) );
+					expect( fitInViewport ).to.be.undefined;
 
 					expect( editor.model.markers.has( 'mention' ) ).to.be.true;
 					const mentionMarker = editor.model.markers.get( 'mention' );
@@ -191,18 +195,18 @@ describe( 'MentionUI', () => {
 						top: 121
 					} );
 
-					expect( caretNorthEast( caretRect, balloonRect ) ).to.deep.equal( {
-						left: 501,
-						name: 'caret_ne',
-						top: -53
-					} );
-
 					expect( caretSouthWest( caretRect, balloonRect ) ).to.deep.equal( {
 						left: 301,
 						name: 'caret_sw',
 						top: 121
 					} );
 
+					expect( caretNorthEast( caretRect, balloonRect ) ).to.deep.equal( {
+						left: 501,
+						name: 'caret_ne',
+						top: -53
+					} );
+
 					expect( caretNorthWest( caretRect, balloonRect ) ).to.deep.equal( {
 						left: 301,
 						name: 'caret_nw',
@@ -247,6 +251,28 @@ describe( 'MentionUI', () => {
 					expect( positions[ 0 ].name ).to.equal( positionAfterFirstShow );
 				} );
 		} );
+
+		it( 'does not fail if selection has no #editableElement', () => {
+			setData( model, '<paragraph>foo []</paragraph>' );
+			stubSelectionRects( [ caretRect ] );
+
+			expect( editor.model.markers.has( 'mention' ) ).to.be.false;
+
+			model.change( writer => {
+				writer.insertText( '@', doc.selection.getFirstPosition() );
+			} );
+
+			return waitForDebounce()
+				.then( () => {
+					const pinArgument = pinSpy.firstCall.args[ 0 ];
+					const { limiter } = pinArgument;
+
+					sinon.stub( editingView.document.selection, 'editableElement' ).value( null );
+
+					// Should not break;
+					expect( limiter() ).to.be.null;
+				} );
+		} );
 	} );
 
 	describe( 'typing integration', () => {