Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose: Defer triggering focus.

Karl Stolley7515ed45be48
diff --git a/web/src/compose_actions.ts b/web/src/compose_actions.ts
index 4d0a6b59f98..90387a7fc79 100644
--- a/web/src/compose_actions.ts
+++ b/web/src/compose_actions.ts
@@ -45,6 +45,7 @@ type ComposeActionsStartOpts = {
skip_scrolling_selected_message?: boolean;
is_reply?: boolean;
keep_composebox_empty?: boolean | undefined;
+ defer_focus?: boolean | undefined;
};
// An iteration on `ComposeActionsStartOpts` that enforces that
@@ -117,7 +118,16 @@ function show_compose_box(opts: ComposeActionsOpts): void {
compose_recipient.update_compose_for_message_type(opts_by_message_type);
// When changing this, edit the 42px in _maybe_autoscroll
$(".new_message_textarea").css("min-height", "3em");
- compose_ui.set_focus(opts_by_message_type);
+ // Under certain circumstances, such as focusing in the
+ // automatically-opened compose box in DMs, we want to
+ // defer running the focus logic.
+ if (opts.defer_focus) {
+ setTimeout(() => {
+ compose_ui.set_focus(opts_by_message_type);
+ }, 0);
+ } else {
+ compose_ui.set_focus(opts_by_message_type);
+ }
// Transitions in the recipient row of the compose box are attached
// to this class we add a slight delay to avoid transitions firing
// immediately.
@@ -622,15 +632,18 @@ export function on_narrow(opts: NarrowActivateOpts): void {
return;
}
- // Open the compose box, passing the option to skip attempting
- // an animated adjustment to scroll position, which is useless
- // because we are called before the narrowing process has set
- // the view's scroll position. recenter_view is responsible
- // for taking the open compose box into account when placing
- // the selecting message.
start({
message_type: "private",
+ // Skip attempting an animated adjustment to scroll
+ // position, which is useless because we are called before
+ // the narrowing process has set the view's scroll
+ // position. recenter_view is responsible for taking the
+ // open compose box into account when placing the
+ // selecting message.
skip_scrolling_selected_message: true,
+ // Defer setting focus on the compose box to avoid a
+ // whole-screen scrolling bug on iPad/Safari.
+ defer_focus: true,
});
return;
}
diff --git a/web/src/compose_ui.ts b/web/src/compose_ui.ts
index f77da04c08c..93c229c1586 100644
--- a/web/src/compose_ui.ts
+++ b/web/src/compose_ui.ts
@@ -35,6 +35,7 @@ export const DEFAULT_COMPOSE_PLACEHOLDER = $t({defaultMessage: "Compose your mes
export type ComposeTriggeredOptions = {
trigger: string;
+ defer_focus?: boolean | undefined;
} & (
| {
message_type: "stream";