@tohuhono/puck-rich-text
Version:
A puck component for rich text editing made for OberonCMS
20 lines (19 loc) • 541 B
JavaScript
import { $isAtNodeEnd } from "@lexical/selection";
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;
}
}
export {
getSelectedNode
};