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_messages: Extract restore_original_selection.

Tim Abbott26355df8e98d
diff --git a/web/src/copy_messages.ts b/web/src/copy_messages.ts
index a77a84dbcd9..673d3b2f16f 100644
--- a/web/src/copy_messages.ts
+++ b/web/src/copy_messages.ts
@@ -127,18 +127,15 @@ function select_div($div: JQuery, selection: Selection): void {
selection.selectAllChildren(util.the($div));
}
-function remove_div(_div: JQuery, ranges: Range[]): void {
- window.setTimeout(() => {
- const selection = window.getSelection();
- assert(selection !== null);
- selection.removeAllRanges();
-
- for (const range of ranges) {
- selection.addRange(range);
- }
+function restore_original_selection(ranges: Range[]): void {
+ // Should be called inside a setTimeout(..., 0).
+ const selection = window.getSelection();
+ assert(selection !== null);
+ selection.removeAllRanges();
- $("#copytempdiv").remove();
- }, 0);
+ for (const range of ranges) {
+ selection.addRange(range);
+ }
}
function copy_selection_to_clipboard(selection: Selection): void {
@@ -292,7 +289,11 @@ export function copy_handler(): void {
select_div($div, selection);
// eslint-disable-next-line @typescript-eslint/no-deprecated
document.execCommand("copy");
- remove_div($div, ranges);
+ setTimeout(() => {
+ restore_original_selection(ranges);
+
+ $div.remove();
+ }, 0);
}
export function analyze_selection(selection: Selection): {