8
0
Эх сурвалжийг харах

Fix error on "enter" when link is selected.

panr 5 жил өмнө
parent
commit
ec3c2368a1

+ 4 - 0
packages/ckeditor5-link/src/autolink.js

@@ -147,6 +147,10 @@ export default class AutoLink extends Plugin {
 		enterCommand.on( 'execute', () => {
 			const position = model.document.selection.getFirstPosition();
 
+			if ( !position.parent.previousSibling ) {
+				return;
+			}
+
 			const rangeToCheck = model.createRange(
 				model.createPositionAt( position.parent.previousSibling, 0 ),
 				model.createPositionAt( position.parent.previousSibling, 'end' )

+ 20 - 0
packages/ckeditor5-link/tests/autolink.js

@@ -110,6 +110,26 @@ describe( 'AutoLink', () => {
 			);
 		} );
 
+		it( 'does not add linkHref attribute on enter when the link is selected', () => {
+			setData( model, '<paragraph>[https://www.cksource.com]</paragraph>' );
+
+			editor.execute( 'enter' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>[]</paragraph>'
+			);
+		} );
+
+		it( 'does not add linkHref attribute on enter when the whole paragraph containing the link is selected', () => {
+			setData( model, '<paragraph>[This feature also works with e-mail addresses: https://www.cksource.com]</paragraph>' );
+
+			editor.execute( 'enter' );
+
+			expect( getData( model ) ).to.equal(
+				'<paragraph>[]</paragraph>'
+			);
+		} );
+
 		it( 'adds linkHref attribute to a text link after space (inside paragraph)', () => {
 			setData( model, '<paragraph>Foo Bar [] Baz</paragraph>' );