refactor(annotate): route TEXTEDIT Mode entry through parse_texteditmode
Fold the Single/Multiple value parsing in TexteditCommand's Mode step into the shared parse_texteditmode() helper, and report unrecognized input to the user — the Mode step now stays active and re-prompts with "Requires Single or Multiple." instead of silently ignoring the value. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
8c48233dcf
commit
b134aff4e3
1 changed files with 24 additions and 8 deletions
|
|
@ -39,6 +39,9 @@ pub struct TexteditCommand {
|
||||||
mode: TextEditMode,
|
mode: TextEditMode,
|
||||||
edit_count: usize,
|
edit_count: usize,
|
||||||
step: Step,
|
step: Step,
|
||||||
|
/// Set when the last Mode entry was unrecognized, so the next prompt
|
||||||
|
/// leads with the error instead of silently re-asking.
|
||||||
|
invalid_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TexteditCommand {
|
impl TexteditCommand {
|
||||||
|
|
@ -52,6 +55,7 @@ impl TexteditCommand {
|
||||||
mode,
|
mode,
|
||||||
edit_count: 0,
|
edit_count: 0,
|
||||||
step: Step::PickObject,
|
step: Step::PickObject,
|
||||||
|
invalid_mode: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -71,8 +75,13 @@ impl CadCommand for TexteditCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Step::EnterMode => {
|
Step::EnterMode => {
|
||||||
|
let prefix = if self.invalid_mode {
|
||||||
|
"Requires Single or Multiple. "
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
format!(
|
format!(
|
||||||
"TEXTEDIT Enter text edit mode [Single/Multiple] <{}>:",
|
"{prefix}TEXTEDIT Enter text edit mode [Single/Multiple] <{}>:",
|
||||||
match self.mode {
|
match self.mode {
|
||||||
TextEditMode::Single => "Single",
|
TextEditMode::Single => "Single",
|
||||||
TextEditMode::Multiple => "Multiple",
|
TextEditMode::Multiple => "Multiple",
|
||||||
|
|
@ -126,17 +135,24 @@ impl CadCommand for TexteditCommand {
|
||||||
}
|
}
|
||||||
Step::EnterMode => {
|
Step::EnterMode => {
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
|
self.invalid_mode = false;
|
||||||
self.step = Step::PickObject;
|
self.step = Step::PickObject;
|
||||||
return Some(CmdResult::NeedPoint);
|
return Some(CmdResult::NeedPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
let lower = text.to_lowercase();
|
match parse_texteditmode(text) {
|
||||||
if lower == "s" || lower == "single" || lower == "1" {
|
Some(single) => {
|
||||||
self.mode = TextEditMode::Single;
|
self.mode = if single {
|
||||||
self.step = Step::PickObject;
|
TextEditMode::Single
|
||||||
} else if lower == "m" || lower == "multiple" || lower == "0" {
|
} else {
|
||||||
self.mode = TextEditMode::Multiple;
|
TextEditMode::Multiple
|
||||||
self.step = Step::PickObject;
|
};
|
||||||
|
self.invalid_mode = false;
|
||||||
|
self.step = Step::PickObject;
|
||||||
|
}
|
||||||
|
// Unrecognized value: stay on the Mode step and re-prompt
|
||||||
|
// with the error rather than silently ignoring it.
|
||||||
|
None => self.invalid_mode = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(CmdResult::NeedPoint)
|
Some(CmdResult::NeedPoint)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue