fix: can not copy text other than block

This commit is contained in:
QiShaoXuan 2022-08-29 11:26:01 +08:00
parent 77e3513d6d
commit 6b6e70f02c
2 changed files with 12 additions and 8 deletions

View File

@ -72,21 +72,21 @@ export class ClipboardEventDispatcher {
);
}
private _copyHandler(e: ClipboardEvent) {
if (!this._utils.shouldHandlerContinue(e)) {
private async _copyHandler(e: ClipboardEvent) {
if (!(await this._utils.shouldHandlerContinue(e))) {
return;
}
this._editor.getHooks().onCopy(e);
}
private _cutHandler(e: ClipboardEvent) {
if (!this._utils.shouldHandlerContinue(e)) {
private async _cutHandler(e: ClipboardEvent) {
if (!(await this._utils.shouldHandlerContinue(e))) {
return;
}
this._editor.getHooks().onCut(e);
}
private _pasteHandler(e: ClipboardEvent) {
if (!this._utils.shouldHandlerContinue(e)) {
private async _pasteHandler(e: ClipboardEvent) {
if (!(await this._utils.shouldHandlerContinue(e))) {
return;
}

View File

@ -11,7 +11,7 @@ export class ClipboardUtils {
this._editor = editor;
}
shouldHandlerContinue(event: ClipboardEvent) {
async shouldHandlerContinue(event: ClipboardEvent) {
const filterNodes = ['INPUT', 'SELECT', 'TEXTAREA'];
if (event.defaultPrevented) {
@ -20,8 +20,12 @@ export class ClipboardUtils {
if (filterNodes.includes((event.target as HTMLElement)?.tagName)) {
return false;
}
const selectInfo = await this._editor.selectionManager.getSelectInfo();
return this._editor.selectionManager.currentSelectInfo.type !== 'None';
return (
selectInfo.blocks.length &&
this._editor.selectionManager.currentSelectInfo.type !== 'None'
);
}
async getClipInfoOfBlockById(blockId: string) {