| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- /**
- * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /**
- * @module link/unlinkcommand
- */
- import Command from '@ckeditor/ckeditor5-core/src/command';
- import findLinkRange from './findlinkrange';
- /**
- * The unlink command. It is used by the {@link module:link/link~Link link plugin}.
- *
- * @extends module:core/command~Command
- */
- export default class UnlinkCommand extends Command {
- /**
- * @inheritDoc
- */
- refresh() {
- this.isEnabled = this.editor.model.document.selection.hasAttribute( 'linkHref' );
- }
- /**
- * Executes the command.
- *
- * When the selection is collapsed, removes the `linkHref` attribute from each node with the same `linkHref` attribute value.
- * When the selection is non-collapsed, removes the `linkHref` attribute from each node in selected ranges.
- *
- * @fires execute
- */
- execute() {
- const model = this.editor.model;
- const selection = model.document.selection;
- model.change( writer => {
- // Get ranges to unlink.
- const rangesToUnlink = selection.isCollapsed ?
- [ findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) ) ] : selection.getRanges();
- // Remove `linkHref` attribute from specified ranges.
- for ( const range of rangesToUnlink ) {
- writer.removeAttribute( 'linkHref', range );
- }
- } );
- }
- }
|