import { PastePlainTextAction } from '../actions/paste-plain-text-action';
import { PreventNewParagraphInterceptor } from '../action-handler-interceptor/prevent-new-paragraph-interceptor';
/**
 * Prevent special type input in function block.
 */
export class PreventPasteContentInterceptor extends PreventNewParagraphInterceptor {
  /**
   * Paste plain text into text block.
   *
   * @param {ActionHandlerExecution} _execution - the original execution function
   * @param {ModifyContentAction} action - the action to be intercepted
   * @param {RTETextBlock} target - the target block
   */
  intercept(_execution, action, target) {
    const { blocksToBeInserted, rteRange } = action;
    let { startNode, startOffset } = action;
    // Set the start offset from rteRange if available, this is to handle the paste issue https://gethired.atlassian.net/browse/VD-7779
    if (rteRange) {
      startNode = rteRange.startNode;
      startOffset = rteRange.startOffset;
    }
    const pastePlainTextAction = new PastePlainTextAction(blocksToBeInserted, startNode, startOffset);
    target.apply(pastePlainTextAction);
  }
}
