stream_list: Enter should use web_channel_default_view.

This previously misleadingly named on_stream_click masked the fact
that this was not using the actual click handler.
This commit is contained in:
Tim Abbott
2025-07-16 12:26:50 -07:00
parent 85835fae9b
commit 45941ba4d1
2 changed files with 106 additions and 96 deletions

View File

@@ -922,27 +922,19 @@ export function initialize_tippy_tooltips(): void {
});
}
export function set_event_handlers({
show_channel_feed,
}: {
show_channel_feed: (stream_id: number, trigger: string) => void;
}): void {
$("#stream_filters").on("click", "li .subscription_block", (e) => {
// Left sidebar channel links have an `href` so that the
// browser will preview the URL and you can middle-click it.
//
// But we want to control what the click does to follow the
// user's default left sidebar click action, rather than
// taking you to the channel feed.
if (e.metaKey || e.ctrlKey || e.shiftKey) {
return;
}
function on_sidebar_channel_click(
stream_id: number,
// Null is used when this is called via `Enter`, because the
// keyboard abstraction we're using doesn't need to pass on the event.
e: JQuery.ClickEvent | null,
show_channel_feed: (stream_id: number, trigger: string) => void,
): void {
clear_and_hide_search();
if (e !== null) {
e.preventDefault();
e.stopPropagation();
}
const stream_id = stream_id_for_elt($(e.target).parents("li.narrow-filter"));
const current_narrow_stream_id = narrow_state.stream_id();
const current_topic = narrow_state.topic();
@@ -969,8 +961,7 @@ export function set_event_handlers({
}
if (
user_settings.web_channel_default_view ===
web_channel_default_view_values.channel_feed.code
user_settings.web_channel_default_view === web_channel_default_view_values.channel_feed.code
) {
show_channel_feed(stream_id, "sidebar");
return;
@@ -1031,6 +1022,26 @@ export function set_event_handlers({
navigate_to_stream();
return;
}
}
export function set_event_handlers({
show_channel_feed,
}: {
show_channel_feed: (stream_id: number, trigger: string) => void;
}): void {
$("#stream_filters").on("click", "li .subscription_block", (e) => {
// Left sidebar channel links have an `href` so that the
// browser will preview the URL and you can middle-click it.
//
// But we want to control what the click does to follow the
// user's default left sidebar click action, rather than
// taking you to the channel feed.
if (e.metaKey || e.ctrlKey || e.shiftKey) {
return;
}
const stream_id = stream_id_for_elt($(e.target).parents("li.narrow-filter"));
on_sidebar_channel_click(stream_id, e, show_channel_feed);
});
$("#stream_filters").on("click", ".channel-new-topic-button", function (this: HTMLElement, e) {
@@ -1095,8 +1106,7 @@ export function set_event_handlers({
return;
}
clear_and_hide_search();
show_channel_feed(stream_id, "sidebar enter key");
on_sidebar_channel_click(stream_id, null, show_channel_feed);
}
keydown_util.handle({

View File

@@ -527,14 +527,14 @@ test_ui("narrowing", ({mock_template}) => {
});
test_ui("focusout_user_filter", () => {
stream_list.set_event_handlers({narrow_show_channel_feed() {}});
stream_list.set_event_handlers({show_channel_feed() {}});
const e = {};
const click_handler = $(".stream-list-filter").get_on_handler("focusout");
click_handler(e);
});
test_ui("focus_user_filter", () => {
stream_list.set_event_handlers({narrow_show_channel_feed() {}});
stream_list.set_event_handlers({show_channel_feed() {}});
initialize_stream_data();
stream_list.build_stream_list();