瀏覽代碼

Refactor typing integration in autolink.

Maciej Gołaszewski 5 年之前
父節點
當前提交
4860012dec
共有 1 個文件被更改,包括 14 次插入8 次删除
  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;