Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui_web: Disable autoscroll (#64041)

Cameron Mcloughlin5a773a406e49
diff --git a/crates/gpui_web/Cargo.toml b/crates/gpui_web/Cargo.toml
index 613fbb55bba..610da14f0d2 100644
--- a/crates/gpui_web/Cargo.toml
+++ b/crates/gpui_web/Cargo.toml
@@ -54,6 +54,7 @@ web-sys = { version = "0.3", features = [
"Element",
"EventTarget",
"File",
+ "FocusOptions",
"HtmlCanvasElement",
"HtmlElement",
"HtmlTextAreaElement",
diff --git a/crates/gpui_web/src/ime_mirror.rs b/crates/gpui_web/src/ime_mirror.rs
index b53792aee2b..5cb08b5a296 100644
--- a/crates/gpui_web/src/ime_mirror.rs
+++ b/crates/gpui_web/src/ime_mirror.rs
@@ -110,7 +110,7 @@ impl ImeMirror {
style.set_property("font-size", "16px").ok();
body.append_child(&element)
.map_err(|e| anyhow::anyhow!("Failed to append input to body: {e:?}"))?;
- element.focus().ok();
+ Self::focus_element(&element);
// The element must stay focused to receive hardware-key and IME
// events, but on touch-first devices a focused *editable* element
// invites the browser to summon the virtual keyboard on the next
@@ -183,7 +183,17 @@ impl ImeMirror {
}
pub(crate) fn focus(&self) {
- self.element.focus().ok();
+ Self::focus_element(&self.element);
+ }
+
+ fn focus_element(element: &web_sys::HtmlTextAreaElement) {
+ // The hidden mirror is not a scroll target: revealing its caret can
+ // pan Android Chrome's visual viewport when the keyboard opens.
+ let options = web_sys::FocusOptions::new();
+ options.set_prevent_scroll(true);
+ if let Err(error) = element.focus_with_options(&options) {
+ log::warn!("Failed to focus IME mirror: {error:?}");
+ }
}
pub(crate) fn is_focused(&self) -> bool {