Parcourir la source

Add removing custom attributes to unlink command.

Mateusz Samsel il y a 6 ans
Parent
commit
363ce8c4d0
1 fichiers modifiés avec 8 ajouts et 0 suppressions
  1. 8 0
      packages/ckeditor5-link/src/unlinkcommand.js

+ 8 - 0
packages/ckeditor5-link/src/unlinkcommand.js

@@ -32,8 +32,10 @@ export default class UnlinkCommand extends Command {
 	 * @fires execute
 	 */
 	execute() {
+		const editor = this.editor;
 		const model = this.editor.model;
 		const selection = model.document.selection;
+		const linkCommand = editor.commands.get( 'link' );
 
 		model.change( writer => {
 			// Get ranges to unlink.
@@ -43,6 +45,12 @@ export default class UnlinkCommand extends Command {
 			// Remove `linkHref` attribute from specified ranges.
 			for ( const range of rangesToUnlink ) {
 				writer.removeAttribute( 'linkHref', range );
+				// If there are registered custom attributes, then remove them during unlink.
+				if ( linkCommand ) {
+					linkCommand.customAttributes.forEach( ( val, key ) => {
+						writer.removeAttribute( key, range );
+					} );
+				}
 			}
 		} );
 	}