Merge pull request #92 from toeverything/bugfix/Backspace-block-in-group

fix bacakspace in group first block
This commit is contained in:
Chi Zhang 2022-08-05 10:43:59 +08:00 committed by GitHub
commit eb4589cbe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 29 deletions

View File

@ -143,13 +143,13 @@ export const ImageView: FC<ImageView> = ({ block, editor }) => {
type: 'link', type: 'link',
}); });
}; };
const handle_click = (e: React.MouseEvent<HTMLDivElement>) => { const handle_click = async (e: React.MouseEvent<HTMLDivElement>) => {
//TODO clear active selection //TODO clear active selection
// document.getElementsByTagName('body')[0].click(); // document.getElementsByTagName('body')[0].click();
e.stopPropagation(); e.stopPropagation();
e.nativeEvent.stopPropagation(); e.nativeEvent.stopPropagation();
editor.selectionManager.setSelectedNodesIds([block.id]); await editor.selectionManager.setSelectedNodesIds([block.id]);
editor.selectionManager.activeNodeByNodeId(block.id); await editor.selectionManager.activeNodeByNodeId(block.id, 'end');
}; };
const down_file = () => { const down_file = () => {
if (down_ref) { if (down_ref) {

View File

@ -99,7 +99,7 @@ export const TextView: FC<CreateTextView> = ({
if (!parentBlock) { if (!parentBlock) {
return false; return false;
} }
const preParent = await parentBlock.previousSibling();
if (Protocol.Block.Type.group === parentBlock.type) { if (Protocol.Block.Type.group === parentBlock.type) {
const children = await block.children(); const children = await block.children();
const preNode = await block.physicallyPerviousSibling(); const preNode = await block.physicallyPerviousSibling();
@ -129,34 +129,19 @@ export const TextView: FC<CreateTextView> = ({
'start' 'start'
); );
if (block.blockProvider.isEmpty()) { if (block.blockProvider.isEmpty()) {
block.remove();
}
}
return true;
} else {
// TODO remove timing problem
const prevGroupBlock = await parentBlock.previousSibling();
if (!prevGroupBlock) {
const childrenBlock = await parentBlock.children();
if (childrenBlock.length) {
if (children.length) {
await parentBlock.append(...children);
}
await block.remove(); await block.remove();
return true; const parentChild = await parentBlock.children();
if (
parentBlock.type ===
Protocol.Block.Type.group &&
!parentChild.length
) {
await editor.selectionManager.setSelectedNodesIds(
[preParent.id]
);
}
} }
parentBlock.remove();
return true;
} }
if (prevGroupBlock.type !== Protocol.Block.Type.group) {
unwrapGroup(parentBlock);
return true;
}
mergeGroup(prevGroupBlock, parentBlock);
return true; return true;
} }
} }