From 8f8f035b3f8192cafe379a89e6786b9d47731cd2 Mon Sep 17 00:00:00 2001 From: AnushreeKasturi Date: Sat, 17 Oct 2026 20:25:54 +0530 Subject: [PATCH 1/2] fix(ui): clamp target width on change instead of every keystroke The target width input parsed and clamped on each `input` event, and the reactive `prop:value` wrote the clamped value back into the field. Typing "1000" therefore became "3840" after the first keystroke. Move the clamp to `on:change`, matching the custom scale input. The typed value now stays in the field while editing, and is clamped to 320-3840 on commit (change or blur) with the clamped value written back to the field. An empty field still disables the target width. Adds the `HtmlInputElement` web-sys feature needed for the write-back. Fixes #37 --- crates/app/Cargo.toml | 1 + crates/app/src/controls.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/app/Cargo.toml b/crates/app/Cargo.toml index a36811c..bdffd90 100644 --- a/crates/app/Cargo.toml +++ b/crates/app/Cargo.toml @@ -33,6 +33,7 @@ web-sys = { version = "0.3", features = [ "FontFaceSet", "HtmlAnchorElement", "HtmlCanvasElement", + "HtmlInputElement", "HtmlTextAreaElement", "Navigator", "Storage", diff --git a/crates/app/src/controls.rs b/crates/app/src/controls.rs index 9d42c5c..d8aac41 100644 --- a/crates/app/src/controls.rs +++ b/crates/app/src/controls.rs @@ -463,12 +463,16 @@ pub fn Controls(settings: Settings) -> impl IntoView { .map(|w| format!("{w:.0}")) .unwrap_or_default() } - on:input=move |ev| { - let val = event_target_value(&ev); + on:change=move |ev| { + // Clamp on commit (change/blur), not per keystroke, so the typed value stays put + let input = event_target::(&ev); + let val = input.value(); if val.is_empty() { settings.target_width.set(None); } else if let Ok(px) = val.parse::() { - settings.target_width.set(Some(px.clamp(320.0, 3840.0))); + let clamped = px.clamp(320.0, 3840.0); + settings.target_width.set(Some(clamped)); + input.set_value(&format!("{clamped:.0}")); } } /> From 8a8363872f14dbf3065355dbaa989c5ebc695d59 Mon Sep 17 00:00:00 2001 From: Suradet PS Date: Tue, 3 Nov 2026 13:32:41 +0700 Subject: [PATCH 2/2] Update crates/app/src/controls.rs --- crates/app/src/controls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/app/src/controls.rs b/crates/app/src/controls.rs index d8aac41..603f74d 100644 --- a/crates/app/src/controls.rs +++ b/crates/app/src/controls.rs @@ -470,7 +470,7 @@ pub fn Controls(settings: Settings) -> impl IntoView { if val.is_empty() { settings.target_width.set(None); } else if let Ok(px) = val.parse::() { - let clamped = px.clamp(320.0, 3840.0); + let clamped = px.clamp(320.0, 3840.0).round(); settings.target_width.set(Some(clamped)); input.set_value(&format!("{clamped:.0}")); }