From 7f359c83a14accae839fa0a5f6ce8ae5393dd6fe Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Fri, 30 Aug 2024 12:29:47 +0200 Subject: [PATCH] Implement changes from code reviews --- masonry/src/passes/update.rs | 5 +++++ masonry/src/widget/portal.rs | 7 +------ masonry/src/widget/textbox.rs | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/masonry/src/passes/update.rs b/masonry/src/passes/update.rs index c518906db..1ec6e7901 100644 --- a/masonry/src/passes/update.rs +++ b/masonry/src/passes/update.rs @@ -205,6 +205,11 @@ pub(crate) fn run_update_disabled_pass(root: &mut RenderRoot) { // ---------------- +// This pass will update scroll positions in cases where a widget has requested to be +// scrolled into view (usually a textbox getting text events). +// Each parent that implements scrolling will update its scroll position to ensure the +// child is visible. (If the target area is larger than the parent, the parent will try +// to show the top left of that area.) pub(crate) fn run_update_scroll_pass(root: &mut RenderRoot) { let _span = info_span!("update_scroll").entered(); diff --git a/masonry/src/widget/portal.rs b/masonry/src/widget/portal.rs index 404ed3a9b..ed6e7eff0 100644 --- a/masonry/src/widget/portal.rs +++ b/masonry/src/widget/portal.rs @@ -149,12 +149,7 @@ impl Portal { // Note - Rect is in child coordinates // TODO - Merge with pan_viewport_to // Right now these functions are just different enough to be a pain to merge. - pub fn pan_viewport_to_raw( - &mut self, - portal_size: Size, - content_size: Size, - target: Rect, - ) -> bool { + fn pan_viewport_to_raw(&mut self, portal_size: Size, content_size: Size, target: Rect) -> bool { let viewport = Rect::from_origin_size(self.viewport_pos, portal_size); let new_pos_x = compute_pan_range( diff --git a/masonry/src/widget/textbox.rs b/masonry/src/widget/textbox.rs index 8a85f2d8e..472670257 100644 --- a/masonry/src/widget/textbox.rs +++ b/masonry/src/widget/textbox.rs @@ -13,6 +13,7 @@ use vello::{ peniko::{BlendMode, Color}, Scene, }; +use winit::event::Ime; use crate::widget::{LineBreaking, WidgetMut}; use crate::{ @@ -205,10 +206,13 @@ impl Widget for Textbox { fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent) { let result = self.editor.text_event(ctx, event); - // If focused on a link and enter pressed, follow it? if result.is_handled() { - // TODO - Use request_scroll_to with cursor rect - ctx.request_scroll_to_this(); + // Some platforms will send a lot of spurious Preedit events. + // We only want to request a scroll on user input. + if !matches!(event, TextEvent::Ime(Ime::Preedit(..))) { + // TODO - Use request_scroll_to with cursor rect + ctx.request_scroll_to_this(); + } ctx.set_handled(); // TODO: only some handlers need this repaint ctx.request_layout();