Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Add logic for scrolling buttons.
Karl Stolleyc6bdebec03c2
diff --git a/web/src/click_handlers.ts b/web/src/click_handlers.tsindex 69e8708a250..d4d667cff73 100644--- a/web/src/click_handlers.ts+++ b/web/src/click_handlers.ts@@ -730,6 +730,54 @@ export function initialize(): void {browser_history.go_to_location(target);});+ $("body").on("click", ".formatting-control-scroller-button", (e) => {+ e.preventDefault();+ e.stopPropagation();++ const $target = $(e.currentTarget);+ const $button_container = $target.closest(".compose-scrolling-buttons-container");+ const $button_bar = $button_container.find(".compose-scrollable-buttons");++ const button_container_width = Number(+ $button_container.attr("data-button-container-width"),+ );+ const button_bar_max_left_scroll = Number(+ $button_container.attr("data-button-bar-max-left-scroll"),+ );+ const button_bar_scroll_left = Number($button_bar.scrollLeft());++ // Buttons do not scale, so as to provide a generous click+ // area while not overwhelming the visibility of buttons on+ // narrower viewports at larger font sizes+ const scroller_button_width_px = 48;+ // We scroll 80% of the viewable area on each click...+ const button_bar_scroll_percentage = 80 / 100;+ // ...less the width of the two scroller buttons.+ const button_adjusted_scroll_shift =+ button_bar_scroll_percentage * (button_container_width - 2 * scroller_button_width_px);+ let new_scroll_position = 0;++ assert(typeof button_bar_scroll_left === "number");++ if ($target.hasClass("formatting-scroller-forward")) {+ new_scroll_position = button_bar_scroll_left + button_adjusted_scroll_shift;+ // If we're less than the width of the scroller button from+ // the end, just scroll the rest of the way forward+ if (button_bar_max_left_scroll <= new_scroll_position - scroller_button_width_px) {+ new_scroll_position = button_bar_max_left_scroll;+ }+ } else {+ new_scroll_position = button_bar_scroll_left - button_adjusted_scroll_shift;+ // If we're less than the width of the scroller button from+ // the start, just scroll the rest of the way back+ if (new_scroll_position <= scroller_button_width_px) {+ new_scroll_position = 0;+ }+ }++ $button_bar.scrollLeft(new_scroll_position);+ });+function handle_compose_click(e: JQuery.ClickEvent): void {const $target = $(e.target);// Emoji clicks should be handled by their own click handler in emoji_picker.jsdiff --git a/web/styles/compose.css b/web/styles/compose.cssindex 3cb8c54596d..ef25ab9c87d 100644--- a/web/styles/compose.css+++ b/web/styles/compose.css@@ -507,6 +507,7 @@grid-area: buttons;overflow-x: scroll;scrollbar-width: none;+ scroll-behavior: smooth;}.formatting-control-scroller-button {