瀏覽代碼

The mention ui should prefer position below the caret.

Maciej Gołaszewski 6 年之前
父節點
當前提交
07adc7c8a4
共有 2 個文件被更改,包括 8 次插入44 次删除
  1. 2 14
      packages/ckeditor5-mention/src/mentionui.js
  2. 6 30
      packages/ckeditor5-mention/tests/mentionui.js

+ 2 - 14
packages/ckeditor5-mention/src/mentionui.js

@@ -435,19 +435,7 @@ 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( positionName ),
-			fitInViewport: true
+			positions: getBalloonPanelPositions( positionName )
 		};
 	}
 }
@@ -504,8 +492,8 @@ function getBalloonPanelPositions( positionName ) {
 	// As default return all positions callbacks.
 	return [
 		positions.caret_se,
-		positions.caret_ne,
 		positions.caret_sw,
+		positions.caret_ne,
 		positions.caret_nw
 	];
 }

+ 6 - 30
packages/ckeditor5-mention/tests/mentionui.js

@@ -137,8 +137,6 @@ describe( 'MentionUI', () => {
 		} );
 
 		it( 'should properly calculate position data', () => {
-			const editableElement = editingView.document.selection.editableElement;
-
 			setData( model, '<paragraph>foo []</paragraph>' );
 			stubSelectionRects( [ caretRect ] );
 
@@ -151,13 +149,13 @@ describe( 'MentionUI', () => {
 			return waitForDebounce()
 				.then( () => {
 					const pinArgument = pinSpy.firstCall.args[ 0 ];
-					const { target, positions, limiter, fitInViewport } = pinArgument;
+					const { target, positions } = pinArgument;
 
-					expect( fitInViewport ).to.be.true;
 					expect( positions ).to.have.length( 4 );
 
-					// Mention UI should set limiter to the editable area.
-					expect( limiter() ).to.equal( editingView.domConverter.mapViewToDom( editableElement ) );
+					// Mention UI should not set limiter or default values.
+					expect( pinArgument.limiter ).to.be.undefined;
+					expect( pinArgument.fitInViewport ).to.be.undefined;
 
 					expect( editor.model.markers.has( 'mention' ) ).to.be.true;
 					const mentionMarker = editor.model.markers.get( 'mention' );
@@ -177,8 +175,8 @@ describe( 'MentionUI', () => {
 					expect( mentionMarker.getRange().isEqual( range ), 'Should position to mention marker.' );
 
 					const caretSouthEast = positions[ 0 ];
-					const caretNorthEast = positions[ 1 ];
-					const caretSouthWest = positions[ 2 ];
+					const caretSouthWest = positions[ 1 ];
+					const caretNorthEast = positions[ 2 ];
 					const caretNorthWest = positions[ 3 ];
 
 					expect( caretSouthEast( caretRect, balloonRect ) ).to.deep.equal( {
@@ -243,28 +241,6 @@ 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', () => {