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' }), '/api': getMenus({ base: '/api' }),
}, },
analytics: { analytics: {
baidu: 'c2e2e4254b6e4388806848d06be68a69', baidu: '285af37fc760a8f865a67cb9120bfd8f',
}, },
manifest: { manifest: {
fileName: 'manifest.json', fileName: 'manifest.json',

View File

@ -668,13 +668,8 @@ class Block implements BlockModelInterface {
} }
if (container && container.length > 0) { if (container && container.length > 0) {
if (rightNodes.length > 0) { safeRange.select(container, true);
safeRange.setStartAfter(container); safeRange.collapse(false);
safeRange.collapse(true);
} else {
safeRange.select(container, true);
safeRange.collapse(false);
}
} }
if (selection.focus) selection.focus.remove(); if (selection.focus) selection.focus.remove();
if (selection.anchor) selection.anchor.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 range = this.cloneRange();
const node = range.commonAncestorNode; const node = range.commonAncestorNode;
if (!node.isRoot() && !node.inEditor()) return; if (!node.isRoot() && !node.inEditor()) return;
@ -777,7 +780,7 @@ class Range implements RangeInterface {
let rootBeginId: string = node.attributes(DATA_ID); let rootBeginId: string = node.attributes(DATA_ID);
let rootBeginIndex: number = rootBeginId ? 0 : -1; let rootBeginIndex: number = rootBeginId ? 0 : -1;
const path = node.getPath( const path = node.getPath(
this.editor.container, root,
node.parent()?.isRoot() node.parent()?.isRoot()
? undefined ? undefined
: this.filterPath(includeCardCursor), : this.filterPath(includeCardCursor),

View File

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

View File

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