MCPcopy Create free account
hub / github.com/code-with-antonio/nightcode / InputBar

Function InputBar

packages/cli/src/components/input-bar.tsx:272–611  ·  view source on GitHub ↗
({ onSubmit, disabled = false }: Props)

Source from the content-addressed store, hash-verified

270];
271
272export function InputBar({ onSubmit, disabled = false }: Props) {
273 const { mode, toggleMode, setMode, setModel } = usePromptConfig();
274 const textareaRef = useRef<TextareaRenderable>(null);
275 const onSubmitRef = useRef<() => void>(() => {});
276 const activeMentionRef = useRef<MentionMatch | null>(null);
277 const mentionScrollRef = useRef<ScrollBoxRenderable>(null);
278
279 const renderer = useRenderer();
280 const navigate = useNavigate();
281 const toast = useToast();
282 const dialog = useDialog();
283 const { colors } = useTheme();
284 const { isTopLayer, push, pop, setResponder } = useKeyboardLayer();
285
286 const [activeMention, setActiveMention] = useState<MentionMatch | null>(null);
287 const [mentionCandidates, setMentionCandidates] = useState<MentionCandidate[]>([]);
288 const [mentionSelectedIndex, setMentionSelectedIndex] = useState(0);
289
290 const {
291 showCommandMenu,
292 commandQuery,
293 selectedIndex,
294 scrollRef,
295 handleContentChange,
296 resolveCommand,
297 setSelectedIndex,
298 } = useCommandMenu();
299
300 const showMentionMenu = activeMention !== null;
301
302 const closeMentionMenu = useCallback(() => {
303 activeMentionRef.current = null;
304 setActiveMention(null);
305 setMentionCandidates([]);
306 pop("mention");
307 }, [pop]);
308
309 const syncMentionMenu = useCallback((text: string, cursorOffset: number) => {
310 const nextMention = findActiveMention(text, cursorOffset);
311 const previousMention = activeMentionRef.current;
312 const mentionChanged =
313 previousMention?.start !== nextMention?.start ||
314 previousMention?.end !== nextMention?.end ||
315 previousMention?.query !== nextMention?.query;
316
317 if (!nextMention) {
318 if (previousMention) {
319 closeMentionMenu();
320 }
321 return;
322 }
323
324 activeMentionRef.current = nextMention;
325 setActiveMention(nextMention);
326 push("mention", () => {
327 closeMentionMenu();
328 return true;
329 });

Callers

nothing calls this directly

Calls 10

usePromptConfigFunction · 0.90
useToastFunction · 0.90
useDialogFunction · 0.90
useThemeFunction · 0.90
useKeyboardLayerFunction · 0.90
useCommandMenuFunction · 0.90
findActiveMentionFunction · 0.85
handleContentChangeFunction · 0.85
resolveCommandFunction · 0.85
loadCandidatesFunction · 0.85

Tested by

no test coverage detected