From 875ad8ed5be2bb86f447e92f97578d4b771f77af Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 31 Jan 2023 17:23:15 -0800 Subject: [PATCH] compose: Fix using Up when editing messages. This fixes a very noticable regression in 92788a52bbd9f1ca04b584e259e119e11f54574b, where using Up/PageUp/Home when focus was in anything other than the compose box would incorrectly be treated as message feed navigation. Fix this by adding a new check, but this now has some fairly duplicated code that queries the DOM for the same thing 3 times in a row; added a TODO comment explaining a likely better approach. --- static/js/compose_state.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/static/js/compose_state.js b/static/js/compose_state.js index 052bc05cd6..5cfe20e8fc 100644 --- a/static/js/compose_state.js +++ b/static/js/compose_state.js @@ -71,6 +71,14 @@ export const message_content = get_or_set("compose-textarea", true); const untrimmed_message_content = get_or_set("compose-textarea", true, true); export function cursor_at_start_of_whitespace_in_compose() { + // First check if the compose box is focused. TODO: Maybe we + // should make `consider_start_of_whitespace_message_empty` a + // parameter to `focus_in_empty_compose` instead. + const focused_element_id = document.activeElement.id; + if (focused_element_id !== "compose-textarea") { + return false; + } + const cursor_position = $("#compose-textarea").caret(); return message_content() === "" && cursor_position === 0; }