MCPcopy Index your code
hub / github.com/coder/mux / toggle

Function toggle

src/browser/features/Tools/AskUserQuestionToolCall.tsx:667–712  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

665 const checked = currentDraft.selected.includes(opt.label);
666
667 const toggle = () => {
668 const isSelecting = !checked;
669
670 setDraftAnswers((prev) => {
671 const draft = prev[currentQuestion.question] ?? {
672 selected: [],
673 otherText: "",
674 };
675
676 if (currentQuestion.multiSelect) {
677 // Multi-select: toggle this option
678 const selected = new Set(draft.selected);
679 if (selected.has(opt.label)) {
680 selected.delete(opt.label);
681 } else {
682 selected.add(opt.label);
683 }
684 return {
685 ...prev,
686 [currentQuestion.question]: {
687 ...draft,
688 selected: Array.from(selected),
689 },
690 };
691 } else {
692 // Single-select: replace selection (clear otherText if not Other)
693 return {
694 ...prev,
695 [currentQuestion.question]: {
696 selected: checked ? [] : [opt.label],
697 otherText: opt.label === OTHER_VALUE ? draft.otherText : "",
698 },
699 };
700 }
701 });
702
703 // For single-select questions, auto-advance *only* when the user selects
704 // a non-Other option (avoid useEffect auto-advance that breaks back-nav).
705 if (
706 !currentQuestion.multiSelect &&
707 isSelecting &&
708 opt.label !== OTHER_VALUE
709 ) {
710 setActiveIndex((idx) => idx + 1);
711 }
712 };
713
714 return (
715 <div

Callers 1

AskUserQuestionToolCallFunction · 0.85

Calls 3

addMethod · 0.80
hasMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected