import changeManager from '../../../../../helpers/change-manager/change-manager';
import domNodeSubjectFactory from '../../../../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-factory';
import { VegaInternalUpdateRTECursorPosition } from '../../../../../helpers/event-manager/event-id/vega-internal-event-id';
import stateEntityRenderingRegistry from '../../../slimmers/controllers/state-entity-rendering-registry';
import { ActionHandleStrategy } from '../action-handle-strategy.abstract';
/**
 * Update the cursor position in the editor.
 */
export class UpdateCursorPositionStrategy extends ActionHandleStrategy {
  /**
   * @inheritDoc
   */
  handleAction(action, target) {
    const { offset, nextFocusNode, immediatelyRun } = action;
    const host = stateEntityRenderingRegistry.getDOMByEntity(target);
    if (host) {
      changeManager.notify(domNodeSubjectFactory.getSubject(host, VegaInternalUpdateRTECursorPosition), {
        node: nextFocusNode,
        offset,
        updateDirectly: immediatelyRun,
      });
    }
  }
}
