Browse Source

Refactor typing integration in autolink.

Maciej Gołaszewski 5 years ago
parent
commit
4860012dec
1 changed files with 14 additions and 8 deletions
  1. 14 8
      packages/ckeditor5-link/src/autolink.js

+ 14 - 8
packages/ckeditor5-link/src/autolink.js

@@ -54,6 +54,20 @@ export default class AutoLink extends Plugin {
 			this.isEnabled = !selection.anchor.parent.is( 'codeBlock' );
 		} );
 
+		this._enableTypingHandling();
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	afterInit() {
+		this._enableEnterHandling();
+		this._enableShiftEnterHandling();
+	}
+
+	_enableTypingHandling() {
+		const editor = this.editor;
+
 		const watcher = new TextWatcher( editor.model, text => {
 			// 1. Detect "space" after a text with a potential link.
 			if ( !isSingleSpaceAtTheEnd( text ) ) {
@@ -83,14 +97,6 @@ export default class AutoLink extends Plugin {
 		watcher.bind( 'isEnabled' ).to( this );
 	}
 
-	/**
-	 * @inheritDoc
-	 */
-	afterInit() {
-		this._enableEnterHandling();
-		this._enableShiftEnterHandling();
-	}
-
 	_enableEnterHandling() {
 		const editor = this.editor;
 		const model = editor.model;