fix: update input field text selection on changing value during action (#1079)

Changing the value in an input field updates its text selection, so typing over a selected value replaces what's shown.
This commit is contained in:
Jasper van Loenen authored and GitHub committed 2026-10-14 11:01:29 -04:00
1 parent 1e1722b7e1
commit a8258eb63a
2 files changed
+36 -26

No files matched your search

+17
View File
@@ -278,3 +278,20 @@ fn rotated_second_occurrence_keeps_saved_from_and_to_points_exact() {
let after: Vec<_> = h.app.session.world_state().bodies.iter().map(|b| (b.name.clone(), b.mesh().bounds())).collect();
assert_eq!(after, before);
}
#[test]
fn dragging_to_update_value_reselects_whole_value_box_text() {
let mut h = make(json!({"distance":"4 mm"}));
open(&mut h);
let id = egui::Id::new("sc_canvas_value");
let selection = |h: &Harness| {
let range = egui::text_edit::TextEditState::load(&h.ctx, id).unwrap().cursor.char_range().unwrap();
let (a, b) = (range.primary.index, range.secondary.index);
(a.min(b).0, a.max(b).0)
};
assert_eq!(selection(&h), (0, 4), "the pick selects all of \"4 mm\"");
h.step(&json!({"drag":[{"handle":"arrow"},{"world":[5,5,15]}]})).unwrap();
let Some(crate::dialogs::Dialog { kind: crate::dialogs::Kind::Extrude { distance, .. }, .. }) = &h.app.dialog else { panic!("extrude dialog") };
assert_eq!(distance, "15 mm");
assert_eq!(selection(&h), (0, 5), "the drag grew the text length; the selection must cover all of it");
}