From 4a00bd3e00de0e00d26d8b127427baf13888a958 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Fri, 28 Feb 2025 01:07:44 -0800 Subject: [PATCH] Cmd+L selections open better ux --- .../react/src/sidebar-tsx/SidebarChat.tsx | 30 ++++++++++++------- .../contrib/void/browser/sidebarActions.ts | 5 ++++ .../contrib/void/common/chatThreadService.ts | 6 ++++ 3 files changed, 30 insertions(+), 11 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 d3c08eaf..e7f2ff37 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 @@ -376,9 +376,6 @@ export const SelectedFiles = ( | { type: 'staging', selections: StagingSelectionItem[]; setSelections: ((newSelections: StagingSelectionItem[]) => void), showProspectiveSelections?: boolean } ) => { - // index -> isOpened - const [selectionIsOpened, setSelectionIsOpened] = useState<(boolean)[]>(selections?.map(() => false) ?? []) - // state for tracking hover on clear all button const [isClearHovered, setIsClearHovered] = useState(false) @@ -409,6 +406,7 @@ export const SelectedFiles = ( fileURI: uri, selectionStr: null, range: null, + state: { isOpened: false }, })) } @@ -423,7 +421,7 @@ export const SelectedFiles = ( {allSelections.map((selection, i) => { - const isThisSelectionOpened = !!(selection.selectionStr && selectionIsOpened[i]) + const isThisSelectionOpened = (!!selection.selectionStr && selection.state.isOpened) //!!(selection.selectionStr && selectionIsOpened[i]) const isThisSelectionAFile = selection.selectionStr === null const isThisSelectionProspective = i > selections.length - 1 @@ -449,8 +447,8 @@ export const SelectedFiles = ( transition-all duration-150 `} onClick={() => { + if (type !== 'staging') return; // (never) if (isThisSelectionProspective) { // add prospective selection to selections - if (type !== 'staging') return; // (never) setSelections([...selections, selection]) } else if (isThisSelectionAFile) { // open files commandService.executeCommand('vscode.open', selection.fileURI, { @@ -458,11 +456,22 @@ export const SelectedFiles = ( // preserveFocus: false, }); } else { // show text - setSelectionIsOpened(s => { - const newS = [...s] - newS[i] = !newS[i] - return newS - }); + + const selection = selections[i] + const newSelection = { ...selection, state: { isOpened: !selection.state.isOpened } } + const newSelections = [ + ...selections.slice(0, i), + newSelection, + ...selections.slice(i + 1) + ] + setSelections(newSelections) + + // setSelectionIsOpened(s => { + // const newS = [...s] + // newS[i] = !newS[i] + // return newS + // }); + } }} > @@ -478,7 +487,6 @@ export const SelectedFiles = ( e.stopPropagation(); // don't open/close selection if (type !== 'staging') return; setSelections([...selections.slice(0, i), ...selections.slice(i + 1)]) - setSelectionIsOpened(o => [...o.slice(0, i), ...o.slice(i + 1)]) }} size={10} /> diff --git a/src/vs/workbench/contrib/void/browser/sidebarActions.ts b/src/vs/workbench/contrib/void/browser/sidebarActions.ts index 551a8cc8..fff6dda4 100644 --- a/src/vs/workbench/contrib/void/browser/sidebarActions.ts +++ b/src/vs/workbench/contrib/void/browser/sidebarActions.ts @@ -124,11 +124,13 @@ registerAction2(class extends Action2 { fileURI: model.uri, selectionStr: null, range: null, + state: { isOpened: false, } } : { type: 'Selection', fileURI: model.uri, selectionStr: selectionStr, range: selectionRange, + state: { isOpened: true, } } // update the staging selections @@ -148,6 +150,9 @@ registerAction2(class extends Action2 { setSelections = (s) => chatThreadService.setCurrentMessageState(focusedMessageIdx, { stagingSelections: s }) } + // close all selections besides the new one + selections = selections.map(s => ({ ...s, state: { ...s.state, isOpened: false } })) + // if matches with existing selection, overwrite (since text may change) const matchingStagingEltIdx = findMatchingStagingIndex(selections, selection) if (matchingStagingEltIdx !== undefined && matchingStagingEltIdx !== -1) { diff --git a/src/vs/workbench/contrib/void/common/chatThreadService.ts b/src/vs/workbench/contrib/void/common/chatThreadService.ts index 2704cd58..956c770c 100644 --- a/src/vs/workbench/contrib/void/common/chatThreadService.ts +++ b/src/vs/workbench/contrib/void/common/chatThreadService.ts @@ -36,6 +36,9 @@ export type CodeSelection = { fileURI: URI; selectionStr: string; range: IRange; + state: { + isOpened: boolean; + }; } export type FileSelection = { @@ -43,6 +46,9 @@ export type FileSelection = { fileURI: URI; selectionStr: null; range: null; + state: { + isOpened: boolean; + }; } export type StagingSelectionItem = CodeSelection | FileSelection