Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
MasanobuRyuman committed Jun 19, 2023
1 parent d458635 commit 813eae2
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/core/src/toolmenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,28 @@ export const Toolmenu: React.FC<ToolmenuProps> = ({ path, onDone }) => {
const handleCopyClick = useCallback(async () => {
const selection = editor.selection;
if (!selection || selection.anchor.offset === selection.focus.offset) {
const node = Node.get(editor, path);
if (!Element.isElement(node)) return;
const lastChildIndex = node.children.length - 1;
const lastNode = node.children[lastChildIndex];
if (!Text.isText(lastNode)) return;
const lastOffset = lastNode.text.length;
const textNodeList = Array.from(
editor.nodes({
at: path,
match: (node) => Text.isText(node),
})
);
if (!textNodeList.length) {
return;
}
const lastTextPath = textNodeList[textNodeList.length - 1][1];
const lastTextNode = textNodeList[textNodeList.length - 1][0];
if (!Text.isText(lastTextNode)) {
return;
}
const lastOffset = lastTextNode.text.length;
editor.selection = {
anchor: {
path: [...path, 0],
offset: 0,
},
focus: {
path: [...path, lastChildIndex],
path: lastTextPath,
offset: lastOffset,
},
};
Expand Down

0 comments on commit 813eae2

Please sign in to comment.