feat: improved clipboard event determination conditions
This commit is contained in:
@@ -17,6 +17,18 @@ import { MarkdownParser } from './markdown-parse';
|
|||||||
|
|
||||||
// todo needs to be a switch
|
// todo needs to be a switch
|
||||||
const support_markdown_paste = true;
|
const support_markdown_paste = true;
|
||||||
|
const filterNodes = ['INPUT', 'SELECT', 'TEXTAREA'];
|
||||||
|
|
||||||
|
const shouldHandlerContinue = (event: Event, editor: Editor) => {
|
||||||
|
if (event.defaultPrevented) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (filterNodes.includes((event.target as HTMLElement)?.tagName)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return editor.selectionManager.currentSelectInfo.type !== 'None';
|
||||||
|
};
|
||||||
|
|
||||||
enum ClipboardAction {
|
enum ClipboardAction {
|
||||||
COPY = 'copy',
|
COPY = 'copy',
|
||||||
@@ -72,8 +84,7 @@ class BrowserClipboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handle_copy(e: Event) {
|
private handle_copy(e: Event) {
|
||||||
//@ts-ignore
|
if (!shouldHandlerContinue(e, this.editor)) {
|
||||||
if (e.defaultPrevented || e.target.nodeName === 'INPUT') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,33 +95,31 @@ class BrowserClipboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handle_cut(e: Event) {
|
private handle_cut(e: Event) {
|
||||||
//@ts-ignore
|
if (!shouldHandlerContinue(e, this.editor)) {
|
||||||
if (e.defaultPrevented || e.target.nodeName === 'INPUT') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dispatch_clipboard_event(ClipboardAction.CUT, e as ClipboardEvent);
|
this.dispatch_clipboard_event(ClipboardAction.CUT, e as ClipboardEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handle_paste(e: Event) {
|
private handle_paste(e: Event) {
|
||||||
//@ts-ignore TODO should be handled more scientifically here, whether to trigger the paste time, also need some whitelist mechanism
|
if (!shouldHandlerContinue(e, this.editor)) {
|
||||||
if (e.defaultPrevented || e.target.nodeName === 'INPUT') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
const clipboardData = (e as ClipboardEvent).clipboardData;
|
const clipboardData = (e as ClipboardEvent).clipboardData;
|
||||||
|
|
||||||
const isPureFile = this.is_pure_file_in_clipboard(clipboardData);
|
const isPureFile = this.is_pure_file_in_clipboard(clipboardData);
|
||||||
|
|
||||||
if (!isPureFile) {
|
if (isPureFile) {
|
||||||
this.paste_content(clipboardData);
|
|
||||||
} else {
|
|
||||||
this.paste_file(clipboardData);
|
this.paste_file(clipboardData);
|
||||||
|
} else {
|
||||||
|
this.paste_content(clipboardData);
|
||||||
}
|
}
|
||||||
// this.editor.selectionManager
|
// this.editor.selectionManager
|
||||||
// .getSelectInfo()
|
// .getSelectInfo()
|
||||||
// .then(selectionInfo => console.log(selectionInfo));
|
// .then(selectionInfo => console.log(selectionInfo));
|
||||||
|
|
||||||
e.stopPropagation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private paste_content(clipboardData: any) {
|
private paste_content(clipboardData: any) {
|
||||||
|
|||||||
@@ -115,10 +115,8 @@ export default class ClipboardParse {
|
|||||||
const block_utils = this.editor.getView(
|
const block_utils = this.editor.getView(
|
||||||
ClipboardParse.block_types[i]
|
ClipboardParse.block_types[i]
|
||||||
);
|
);
|
||||||
const blocks =
|
const blocks = block_utils?.html2block?.(el, this.parse_dom);
|
||||||
block_utils &&
|
|
||||||
block_utils.html2block &&
|
|
||||||
block_utils.html2block(el, this.parse_dom);
|
|
||||||
if (blocks) {
|
if (blocks) {
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user