mirror of
https://github.com/makeplane/plane.git
synced 2025-12-16 11:57:56 +01:00
18 lines
528 B
TypeScript
18 lines
528 B
TypeScript
|
|
import { $isAtNodeEnd } from "@lexical/selection";
|
||
|
|
|
||
|
|
export const getSelectedNode = (selection: any) => {
|
||
|
|
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) ? focusNode : anchorNode;
|
||
|
|
}
|
||
|
|
};
|