Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
quote: Use better name for helper to get highlighted msg id.
Apoorva Pendse41648d30d668
diff --git a/web/src/compose_reply.ts b/web/src/compose_reply.tsindex 0f6c5845960..8ff61454247 100644--- a/web/src/compose_reply.ts+++ b/web/src/compose_reply.ts@@ -191,9 +191,7 @@ export function reply_with_mention(opts: {compose_ui.insert_syntax_and_focus(mention);}-export let selection_within_message_id = (- selection = window.getSelection(),-): number | undefined => {+export let get_highlighted_message_id = (selection = window.getSelection()): number | undefined => {// Returns the message_id if the selection is entirely within a message,// otherwise returns undefined.assert(selection !== null);@@ -207,10 +205,8 @@ export let selection_within_message_id = (return undefined;};-export function rewire_selection_within_message_id(- value: typeof selection_within_message_id,-): void {- selection_within_message_id = value;+export function rewire_get_highlighted_message_id(value: typeof get_highlighted_message_id): void {+ get_highlighted_message_id = value;}function get_quote_target_for_single_message(opts: {@@ -232,11 +228,11 @@ function get_quote_target_for_single_message(opts: {}} else {// If triggered via hotkey- const selection_message_id = selection_within_message_id();- if (selection_message_id) {- // If the current selection is entirely within a message, we- // quote that selection.- message_id = selection_message_id;+ const highlighted_msg_id = get_highlighted_message_id();+ if (highlighted_msg_id) {+ // If the current content selection is entirely within a message,+ // we quote that selection.+ message_id = highlighted_msg_id;quote_content = get_message_selection();} else {// Else we pick the currently focused message.diff --git a/web/src/message_actions_popover.ts b/web/src/message_actions_popover.tsindex 3e295eef301..e8d52a95732 100644--- a/web/src/message_actions_popover.ts+++ b/web/src/message_actions_popover.ts@@ -102,7 +102,7 @@ export function initialize({const $row = $(instance.reference).closest(".message_row");const message_id = rows.id($row);let quote_content: string | undefined;- if (compose_reply.selection_within_message_id() === message_id) {+ if (compose_reply.get_highlighted_message_id() === message_id) {// If the user has selected text within this message, quote only that.// We track the selection right now, before the popover option for Quote// and reply is clicked, since by then the selection is lost, due to thediff --git a/web/tests/compose_actions.test.cjs b/web/tests/compose_actions.test.cjsindex 20c55765cec..f3838b002f8 100644--- a/web/tests/compose_actions.test.cjs+++ b/web/tests/compose_actions.test.cjs@@ -464,7 +464,7 @@ test("reply_with_mention", ({override, override_rewire, mock_template}) => {test("quote_message", ({disallow, override, override_rewire}) => {override_rewire(compose_recipient, "on_compose_select_recipient_update", noop);override_rewire(compose_recipient, "update_recipient_row_attention_level", noop);- override_rewire(compose_reply, "selection_within_message_id", () => undefined);+ override_rewire(compose_reply, "get_highlighted_message_id", () => undefined);const $elem = $("#send_message_form");const $textarea = $("textarea#compose-textarea");const $indicator = $("#compose-limit-indicator");@@ -933,9 +933,8 @@ ${fence}`;opts = {trigger: "hotkey",};- const selected_string = "Hello world";- override_rewire(compose_reply, "selection_within_message_id", () => 50);- override_rewire(compose_reply, "get_message_selection", () => selected_string);+ override_rewire(compose_reply, "get_highlighted_message_id", () => 50);+ override_rewire(compose_reply, "get_message_selection", () => "Hello world");const stub = make_stub();override_rewire(compose_reply, "respond_to_message", stub.f);@@ -966,7 +965,7 @@ ${fence}`;// to quote, then message_id passed to `respond_to_message` will be same as as the// id of the message having the pointer.const message_with_pointer = highlighted_message;- override_rewire(compose_reply, "selection_within_message_id", () => undefined);+ override_rewire(compose_reply, "get_highlighted_message_id", () => undefined);override(message_lists.current, "selected_id", () => 100);override(message_lists.current, "get", (id) => (id === 100 ? message_with_pointer : undefined));diff --git a/web/tests/compose_ui.test.cjs b/web/tests/compose_ui.test.cjsindex 1a4a315216e..dcc127f843e 100644--- a/web/tests/compose_ui.test.cjs+++ b/web/tests/compose_ui.test.cjs@@ -588,7 +588,7 @@ run_test("quote_message", ({override, override_rewire}) => {// quoting a message, the quoted message should be placed// at the beginning of compose-box.override(message_lists.current, "selected_id", () => 100);- override_rewire(compose_reply, "selection_within_message_id", () => undefined);+ override_rewire(compose_reply, "get_highlighted_message_id", () => undefined);compose_reply.quote_message({});quote_text = "Testing with compose-box closed initially.";