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.

typing: Prevent `input` event from being called many times during paste.

Aman Agrawalb3f037e5255b
diff --git a/web/src/typing.ts b/web/src/typing.ts
index 942d3b25b79..41b403c1972 100644
--- a/web/src/typing.ts
+++ b/web/src/typing.ts
@@ -1,4 +1,5 @@
import $ from "jquery";
+import _ from "lodash";
import assert from "minimalistic-assert";
import * as blueslip from "./blueslip.ts";
@@ -234,17 +235,21 @@ export function initialize(): void {
notify_server_editing_stop,
};
- $(document).on("input", "#compose-textarea", () => {
- // If our previous state was no typing notification, send a
- // start-typing notice immediately.
- const new_recipient = is_valid_conversation() ? get_recipient() : null;
- typing_status.update(
- worker,
- new_recipient,
- realm.server_typing_started_wait_period_milliseconds,
- realm.server_typing_stopped_wait_period_milliseconds,
- );
- });
+ $(document).on(
+ "input",
+ "#compose-textarea",
+ _.throttle(() => {
+ // If our previous state was no typing notification, send a
+ // start-typing notice immediately.
+ const new_recipient = is_valid_conversation() ? get_recipient() : null;
+ typing_status.update(
+ worker,
+ new_recipient,
+ realm.server_typing_started_wait_period_milliseconds,
+ realm.server_typing_stopped_wait_period_milliseconds,
+ );
+ }, 25),
+ );
$("body").on("input", ".message_edit_content", function (this: HTMLElement) {
const $message_row = $(this).closest(".message_row");