MCPcopy Create free account
hub / github.com/GCWing/BitFun / handle_editing_key

Method handle_editing_key

src/apps/cli/src/ui/question.rs:230–289  ·  view source on GitHub ↗

Handle keys when editing custom "Other" text

(&mut self, key: KeyEvent)

Source from the content-addressed store, hash-verified

228
229 /// Handle keys when editing custom "Other" text
230 fn handle_editing_key(&mut self, key: KeyEvent) -> QuestionAction {
231 match (key.code, key.modifiers) {
232 (KeyCode::Esc, _) => {
233 self.editing_custom = false;
234 QuestionAction::None
235 }
236 (KeyCode::Enter, _) => {
237 let text = self.custom_inputs[self.current_tab].trim().to_string();
238 self.editing_custom = false;
239
240 if text.is_empty() {
241 // Clear custom answer
242 let answers = &mut self.answers[self.current_tab];
243 answers.retain(|a| a != "Other");
244 return QuestionAction::None;
245 }
246
247 let q = &self.questions[self.current_tab];
248 if q.multi_select {
249 // For multi-select: store custom text, toggle "Other" marker
250 self.custom_inputs[self.current_tab] = text.clone();
251 let answers = &mut self.answers[self.current_tab];
252 // Remove old "Other" and re-add with new text
253 answers.retain(|a| a != "Other");
254 answers.push("Other".to_string());
255 QuestionAction::None
256 } else {
257 // For single-select: pick and advance
258 self.custom_inputs[self.current_tab] = text.clone();
259 self.answers[self.current_tab] = vec!["Other".to_string()];
260 if self.is_single_auto_submit() {
261 QuestionAction::Submit(self.build_answers_payload())
262 } else {
263 self.advance_tab();
264 QuestionAction::None
265 }
266 }
267 }
268 (KeyCode::Backspace, _) => {
269 self.custom_inputs[self.current_tab].pop();
270 QuestionAction::None
271 }
272 (KeyCode::Char('u'), KeyModifiers::CONTROL) => {
273 let text = &self.custom_inputs[self.current_tab];
274 if text.is_empty() {
275 self.editing_custom = false;
276 } else {
277 self.custom_inputs[self.current_tab].clear();
278 }
279 QuestionAction::None
280 }
281 (KeyCode::Char(c), KeyModifiers::NONE | KeyModifiers::SHIFT) => {
282 if !c.is_control() {
283 self.custom_inputs[self.current_tab].push(c);
284 }
285 QuestionAction::None
286 }
287 _ => QuestionAction::None,

Callers 1

handle_key_eventMethod · 0.80

Calls 9

trimMethod · 0.80
is_single_auto_submitMethod · 0.80
build_answers_payloadMethod · 0.80
advance_tabMethod · 0.80
is_emptyMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45
popMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected