Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Complete only stream on stream+topic typeahead with ESC.
apoorvapendsec5b3c62e10ac
diff --git a/web/src/bootstrap_typeahead.ts b/web/src/bootstrap_typeahead.tsindex 0421fd26769..84ec73489b3 100644--- a/web/src/bootstrap_typeahead.ts+++ b/web/src/bootstrap_typeahead.ts@@ -244,6 +244,8 @@ export class Typeahead<ItemType extends string | object> {query = "";mouse_moved_since_typeahead = false;shown = false;+ // To trigger updater when Esc is pressed only during the stream topic typeahead in composebox.+ escape_topic_completion = false;openInputFieldOnKeyUp: (() => void) | undefined;closeInputFieldOnHide: (() => void) | undefined;helpOnEmptyStrings: boolean;@@ -294,6 +296,7 @@ export class Typeahead<ItemType extends string | object> {// return a string to show in typeahead items or false.this.option_label = options.option_label ?? (() => false);this.stopAdvance = options.stopAdvance ?? false;+ this.escape_topic_completion = options.escape_topic_completion ?? false;this.advanceKeys = options.advanceKeys ?? [];this.openInputFieldOnKeyUp = options.openInputFieldOnKeyUp;this.closeInputFieldOnHide = options.closeInputFieldOnHide;@@ -751,6 +754,11 @@ export class Typeahead<ItemType extends string | object> {break;case "Escape":+ // TODO: escape_topic_completion should be scoped more narrowly.+ // See https://github.com/zulip/zulip/pull/32217#discussion_r1934905517+ if (this.escape_topic_completion) {+ this.select(e);+ }if (!this.shown) {return;}@@ -881,6 +889,7 @@ type TypeaheadOptions<ItemType> = {sorter: (items: ItemType[], query: string) => ItemType[];stopAdvance?: boolean;tabIsEnter?: boolean;+ escape_topic_completion?: boolean;trigger_selection?: (event: JQuery.KeyDownEvent) => boolean;updater?: (item: ItemType,diff --git a/web/src/composebox_typeahead.ts b/web/src/composebox_typeahead.tsindex ef8cb766e37..81c721c5590 100644--- a/web/src/composebox_typeahead.ts+++ b/web/src/composebox_typeahead.ts@@ -1068,6 +1068,7 @@ export function content_typeahead_selected(item: TypeaheadSuggestion,query: string,input_element: TypeaheadInputElement,+ event?: JQuery.ClickEvent | JQuery.KeyUpEvent | JQuery.KeyDownEvent,): string {const pieces = split_at_cursor(query, input_element.$element);let beginning = pieces[0];@@ -1093,6 +1094,22 @@ export function content_typeahead_selected(message: "",};}++ // We only want to consider escape key for the stream+topic typeahead completion case.+ if (event?.key === "Escape" && item.type !== "topic_list") {+ setTimeout(() => {+ // Select any placeholder text configured to be highlighted.+ if (highlight.start && highlight.end) {+ $textbox.range(highlight.start, highlight.end);+ } else {+ $textbox.caret(beginning.length);+ }+ // Also, trigger autosize to check if compose box needs to be resized.+ compose_ui.autosize_textarea($textbox);+ }, 0);+ return beginning + rest;+ }+switch (item.type) {case "emoji":// leading and trailing spaces are required for emoji,@@ -1205,6 +1222,15 @@ export function content_typeahead_selected(break;}case "topic_list": {+ // If we use "Escape" we would want `#**design>this is a design topic` to be+ // resolved to `#**design** this is a design topic`+ if (event?.key === "Escape") {+ const topic_start_index = beginning.lastIndexOf(">");+ const topic = beginning.slice(topic_start_index + 1);+ beginning = beginning.slice(0, topic_start_index) + "** " + topic;+ break;+ }+// Stream + topic mention typeahead; close the stream+topic mention syntax with// the topic and the final ** or replace it with markdown link syntax if topic name// will cause encoding issues.@@ -1253,7 +1279,6 @@ export function content_typeahead_selected(return beginning + rest;}}-// Keep the cursor after the newly inserted text / selecting the// placeholder text, as Bootstrap will call $textbox.change() to// overwrite the text in the textbox.@@ -1361,6 +1386,7 @@ export function initialize_compose_typeahead($element: JQuery<HTMLTextAreaElemen},updater: content_typeahead_selected,stopAdvance: true, // Do not advance to the next field on a Tab or Enter+ escape_topic_completion: true,automated: compose_automated_selection,option_label(_matching_items, item): string | false {if (item.type === "topic_list" && item.is_channel_link) {