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.

composebox_typeahead: Fix topic completion broken for long stream names.

Aman Agrawal6d30b10b6006
diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.ts
index 3ee4539d650..da00d08208b 100644
--- a/web/src/composebox_typeahead.ts
+++ b/web/src/composebox_typeahead.ts
@@ -43,6 +43,9 @@ import type {UserPillData} from "./user_pill.ts";
import {user_settings} from "./user_settings.ts";
import * as util from "./util.ts";
+/* Maximum channel name length + link syntax (#**>**) + some topic characters */
+const MAX_LOOKBACK_FOR_TYPEAHEAD_COMPLETION = 60 + 6 + 20;
+
// **********************************
// AN IMPORTANT NOTE ABOUT TYPEAHEADS
// **********************************
@@ -423,7 +426,7 @@ export function tokenize_compose_str(s: string): string {
// We limit how far back to scan to limit potential weird behavior
// in very long messages, and simplify performance analysis.
- let min_i = s.length - 40;
+ let min_i = s.length - MAX_LOOKBACK_FOR_TYPEAHEAD_COMPLETION;
if (min_i < 0) {
min_i = 0;
}
diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs
index c4aa01ffe62..dee6c3ff6f8 100644
--- a/web/tests/composebox_typeahead.test.cjs
+++ b/web/tests/composebox_typeahead.test.cjs
@@ -2014,7 +2014,12 @@ test("tokenizing", () => {
// The following cases are kinda judgment calls...
// max scanning limit is 40 characters until chars like @, # , / are found
- assert.equal(ct.tokenize_compose_str("foo @toomanycharactersistooridiculoustocomplete"), "");
+ assert.equal(
+ ct.tokenize_compose_str(
+ "foo @toomanycharactersistooridiculoustoautocompletethatitexceedsalllimits",
+ ),
+ "",
+ );
assert.equal(ct.tokenize_compose_str("foo #bar@foo"), "#bar@foo");
});