feat(props): select whole value when a property field is clicked

Clicking an editable property value field now selects its entire value instead
of only placing the caret, so typing immediately replaces it. The click is
observed through a global left-press subscription (PropPointerPressed); a focus
sweep reports which widget took focus and PropSyncActive maps it back to the
active property row, then issues a select-all operation only when focus landed
on a different field.

The active row stays highlighted while its text input holds keyboard focus and
clears when focus moves elsewhere.
This commit is contained in:
Karim Jerbi committed 2026-08-14 21:21:40 +01:00
1 parent dceb9626ae
commit 9f68034a60
6 files changed
+336 -18

No files matched your search

+2
View File
@@ -2120,6 +2120,7 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
pub(super) fn on_prop_geom_commit(&mut self, field: &'static str) -> Task<Message> {
let i = self.active_tab;
self.tabs[i].properties.active_field = None;
let handles = self.property_target_handles(i);
if !handles.is_empty() {
if let Some(raw_val) = self.tabs[i].properties.edit_buf.remove(field) {
@@ -2348,6 +2349,7 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
/// it is not run through the expression evaluator like numeric fields).
pub(super) fn on_prop_attr_commit(&mut self, tag: String) -> Task<Message> {
let i = self.active_tab;
self.tabs[i].properties.active_field = None;
let key = crate::ui::properties::attr_edit_key(&tag);
let handles = self.property_target_handles(i);
if handles.is_empty() {
+62 -5
View File
@@ -217,6 +217,20 @@ impl OpenCADStudio {
self.reset_modal_geometry();
}
/// Fire the focus-sweep once when a property field is active, so a
/// click-away that moved focus off the field (viewport, toolbar, command
/// line) clears the active-row highlight. Idle (`Task::none()`) unless a
/// field is active, and the sweep itself keeps the marker whenever the
/// active field still holds focus — re-firing it on unrelated messages is
/// cheap and safe.
fn sync_active_field_if_any(&self) -> Task<Message> {
if self.tabs[self.active_tab].properties.active_field.is_some() {
crate::ui::properties::sync_active_field_task()
} else {
Task::none()
}
}
pub fn update(&mut self, msg: Message) -> Task<Message> {
let perf_started = crate::perf::enabled().then(Instant::now);
let perf_label = perf_message_label(&msg);
@@ -1158,7 +1172,8 @@ impl OpenCADStudio {
}
Message::RibbonToolClick { tool_id, event } => {
self.on_ribbon_tool_click(tool_id, event)
let sweep = self.sync_active_field_if_any();
Task::batch(vec![sweep, self.on_ribbon_tool_click(tool_id, event)])
}
Message::PluginFileDialogResult { command, path } => {
if let Some(path) = path {
@@ -1401,14 +1416,15 @@ impl OpenCADStudio {
// the submit path, which tokenises multi-token lines — so a typed
// token, a pasted `LINE 0,0 10,10`, or API-fed text all run their
// spaces as step separators. A leading `>` keeps spaces literal.
let sweep = self.sync_active_field_if_any();
if !self.command_line.literal_spaces && !s.starts_with('>') && s.contains(' ') {
self.command_line.input = s;
return self.update(Message::CommandSubmit);
return Task::batch(vec![sweep, self.update(Message::CommandSubmit)]);
}
self.command_line.input = s;
self.command_line.autocomplete_cursor = None;
self.command_line.cancel_history_navigation();
Task::none()
Task::batch(vec![sweep, Task::none()])
}
Message::CommandAppendChar(s) => self.on_command_append_char(s),
@@ -2591,10 +2607,13 @@ impl OpenCADStudio {
Task::none()
}
Message::PanePress(idx) => {
// A click-away into the drawing area re-syncs the active-row
// highlight against real focus before the pick runs.
let sweep = self.sync_active_field_if_any();
// A fresh press ends any stale (un-dropped) pane move.
self.pane_move_from = None;
self.focus_model_pane(idx);
self.on_viewport_left_press()
Task::batch(vec![sweep, self.on_viewport_left_press()])
}
Message::PaneRelease(idx) => {
// Finishing a pane-move drag: swap the source pane with the one
@@ -2629,7 +2648,10 @@ impl OpenCADStudio {
self.update(Message::ViewportScroll(d))
}
Message::ViewportLeftPress => self.on_viewport_left_press(),
Message::ViewportLeftPress => {
let sweep = self.sync_active_field_if_any();
Task::batch(vec![sweep, self.on_viewport_left_press()])
}
Message::ViewportLeftRelease => self.on_viewport_left_release(),
@@ -4610,6 +4632,41 @@ impl OpenCADStudio {
Message::PropAttrCommit(tag) => self.on_prop_attr_commit(tag),
Message::PropPointerPressed => {
if self.tabs[self.active_tab].is_start || self.clean_screen {
return Task::none();
}
crate::ui::properties::sync_active_field_task()
}
Message::PropSyncActive(focused) => {
let panel = &mut self.tabs[self.active_tab].properties;
if let Some(id) = focused.as_ref() {
if let Some(key) = crate::ui::properties::prop_field_key_for_id(
&panel.sections,
id,
) {
let changed = panel.active_field.as_deref() != Some(key.as_str());
panel.active_field = Some(key);
// Only select the whole value when focus landed on a
// field that wasn't already the active one; re-focusing
// the same field (or sweeping after a click elsewhere
// left its focus in place) must keep caret placement.
if changed {
return iced::widget::operation::select_all(id.clone());
}
return Task::none();
}
}
if !crate::ui::properties::active_key_focused(
panel.active_field.as_deref(),
focused.as_ref(),
) {
panel.active_field = None;
}
Task::none()
}
Message::PropColorPickerToggle => {
let i = self.active_tab;
self.tabs[i].properties.color_picker_open =