fix: inline 卡片删除后光标位置错误

This commit is contained in:
yanmao 2021-12-20 12:51:05 +08:00
parent d93c2ba7f5
commit 82cb61d7be
1 changed files with 13 additions and 2 deletions

View File

@ -56,14 +56,20 @@ class Backspace {
if (!card) {
// 光标前面有Card并且不是自定义列表移除卡片
const prevNode = range.getPrevNode();
const prevParent = prevNode?.parent();
if (
!event['isDelete'] &&
prevNode &&
prevNode.isCard() &&
!this.engine.node.isCustomize(prevNode)
(!prevParent || !this.engine.node.isCustomize(prevParent))
) {
event.preventDefault();
const cloneRange = range.cloneRange();
cloneRange.setStartBefore(prevNode);
cloneRange.collapse(true);
this.engine.card.remove(prevNode);
cloneRange.handleBr();
change.range.select(cloneRange.shrinkToTextNode());
return false;
}
return true;
@ -94,8 +100,13 @@ class Backspace {
const cardRight = range.startNode.closest(CARD_RIGHT_SELECTOR);
if (cardRight.length > 0) {
event.preventDefault();
const cloneRange = range.cloneRange();
cloneRange.setStartBefore(card.root);
cloneRange.collapse(true);
this.engine.card.remove(card.id);
range.handleBr();
cloneRange.handleBr();
change.range.select(cloneRange.shrinkToTextNode());
return false;
}
} else {