import { DeleteLinkGroupAction } from '../../actions/delete-link-group-action';
import { ActionHandleStrategy } from '../action-handle-strategy.abstract';
/**
 * Update the editor text node text content strategy.
 */
export class NodeUpdateTextStrategy extends ActionHandleStrategy {
  /**
   * Updates the text content of a node and unlink the node if it is a link node and the text is deleted.
   *
   * @param {UpdateTextAction} action - The update text action instance.
   * @param {RTETextNode} target - The text node instance which need update the text.
   */
  handleAction(action, target) {
    target.text = action.newTextContent;
    // The link node should unlink when delete all text
    if (!target.text && target.annotationMap.has('LINK')) {
      target.apply(new DeleteLinkGroupAction());
    }
  }
}
