diff --git a/config/config.ts b/config/config.ts index daac109b..bf410889 100644 --- a/config/config.ts +++ b/config/config.ts @@ -79,5 +79,9 @@ export default defineConfig({ pathRewrite: { '^/api': '' }, }, }, + // scripts: [ + // 'https://unpkg.com/vconsole/dist/vconsole.min.js', + // 'var vConsole = new window.VConsole();', + // ], // more config: https://d.umijs.org/config }); diff --git a/packages/engine/src/card/entry.ts b/packages/engine/src/card/entry.ts index 319d0d20..22bbc522 100644 --- a/packages/engine/src/card/entry.ts +++ b/packages/engine/src/card/entry.ts @@ -378,10 +378,15 @@ abstract class CardEntry this.resizeModel?.render(container); } } - this.toolbarModel?.hide(); - this.toolbarModel?.destroy(); if (this.toolbar) { - this.toolbarModel = new Toolbar(this.editor, this); + if (!this.toolbarModel) + this.toolbarModel = new Toolbar(this.editor, this); + if (this.activated) { + this.toolbarModel.show(); + } + } else { + this.toolbarModel?.hide(); + this.toolbarModel?.destroy(); } if (this.isEditable) { this.editor.nodeId.generateAll(this.getCenter().get()!); diff --git a/packages/engine/src/change/index.ts b/packages/engine/src/change/index.ts index 718d7af0..63c5f347 100644 --- a/packages/engine/src/change/index.ts +++ b/packages/engine/src/change/index.ts @@ -480,10 +480,13 @@ class ChangeModel implements ChangeInterface { } // 被删除了重新设置开始节点位置 if (startRange && !startRange.node[0].parentNode) { - startRange = { - node: appendNodes[0], - offset: 0, - }; + const parent = node.parent(); + if (parent) { + startRange = { + node: parent, + offset: node.index(), + }; + } } node = next; } diff --git a/packages/engine/src/change/native-event.ts b/packages/engine/src/change/native-event.ts index 7d7cd21b..bf44931f 100644 --- a/packages/engine/src/change/native-event.ts +++ b/packages/engine/src/change/native-event.ts @@ -4,6 +4,7 @@ import { CARD_RIGHT_SELECTOR, CARD_SELECTOR, DATA_ELEMENT, + DATA_ID, EDITABLE, ROOT, ROOT_SELECTOR, @@ -550,11 +551,27 @@ class NativeEvent { range, (range) => { this.engine.trigger('paste:insert', range); - this.#lastePasteRange = range.cloneRange(); + const cloneRange = range.cloneRange(); + const { endNode } = cloneRange; + let cardId = ''; + if (endNode.isCard() && endNode.children().length === 0) { + cloneRange.setEndAfter(endNode); + cardId = endNode.attributes(DATA_ID); + } + this.#lastePasteRange = cloneRange; range.collapse(false); const selection = range.createSelection(); this.engine.card.render(undefined, (count) => { selection.move(); + if (cardId) { + const newCard = this.engine.container.find( + `[data-id="${cardId}"]`, + ); + if (newCard.length > 0) { + cloneRange.setEndAfter(newCard); + this.#lastePasteRange = cloneRange; + } + } range.scrollRangeIntoView(); change.range.select(range); if (callback) { diff --git a/packages/engine/src/inline/index.ts b/packages/engine/src/inline/index.ts index fb98972d..8350b980 100644 --- a/packages/engine/src/inline/index.ts +++ b/packages/engine/src/inline/index.ts @@ -1057,7 +1057,10 @@ class Inline implements InlineModelInterface { flat(node: NodeInterface | RangeInterface, schema?: SchemaInterface) { if (isRangeInterface(node)) { - const selection = node.shrinkToElementNode().createSelection(); + const selection = node + .cloneRange() + .shrinkToElementNode() + .createSelection(); const inlines = this.findInlines(node); inlines.forEach((inline) => { if (inline.isCard()) return; diff --git a/packages/engine/src/list/index.ts b/packages/engine/src/list/index.ts index 57ce2595..a4d31d3a 100644 --- a/packages/engine/src/list/index.ts +++ b/packages/engine/src/list/index.ts @@ -455,7 +455,7 @@ class List implements ListModelInterface { const safeRange = range || change.range.toTrusty(); const selection = blocks ? undefined - : safeRange.shrinkToElementNode().createSelection(); + : safeRange.cloneRange().shrinkToElementNode().createSelection(); blocks = blocks || block.getBlocks(safeRange); blocks.forEach((block) => { block = block.closest('ul,ol'); diff --git a/packages/engine/src/request/index.ts b/packages/engine/src/request/index.ts index 51ce91a8..578321ac 100644 --- a/packages/engine/src/request/index.ts +++ b/packages/engine/src/request/index.ts @@ -57,8 +57,7 @@ class Request implements RequestInterface { } else if (!!input['fireEvent']) { input['fireEvent'](event); } else throw ''; - - //document.addEventListener('mousedown', remove); + document.addEventListener('mousedown', remove); } catch (error) { input.removeEventListener('change', change); remove();