fix(shell): every prompt selects the name it offers, through one helper (M8)

This commit is contained in:
Tanish Manku committed 2026-11-17 13:51:07 -07:00
1 parent 955d26acec
commit 6304cf2f2b
4 files changed
+18 -34

No files matched your search

+2 -13
View File
@@ -3550,19 +3550,8 @@ impl App {
ui.set_min_width(360.0);
let r = ui.add(egui::TextEdit::singleline(&mut p.text).desired_width(f32::INFINITY)).named(title);
if p.focus {
r.request_focus();
if matches!(p.cmd, "layer.rename" | "scene.rename")
&& let Some(mut state) = egui::TextEdit::load_state(ui.ctx(), r.id)
{
let start = egui::text::CCursor::new(0);
let end = egui::text::CCursor::new(p.text.chars().count());
state.cursor.set_char_range(Some(egui::text::CCursorRange::two(start, end)));
state.store(ui.ctx(), r.id);
}
// What the prompt offers (a name to change) is selected: typing replaces it.
crate::theme::focus_selected(ui, &r, &p.text);
p.focus = false;
}
if r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)) {
+1 -8
View File
@@ -7,7 +7,6 @@ use crate::app::App;
use crate::theme::{FORM_LABEL_DOCK, Type, form_row, text};
use anicraft_engine::doc::{Document, FolderId, LibraryEntry, SymbolKind};
use egui::Key;
use egui::text::{CCursor, CCursorRange};
use serde_json::json;
/// The dialog while it is open.
@@ -75,13 +74,7 @@ pub fn window(app: &mut App, ctx: &egui::Context) {
form_row(ui, FORM_LABEL_DOCK, tr!("Name"), |ui| {
let r = ui.add(egui::TextEdit::singleline(&mut d.name).desired_width(f32::INFINITY)).named(tr!("Symbol name"));
if d.focus {
r.request_focus();
if let Some(mut state) = egui::TextEdit::load_state(ui.ctx(), r.id) {
let start = CCursor::new(0);
let end = CCursor::new(d.name.chars().count());
state.cursor.set_char_range(Some(CCursorRange::two(start, end)));
state.store(ui.ctx(), r.id);
}
crate::theme::focus_selected(ui, &r, &d.name);
d.focus = false;
}
if r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)) {
+3 -13
View File
@@ -103,17 +103,7 @@ pub fn window(app: &mut App, ctx: &egui::Context) {
form_row(ui, FORM_LABEL_DIALOG, tr!("Name"), |ui| {
let r = ui.add(egui::TextEdit::singleline(&mut d.name).desired_width(f32::INFINITY)).named(tr!("Layer name"));
if d.focus {
r.request_focus();
if let Some(mut state) = egui::TextEdit::load_state(ui.ctx(), r.id) {
let start = egui::text::CCursor::new(0);
let end = egui::text::CCursor::new(d.name.chars().count());
state.cursor.set_char_range(Some(egui::text::CCursorRange::two(start, end)));
state.store(ui.ctx(), r.id);
}
crate::theme::focus_selected(ui, &r, &d.name);
d.focus = false;
}
if r.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter)) {
@@ -285,7 +275,7 @@ mod tests {
assert!(app.layer_props.is_some());
}
#[test]
#[test]
fn opening_layer_properties_selects_entire_name() {
let ctx = egui::Context::default();
@@ -330,4 +320,4 @@ mod tests {
assert_eq!(a.min(b), egui::text::CharIndex(0));
assert_eq!(a.max(b), egui::text::CharIndex(original.chars().count()));
}
}
}
+12
View File
@@ -842,6 +842,18 @@ pub fn heat(w: f32) -> Color32 {
Color32::from_rgb(mix(a.r(), b.r()), mix(a.g(), b.g()), mix(a.b(), b.b()))
}
/// Gives a text field the keyboard with all of `text` selected, so typing replaces what a
/// dialog offers (a name to change, a default name) and the arrow keys still edit it
/// (#196, #322).
pub fn focus_selected(ui: &egui::Ui, field: &egui::Response, text: &str) {
field.request_focus();
if let Some(mut state) = egui::TextEdit::load_state(ui.ctx(), field.id) {
let all = egui::text::CCursorRange::two(egui::text::CCursor::new(0), egui::text::CCursor::new(text.chars().count()));
state.cursor.set_char_range(Some(all));
state.store(ui.ctx(), field.id);
}
}
/// Construct an RGB colour derived from artwork rather than a UI theme token.
/// UI control colours must still come from T.
pub(crate) fn artwork_rgb(r: u8, g: u8, b: u8) -> Color32 {