js: Simplify indexing arrays from the end with Array#at.

https://github.com/tc39/proposal-relative-indexing-method

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-01-24 00:05:06 -08:00
committed by Tim Abbott
parent 0b03628324
commit c6b372b471
13 changed files with 26 additions and 33 deletions

View File

@@ -470,7 +470,7 @@ function drafts_initialize_focus(event_name) {
let draft_element;
if (event_name === "up_arrow") {
draft_element = document.querySelectorAll(
'[data-draft-id="' + draft_id_arrow[draft_id_arrow.length - 1] + '"]',
'[data-draft-id="' + draft_id_arrow.at(-1) + '"]',
);
} else if (event_name === "down_arrow") {
draft_element = document.querySelectorAll('[data-draft-id="' + draft_id_arrow[0] + '"]');
@@ -565,7 +565,7 @@ export function drafts_handle_events(e, event_key) {
if (document.activeElement.parentElement.hasAttribute("data-draft-id")) {
restore_draft(focused_draft_id);
} else {
const first_draft = draft_id_arrow[draft_id_arrow.length - 1];
const first_draft = draft_id_arrow.at(-1);
restore_draft(first_draft);
}
}