Skip to content

Commit

Permalink
refactor: refactor handleCopyClick function ♻️
Browse files Browse the repository at this point in the history
  • Loading branch information
MasanobuRyuman committed Jun 20, 2023
1 parent edf00d7 commit e4f1c2e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/core/src/toolmenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ export const Toolmenu: React.FC<ToolmenuProps> = ({ path, onDone }) => {
if (!textNodeList.length) {
return;
}

const [lastTextNode, lastTextPath] =
textNodeList[textNodeList.length - 1];
if (!Text.isText(lastTextNode)) {
return;
}

const lastOffset = lastTextNode.text.length;
if (!lastOffset) {
onDone();
return;
}

editor.selection = {
anchor: {
path: [...path, 0],
Expand All @@ -54,15 +57,14 @@ export const Toolmenu: React.FC<ToolmenuProps> = ({ path, onDone }) => {
},
};
await helpers.nodeHelpers.copySelectedNodeToClipBoard(editor);

const headLinePoint = {
path: [...path, 0],
offset: 0,
};
editor.selection = {
anchor: {
path: [...path, 0],
offset: 0,
},
focus: {
path: [...path, 0],
offset: 0,
},
anchor: headLinePoint,
focus: headLinePoint,
};
} else {
helpers.nodeHelpers.copySelectedNodeToClipBoard(editor);
Expand Down

0 comments on commit e4f1c2e

Please sign in to comment.