Select or toggle the currently highlighted option
(&mut self)
| 389 | |
| 390 | /// Select or toggle the currently highlighted option |
| 391 | fn select_current_option(&mut self) -> QuestionAction { |
| 392 | if self.is_other_selected() { |
| 393 | // Enter editing mode for custom input |
| 394 | self.editing_custom = true; |
| 395 | return QuestionAction::None; |
| 396 | } |
| 397 | |
| 398 | let q = &self.questions[self.current_tab]; |
| 399 | let opt_label = q.options[self.selected_option].label.clone(); |
| 400 | |
| 401 | if q.multi_select { |
| 402 | // Toggle |
| 403 | let answers = &mut self.answers[self.current_tab]; |
| 404 | if let Some(pos) = answers.iter().position(|a| a == &opt_label) { |
| 405 | answers.remove(pos); |
| 406 | } else { |
| 407 | answers.push(opt_label); |
| 408 | } |
| 409 | QuestionAction::None |
| 410 | } else { |
| 411 | // Single-select: pick and advance |
| 412 | self.answers[self.current_tab] = vec![opt_label]; |
| 413 | if self.is_single_auto_submit() { |
| 414 | QuestionAction::Submit(self.build_answers_payload()) |
| 415 | } else { |
| 416 | self.advance_tab(); |
| 417 | QuestionAction::None |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /// Advance to the next tab |
| 423 | fn advance_tab(&mut self) { |
no test coverage detected