feat: fix backspeace

This commit is contained in:
SaikaSakura
2022-08-10 16:07:52 +08:00
parent 4c9f04bc1c
commit 8183552011
2 changed files with 15 additions and 7 deletions

View File

@@ -112,13 +112,18 @@ export const TextView: FC<CreateTextView> = ({
block.id, block.id,
'end' 'end'
); );
const value = [ if (
...preNode.getProperty('text').value, block.getProperty('text').value[0] &&
...block.getProperty('text').value, block.getProperty('text').value[0]?.text !== ''
]; ) {
await preNode.setProperty('text', { const value = [
value, ...preNode.getProperty('text').value,
}); ...block.getProperty('text').value,
];
await preNode.setProperty('text', {
value,
});
}
await preNode.append(...children); await preNode.append(...children);
await block.remove(); await block.remove();
editor.suspend(false); editor.suspend(false);

View File

@@ -83,6 +83,9 @@ export const CommandMenu = ({ editor, hooks, style }: CommandMenuProps) => {
async (event: React.KeyboardEvent<HTMLDivElement>) => { async (event: React.KeyboardEvent<HTMLDivElement>) => {
const { type, anchorNode } = editor.selection.currentSelectInfo; const { type, anchorNode } = editor.selection.currentSelectInfo;
// console.log(await editor.getBlockById(anchorNode.id)); // console.log(await editor.getBlockById(anchorNode.id));
if (!anchorNode?.id) {
return;
}
const activeBlock = await editor.getBlockById(anchorNode.id); const activeBlock = await editor.getBlockById(anchorNode.id);
if (activeBlock.type === Protocol.Block.Type.page) { if (activeBlock.type === Protocol.Block.Type.page) {
return; return;