mirror of
https://github.com/ankitects/anki.git
synced 2025-11-11 15:17:12 -05:00
Use wantsExtendedPaste() for paste event
This commit is contained in:
parent
2239bf9b02
commit
4567c721ad
2 changed files with 12 additions and 4 deletions
|
|
@ -38,11 +38,13 @@ function imageDataToUint8Array(data: ImageData): Uint8Array {
|
|||
return typeof data === "string" ? new TextEncoder().encode(data) : data;
|
||||
}
|
||||
|
||||
async function wantsExtendedPaste(event: MouseEvent | KeyboardEvent): Promise<boolean> {
|
||||
let isShiftPressed = false;
|
||||
|
||||
async function wantsExtendedPaste(event: MouseEvent | KeyboardEvent | null = null): Promise<boolean> {
|
||||
let stripHtml = (await getConfigBool({
|
||||
key: ConfigKey_Bool.PASTE_STRIPS_FORMATTING,
|
||||
})).val;
|
||||
if (shiftPressed(event)) {
|
||||
if ((event && shiftPressed(event)) || isShiftPressed) {
|
||||
stripHtml = !stripHtml;
|
||||
}
|
||||
return !stripHtml;
|
||||
|
|
@ -322,7 +324,7 @@ async function runPreFilter(html: string, internal = false): Promise<string> {
|
|||
export async function handlePaste(event: ClipboardEvent) {
|
||||
// bridgeCommand("paste");
|
||||
event.preventDefault();
|
||||
let html = await processDataTransferEvent(event, Promise.resolve(true));
|
||||
let html = await processDataTransferEvent(event, wantsExtendedPaste());
|
||||
if (html) {
|
||||
html = await runPreFilter(html);
|
||||
pasteHTML(html, false, false);
|
||||
|
|
@ -343,6 +345,10 @@ export async function handleDragover(event: DragEvent) {
|
|||
event.preventDefault();
|
||||
}
|
||||
|
||||
export async function handleKeydown(event: KeyboardEvent) {
|
||||
isShiftPressed = shiftPressed(event);
|
||||
}
|
||||
|
||||
export function handleCutOrCopy() {
|
||||
bridgeCommand("cutOrCopy");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import { on } from "@tslib/events";
|
||||
import { promiseWithResolver } from "@tslib/promise";
|
||||
import { handleCutOrCopy, handleDragover, handleDrop, handlePaste } from "./data-transfer";
|
||||
import { handleCutOrCopy, handleDragover, handleDrop, handleKeydown, handlePaste } from "./data-transfer";
|
||||
|
||||
function bridgeCopyPasteCommands(input: HTMLElement): { destroy(): void } {
|
||||
const removePaste = on(input, "paste", handlePaste);
|
||||
|
|
@ -11,6 +11,7 @@ function bridgeCopyPasteCommands(input: HTMLElement): { destroy(): void } {
|
|||
const removeCut = on(input, "cut", handleCutOrCopy);
|
||||
const removeDragover = on(input, "dragover", handleDragover);
|
||||
const removeDrop = on(input, "drop", handleDrop);
|
||||
const removeKeydown = on(input, "keydown", handleKeydown);
|
||||
return {
|
||||
destroy() {
|
||||
removePaste();
|
||||
|
|
@ -18,6 +19,7 @@ function bridgeCopyPasteCommands(input: HTMLElement): { destroy(): void } {
|
|||
removeCut();
|
||||
removeDragover();
|
||||
removeDrop();
|
||||
removeKeydown();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue