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

Hide panel on matched text inside other mention when UI is still waiting for a feed.

Maciej Gołaszewski 6 лет назад
Родитель
Сommit
ab796b3817

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

@@ -366,6 +366,8 @@ export default class MentionUI extends Plugin {
 			const nodeBefore = focus.nodeBefore;
 
 			if ( hasMention || nodeBefore && nodeBefore.is( 'text' ) && nodeBefore.hasAttribute( 'mention' ) ) {
+				this._hideUIAndRemoveMarker();
+
 				return;
 			}
 

+ 36 - 1
packages/ckeditor5-mention/tests/mentionui.js

@@ -977,7 +977,6 @@ describe( 'MentionUI', () => {
 				feedCallbackTimeout = 500;
 
 				return Promise.resolve()
-				// .then( waitForDebounce )
 					.then( waitForDebounce )
 					.then( wait( 20 ) )
 					.then( () => {
@@ -1000,6 +999,42 @@ describe( 'MentionUI', () => {
 						sinon.assert.calledOnce( selectFirstMentionSpy );
 					} );
 			} );
+
+			it( 'should not show panel if selection was moved during fetching a feed', () => {
+				setData( model, '<paragraph>foo [#101] bar</paragraph><paragraph></paragraph>' );
+
+				model.change( writer => {
+					writer.setAttribute( 'mention', { id: '#101', _uid: 1234 }, doc.selection.getFirstRange() );
+				} );
+
+				// Increase the response time to extend the debounce time out.
+				feedCallbackTimeout = 300;
+
+				model.change( writer => {
+					writer.setSelection( doc.getRoot().getChild( 1 ), 0 );
+					writer.insertText( '#', doc.selection.getFirstPosition() );
+				} );
+
+				sinon.assert.notCalled( feedCallbackStub );
+
+				return Promise.resolve()
+					.then( waitForDebounce )
+					.then( () => {
+						sinon.assert.calledOnce( feedCallbackStub );
+
+						model.change( writer => {
+							writer.setSelection( doc.getRoot().getChild( 0 ), 6 );
+						} );
+
+						expect( panelView.isVisible ).to.be.false;
+					} )
+					.then( waitForDebounce )
+					.then( wait( 20 ) )
+					.then( () => {
+						expect( panelView.isVisible ).to.be.false;
+						expect( editor.model.markers.has( 'mention' ) ).to.be.false;
+					} );
+			} );
 		} );
 	} );