composebox_typeahead: Fix topic completion broken for long stream names.

Previous value of `40` didn't account for full length of stream name
which results in topic completion not working for stream names bigger
than that.
This commit is contained in:
Aman Agrawal
2025-02-24 06:43:42 +00:00
committed by Tim Abbott
parent ba7ad3de94
commit 6d30b10b60
2 changed files with 10 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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");
});