Browse Source

A working solution.

Kamil Piechaczek 5 years ago
parent
commit
a2fd6def5e
2 changed files with 6 additions and 14 deletions
  1. 1 1
      packages/ckeditor5-link/package.json
  2. 5 13
      packages/ckeditor5-link/src/linkediting.js

+ 1 - 1
packages/ckeditor5-link/package.json

@@ -10,6 +10,7 @@
     "ckeditor5-plugin"
   ],
   "dependencies": {
+    "@ckeditor/ckeditor5-clipboard": "^20.0.0",
     "@ckeditor/ckeditor5-core": "^20.0.0",
     "@ckeditor/ckeditor5-engine": "^20.0.0",
     "@ckeditor/ckeditor5-image": "^20.0.0",
@@ -21,7 +22,6 @@
   "devDependencies": {
     "@ckeditor/ckeditor5-basic-styles": "^20.0.0",
     "@ckeditor/ckeditor5-block-quote": "^20.0.0",
-    "@ckeditor/ckeditor5-clipboard": "^20.0.0",
     "@ckeditor/ckeditor5-code-block": "^20.0.0",
     "@ckeditor/ckeditor5-editor-classic": "^20.0.0",
     "@ckeditor/ckeditor5-enter": "^20.0.0",

+ 5 - 13
packages/ckeditor5-link/src/linkediting.js

@@ -11,6 +11,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import MouseObserver from '@ckeditor/ckeditor5-engine/src/view/observer/mouseobserver';
 import TwoStepCaretMovement from '@ckeditor/ckeditor5-typing/src/twostepcaretmovement';
 import Input from '@ckeditor/ckeditor5-typing/src/input';
+import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
 import LinkCommand from './linkcommand';
 import UnlinkCommand from './unlinkcommand';
 import AutomaticDecorators from './utils/automaticdecorators';
@@ -45,7 +46,8 @@ export default class LinkEditing extends Plugin {
 	 * @inheritDoc
 	 */
 	static get requires() {
-		return [ TwoStepCaretMovement, Input ];
+		// Clipboard is required for handling cut and paste events while typing over the link.
+		return [ TwoStepCaretMovement, Input, Clipboard ];
 	}
 
 	/**
@@ -444,16 +446,6 @@ export default class LinkEditing extends Plugin {
 			deletedContent = true;
 		}, { priority: 'high' } );
 
-		// Detect when the content was cut from the editor.
-		// this.listenTo( view.document, 'cut', () => {
-		// 	deletedContent = true;
-		// }, { priority: 'high' } );
-
-		// Detect when pasting content. Attributes should not be copied.
-		// this.listenTo( view.document, 'paste', () => {
-		// 	selectionAttributes = null;
-		// }, { priority: 'high' } );
-
 		// Listening to `model#deleteContent` allows detecting whether selected content was a link.
 		// If so, before removing the element, we will copy its attributes.
 		this.listenTo( editor.model, 'deleteContent', () => {
@@ -484,8 +476,6 @@ export default class LinkEditing extends Plugin {
 		// Listening to `model#insertContent` allows detecting the content insertion.
 		// We want to apply attributes that were removed while typing over the link.
 		this.listenTo( editor.model, 'insertContent', ( evt, [ element ] ) => {
-			// eslint-disable-next-line
-			console.log( 'insertContent: isTyping', editor.plugins.get( 'Input' ).isInput( editor.model.change( writer => writer.batch ) ) );
 			deletedContent = false;
 
 			// Enabled only when typing.
@@ -539,6 +529,8 @@ function shouldCopyAttributes( positionA, positionB ) {
 	return nodeAtFirstPosition === nodeAtLastPosition;
 }
 
+// Checks whether provided changes were caused by typing.
+//
 // @params {module:core/editor/editor~Editor} editor
 // @returns {Boolean}
 function isTyping( editor ) {