import { getTextDirection } from "./../../ricos-content/get-text-direction.js";
import { TextSelection } from "./../../tiptap/pm/state.js";
import { findNodeById } from "./../../tiptap-editor/helpers/index.js";
const activateCaption = (view, captionId) => {
  const captionNodePos = findNodeById(view.state.tr, captionId)[0];
  if (!captionNodePos) {
    return false;
  }
  const { tr } = view.state;
  tr.setNodeAttribute(captionNodePos.pos, "showEmpty", true);
  view.dispatch(tr);
  setTimeout(() => {
    const captionNode = captionNodePos.node;
    const hasContent = captionNode.content.size > 0;
    let selectionPos = captionNodePos.pos + 1;
    if (hasContent) {
      const captionText = captionNode.textContent;
      const direction = getTextDirection(captionText);
      selectionPos = direction === "rtl" ? selectionPos : selectionPos + captionNode.content.size;
    }
    const { tr: tr2 } = view.state;
    tr2.setSelection(TextSelection.create(tr2.doc, selectionPos, selectionPos));
    view.dispatch(tr2);
    view.focus();
  }, 0);
  return true;
};
export {
  activateCaption
};
//# sourceMappingURL=activate-caption.js.map
