fix: paste

This commit is contained in:
yanmao 2022-01-11 16:54:25 +08:00
parent b467b65edb
commit 5673538b8e
7 changed files with 43 additions and 12 deletions

View File

@ -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
});

View File

@ -378,10 +378,15 @@ abstract class CardEntry<T extends CardValue = CardValue>
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<Element>()!);

View File

@ -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;
}

View File

@ -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) {

View File

@ -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;

View File

@ -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');

View File

@ -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();