From 789016709a44e47f9d17b41541ba5049950dae68 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Thu, 16 Jan 2025 20:02:22 -0800 Subject: [PATCH] multiple prospective --- .../react/src/sidebar-tsx/SidebarChat.tsx | 51 +++++++++++++------ 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index 607bd204..c0a3b638 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -273,24 +273,36 @@ export const SelectedFiles = ( const accessor = useAccessor() const commandService = accessor.get('ICommandService') + // state for tracking prospective files const { currentUri } = useUriState() - + const [recentUris, setRecentUris] = useState([]) + const maxProspectiveFiles = 3 + useEffect(() => { + if (!currentUri) return + setRecentUris(prev => { + const withoutCurrent = prev.filter(uri => uri.fsPath !== currentUri.fsPath) // remove if already exists + const withCurrent = [currentUri, ...withoutCurrent] + return withCurrent.slice(0, maxProspectiveFiles) + }) + }, [currentUri]) let prospectiveSelections: CodeStagingSelection[] = [] - if ( // add a prospective file if type === 'staging' and if the user is in a file, and if the file is not selected yet - type === 'staging' - && currentUri - && !selections.find(s => s.range === null && s.fileURI.fsPath === currentUri.fsPath) - ) { - prospectiveSelections = [{ - type: 'File', - fileURI: currentUri, - selectionStr: null, - range: null, - }] + if (type === 'staging') { // add a prospective file if type === 'staging' and if the user is in a file, and if the file is not selected yet + prospectiveSelections = recentUris + .filter(uri => !selections.find(s => s.range === null && s.fileURI.fsPath === uri.fsPath)) + .map(uri => ({ + type: 'File', + fileURI: uri, + selectionStr: null, + range: null, + })) } const allSelections = [...selections, ...prospectiveSelections] + if (allSelections.length === 0) { + return null + } + return (
@@ -300,8 +312,10 @@ export const SelectedFiles = ( const isThisSelectionAFile = selection.selectionStr === null const isThisSelectionProspective = i > selections.length - 1 - return
{/* selection summary */}
{/* clear all selections button */} - {type !== 'staging' || selections.length === 0 || i !== allSelections.length - 1 + {type !== 'staging' || selections.length === 0 || i !== selections.length - 1 ? null :
} -
+
) + + return <> + {i === selections.length &&
} + {selectionHTML} + })}