js: Use jQuery .first() when appropriate.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-08-25 23:01:32 -07:00 committed by Tim Abbott
parent bd1a27491e
commit 864abac946
3 changed files with 9 additions and 10 deletions

View File

@ -85,10 +85,9 @@ function construct_copy_div($div, start_id, end_id) {
should_include_start_recipient_header = true; should_include_start_recipient_header = true;
} }
const message = message_lists.current.get(rows.id($row)); const message = message_lists.current.get(rows.id($row));
const $message_firstp = $(message.content).slice(0, 1); const $content = $(message.content);
$message_firstp.prepend(message.sender_full_name + ": "); $content.first().prepend(message.sender_full_name + ": ");
$div.append($message_firstp); $div.append($content);
$div.append($(message.content).slice(1));
} }
if (should_include_start_recipient_header) { if (should_include_start_recipient_header) {
@ -218,7 +217,7 @@ export function analyze_selection(selection) {
$startc = $(range.startContainer); $startc = $(range.startContainer);
start_data = find_boundary_tr( start_data = find_boundary_tr(
$($startc.parents(".selectable_row, .message_header")[0]), $startc.parents(".selectable_row, .message_header").first(),
($row) => $row.next(), ($row) => $row.next(),
); );
if (start_data === undefined) { if (start_data === undefined) {
@ -279,19 +278,19 @@ function get_end_tr_from_endc($endc) {
// If the selection ends within the message following the selected // If the selection ends within the message following the selected
// messages, go back to use the actual last message. // messages, go back to use the actual last message.
if ($endc.parents(".message_row").length > 0) { if ($endc.parents(".message_row").length > 0) {
const $parent_msg = $($endc.parents(".message_row")[0]); const $parent_msg = $endc.parents(".message_row").first();
return $parent_msg.prev(".message_row"); return $parent_msg.prev(".message_row");
} }
// If it's not in a .message_row, it's probably in a .message_header and // If it's not in a .message_row, it's probably in a .message_header and
// we can use the last message from the previous recipient_row. // we can use the last message from the previous recipient_row.
if ($endc.parents(".message_header").length > 0) { if ($endc.parents(".message_header").length > 0) {
const $overflow_recipient_row = $($endc.parents(".recipient_row")[0]); const $overflow_recipient_row = $endc.parents(".recipient_row").first();
return $overflow_recipient_row.prev(".recipient_row").last(".message_row"); return $overflow_recipient_row.prev(".recipient_row").last(".message_row");
} }
// If somehow we get here, do the default return. // If somehow we get here, do the default return.
} }
return $($endc.parents(".selectable_row")[0]); return $endc.parents(".selectable_row").first();
} }
export function paste_handler_converter(paste_html) { export function paste_handler_converter(paste_html) {

View File

@ -146,7 +146,7 @@ export function open_edit_panel_for_row(stream_row) {
} }
export function open_edit_panel_empty() { export function open_edit_panel_empty() {
const tab_key = $(stream_settings_ui.get_active_data().$tabs[0]).attr("data-tab-key"); const tab_key = stream_settings_ui.get_active_data().$tabs.first().attr("data-tab-key");
$(".stream-row.active").removeClass("active"); $(".stream-row.active").removeClass("active");
stream_settings_ui.show_subs_pane.nothing_selected(); stream_settings_ui.show_subs_pane.nothing_selected();
setup_subscriptions_tab_hash(tab_key); setup_subscriptions_tab_hash(tab_key);

View File

@ -825,7 +825,7 @@ export function keyboard_sub() {
export function toggle_view(event) { export function toggle_view(event) {
const active_data = get_active_data(); const active_data = get_active_data();
const stream_filter_tab = $(active_data.$tabs[0]).text(); const stream_filter_tab = active_data.$tabs.first().text();
if (event === "right_arrow" && stream_filter_tab === "Subscribed") { if (event === "right_arrow" && stream_filter_tab === "Subscribed") {
toggler.goto("all-streams"); toggler.goto("all-streams");