import { $isAtNodeEnd } from '@lexical/selection';
export function getSelectedNode(selection) {
    const anchor = selection.anchor;
    const focus = selection.focus;
    const anchorNode = selection.anchor.getNode();
    const focusNode = selection.focus.getNode();
    if (anchorNode === focusNode) {
        return anchorNode;
    }
    const isBackward = selection.isBackward();
    if (isBackward) {
        return $isAtNodeEnd(focus) ? anchorNode : focusNode;
    }
    else {
        return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
    }
}
/**
 * Extract id of hashtags from html text
 * @param html
 */
export function extractHashtags(html) {
    return Array.from(html.matchAll(/<hashtag id="(?<id>[0-9]+)">#(?<name>[^<>]+)<\/hashtag>/g)).map((match) => match.groups.id);
}
