Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

copy_and_paste: Reuse `execute_copy` for clipboard.

apoorvapendseff8ffbc2fa81
diff --git a/web/src/clipboard_handler.ts b/web/src/clipboard_handler.ts
index f648f15c138..29b10fda421 100644
--- a/web/src/clipboard_handler.ts
+++ b/web/src/clipboard_handler.ts
@@ -8,7 +8,7 @@ import * as topic_link_util from "./topic_link_util.ts";
// The standard Clipboard API do not support custom mime types like
// text/x-gfm, but this approach does.
-function execute_copy(handle_copy_event: (e: ClipboardEvent) => void): void {
+export function execute_copy(handle_copy_event: (e: ClipboardEvent) => void): void {
document.addEventListener("copy", handle_copy_event);
// eslint-disable-next-line @typescript-eslint/no-deprecated
document.execCommand("copy");
diff --git a/web/src/copy_and_paste.ts b/web/src/copy_and_paste.ts
index d7b7948b4e8..b01db480f40 100644
--- a/web/src/copy_and_paste.ts
+++ b/web/src/copy_and_paste.ts
@@ -5,6 +5,7 @@ import assert from "minimalistic-assert";
import {insertTextIntoField} from "text-field-edit";
import TurndownService from "turndown";
+import * as clipboard_handler from "./clipboard_handler.ts";
import * as compose_ui from "./compose_ui.ts";
import * as hash_util from "./hash_util.ts";
import * as message_lists from "./message_lists.ts";
@@ -177,10 +178,7 @@ async function copy_selection_to_clipboard(selection: Selection): Promise<void>
e.clipboardData?.setData("text/plain", plain_text);
e.preventDefault();
};
- document.addEventListener("copy", cb);
- // eslint-disable-next-line @typescript-eslint/no-deprecated
- document.execCommand("copy");
- document.removeEventListener("copy", cb);
+ clipboard_handler.execute_copy(cb);
}
}