MCPcopy
hub / github.com/codeaashu/claude-code / getPreservedSelection

Function getPreservedSelection

src/hooks/useTypeahead.tsx:52–74  ·  view source on GitHub ↗
(prevSuggestions: SuggestionItem[], prevSelection: number, newSuggestions: SuggestionItem[])

Source from the content-addressed store, hash-verified

50
51// Helper to determine selectedSuggestion when updating suggestions
52function getPreservedSelection(prevSuggestions: SuggestionItem[], prevSelection: number, newSuggestions: SuggestionItem[]): number {
53 // No new suggestions
54 if (newSuggestions.length === 0) {
55 return -1;
56 }
57
58 // No previous selection
59 if (prevSelection < 0) {
60 return 0;
61 }
62
63 // Get the previously selected item
64 const prevSelectedItem = prevSuggestions[prevSelection];
65 if (!prevSelectedItem) {
66 return 0;
67 }
68
69 // Try to find the same item in the new list by ID
70 const newIndex = newSuggestions.findIndex(item => item.id === prevSelectedItem.id);
71
72 // Return the new index if found, otherwise default to 0
73 return newIndex >= 0 ? newIndex : 0;
74}
75function buildResumeInputFromSuggestion(suggestion: SuggestionItem): string {
76 const metadata = suggestion.metadata as {
77 sessionId: string;

Callers 1

useTypeaheadFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected