fix(toPath & block.insert)

- 评论标记获取路径错误,增加 range.toPath root 参数
- block 节点插入会跳转到下一行
This commit is contained in:
yanmao 2021-12-13 00:18:22 +08:00
parent 9200b3386f
commit 4c057a901a
5 changed files with 11 additions and 11 deletions

View File

@ -331,7 +331,7 @@ export default defineConfig({
'/api': getMenus({ base: '/api' }),
},
analytics: {
baidu: 'c2e2e4254b6e4388806848d06be68a69',
baidu: '285af37fc760a8f865a67cb9120bfd8f',
},
manifest: {
fileName: 'manifest.json',

View File

@ -668,13 +668,8 @@ class Block implements BlockModelInterface {
}
if (container && container.length > 0) {
if (rightNodes.length > 0) {
safeRange.setStartAfter(container);
safeRange.collapse(true);
} else {
safeRange.select(container, true);
safeRange.collapse(false);
}
safeRange.select(container, true);
safeRange.collapse(false);
}
if (selection.focus) selection.focus.remove();
if (selection.anchor) selection.anchor.remove();

View File

@ -767,7 +767,10 @@ class Range implements RangeInterface {
};
}
toPath(includeCardCursor: boolean = false) {
toPath(
includeCardCursor: boolean = false,
root: NodeInterface = this.editor.container,
) {
const range = this.cloneRange();
const node = range.commonAncestorNode;
if (!node.isRoot() && !node.inEditor()) return;
@ -777,7 +780,7 @@ class Range implements RangeInterface {
let rootBeginId: string = node.attributes(DATA_ID);
let rootBeginIndex: number = rootBeginId ? 0 : -1;
const path = node.getPath(
this.editor.container,
root,
node.parent()?.isRoot()
? undefined
: this.filterPath(includeCardCursor),

View File

@ -305,8 +305,10 @@ export interface RangeInterface {
/**
*
* @param includeCardCursor
* @param root
*/
toPath(
includeCardCursor?: boolean,
root?: NodeInterface,
): { start: RangePath; end: RangePath } | undefined;
}

View File

@ -662,7 +662,7 @@ export default class extends MarkPlugin<Options> {
const rangePath = rangeClone
.shrinkToElementNode()
.shrinkToTextNode()
.toPath();
.toPath(undefined, container);
paths.push({
id: id.split(','),
path: rangePath