compose: Fix using Up when editing messages.

This fixes a very noticable regression in
92788a52bb, 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.
This commit is contained in:
Tim Abbott 2023-01-31 17:23:15 -08:00
parent 92c8c17190
commit 875ad8ed5b
1 changed files with 8 additions and 0 deletions

View File

@ -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); const untrimmed_message_content = get_or_set("compose-textarea", true, true);
export function cursor_at_start_of_whitespace_in_compose() { 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(); const cursor_position = $("#compose-textarea").caret();
return message_content() === "" && cursor_position === 0; return message_content() === "" && cursor_position === 0;
} }