From b134aff4e34aa1d55dae01c7d18d8496281cf2b6 Mon Sep 17 00:00:00 2001 From: Hakan Seven Date: Sun, 21 Jun 2026 12:10:39 +0300 Subject: [PATCH] refactor(annotate): route TEXTEDIT Mode entry through parse_texteditmode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/modules/annotate/textedit.rs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/modules/annotate/textedit.rs b/src/modules/annotate/textedit.rs index 5828cb6bf..bf223fbe9 100644 --- a/src/modules/annotate/textedit.rs +++ b/src/modules/annotate/textedit.rs @@ -39,6 +39,9 @@ pub struct TexteditCommand { mode: TextEditMode, edit_count: usize, 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 { @@ -52,6 +55,7 @@ impl TexteditCommand { mode, edit_count: 0, step: Step::PickObject, + invalid_mode: false, } } } @@ -71,8 +75,13 @@ impl CadCommand for TexteditCommand { } } Step::EnterMode => { + let prefix = if self.invalid_mode { + "Requires Single or Multiple. " + } else { + "" + }; format!( - "TEXTEDIT Enter text edit mode [Single/Multiple] <{}>:", + "{prefix}TEXTEDIT Enter text edit mode [Single/Multiple] <{}>:", match self.mode { TextEditMode::Single => "Single", TextEditMode::Multiple => "Multiple", @@ -126,17 +135,24 @@ impl CadCommand for TexteditCommand { } Step::EnterMode => { if text.is_empty() { + self.invalid_mode = false; self.step = Step::PickObject; return Some(CmdResult::NeedPoint); } - let lower = text.to_lowercase(); - if lower == "s" || lower == "single" || lower == "1" { - self.mode = TextEditMode::Single; - self.step = Step::PickObject; - } else if lower == "m" || lower == "multiple" || lower == "0" { - self.mode = TextEditMode::Multiple; - self.step = Step::PickObject; + match parse_texteditmode(text) { + Some(single) => { + self.mode = if single { + TextEditMode::Single + } else { + TextEditMode::Multiple + }; + 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)