import { ModifyContentAction, ModifyContentActionType } from './modify-content-action.abstract';
/**
 * Update the cursor position in the editor.
 *
 * @example richEditorRef.value.apply(new UpdateCursorPositionAction(nextFocusNode, [offset], [immediatelyRun]))
 */
export class UpdateCursorPositionAction extends ModifyContentAction {
  /**
   * Set the cursor position at end of the current node.
   *
   * @param {RTENode} nextFocusNode - The rich text editor needs focus node.
   * @param {number} offset - The cursor offset position.
   * @param {boolean} immediatelyRun - Whether to immediately set the cursor position after applying it. Usually the set action will trigger after the UI renders.
   */
  constructor(nextFocusNode, offset, immediatelyRun = false) {
    super();
    this.isFlushable = true;
    this.type = ModifyContentActionType.UPDATE_CURSOR_POSITION;
    this.immediatelyRun = false;
    this.nextFocusNode = nextFocusNode;
    this.offset = offset;
    this.immediatelyRun = immediatelyRun;
    // Don't flush changes if we want to immediately run the cursor update. Usually the current value is the latest value.
    if (this.immediatelyRun) {
      this.isFlushable = false;
    }
  }
}
