From 730758cbec220806311395ef2318212f3886bf41 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Tue, 18 Mar 2025 03:43:10 -0700 Subject: [PATCH] small changes.. --- .../void-command-bar-tsx/VoidCommandBar.tsx | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/void-command-bar-tsx/VoidCommandBar.tsx b/src/vs/workbench/contrib/void/browser/react/src/void-command-bar-tsx/VoidCommandBar.tsx index 9f494909..6783be26 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/void-command-bar-tsx/VoidCommandBar.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/void-command-bar-tsx/VoidCommandBar.tsx @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------*/ -import { useAccessor, useIsDark } from '../util/services.js'; +import { useAccessor, useIsDark, useUriState } from '../util/services.js'; import '../styles.css' import { DiffZone } from '../../../editCodeService.js'; @@ -39,16 +39,7 @@ const VoidCommandBar = () => { const [diffIdxOfFspath, setDiffIdxOfFspath] = useState>({}) // const [currentUriIdx, setCurrentUriIdx] = useState(-1) // we are doing O(n) search for this - const getCurrentUri = useCallback(() => { - const editor = editorService.getActiveCodeEditor() - if (!editor) return null - const uri = editor.getModel()?.uri - if (!uri) return null - return uri - }, [editorService]) - - const diffZones: DiffZone[] = [] - + const { currentUri } = useUriState() // trigger rerender when diffzone is created (TODO need to also update when diff is accepted/rejected) useEffect(() => { @@ -58,11 +49,7 @@ const VoidCommandBar = () => { return () => disposable.dispose() }, [editCodeService, rerender]) - const getNextDiff = useCallback(({ step }: { step: 1 | -1 }) => { - - const currentUri = getCurrentUri() - if (!currentUri) { return; } @@ -78,9 +65,9 @@ const VoidCommandBar = () => { const nextDiff = sortedDiffs[nextDiffIdx] - return { nextDiff, nextDiffIdx, } + return { nextDiff, nextDiffIdx } - }, [getCurrentUri, editCodeService._sortedDiffsOfFspath, diffIdxOfFspath]) + }, [currentUri, editCodeService._sortedDiffsOfFspath, diffIdxOfFspath]) const getNextUri = useCallback(({ step }: { step: 1 | -1 }) => { @@ -89,8 +76,6 @@ const VoidCommandBar = () => { return; } - const currentUri = getCurrentUri() - const defaultUriIdx = step === 1 ? -1 : 0 // defaults: if next, currentIdx = -1; if prev, currentIdx = 0 let currentUriIdx = -1 if (currentUri) { @@ -104,15 +89,14 @@ const VoidCommandBar = () => { const nextUriIdx = (currentUriIdx + step) % sortedUris.length const nextUri = sortedUris[nextUriIdx] - return { nextUri, nextUriIdx, } - - }, [getCurrentUri, editCodeService._sortedUrisWithDiffs]) + return { nextUri, nextUriIdx } + }, [currentUri, editCodeService._sortedUrisWithDiffs]) const gotoNextDiff = ({ step }: { step: 1 | -1 }) => { // get the next diff - const res = getNextDiff({ step: 1 }) + const res = getNextDiff({ step }) if (!res) return; // scroll to the next diff @@ -132,7 +116,7 @@ const VoidCommandBar = () => { const gotoNextUri = ({ step }: { step: 1 | -1 }) => { // get the next uri - const res = getNextUri({ step: 1 }) + const res = getNextUri({ step }) if (!res) return; const { nextUri, nextUriIdx } = res; @@ -197,8 +181,8 @@ const VoidCommandBar = () => {
-
File {(editCodeService._sortedUrisWithDiffs.findIndex(u => u.fsPath === getCurrentUri()?.fsPath) ?? 0) + 1} of {editCodeService._sortedUrisWithDiffs.length}
-
Diff {(diffIdxOfFspath[getCurrentUri()?.fsPath ?? ''] ?? 0) + 1} of {editCodeService._sortedDiffsOfFspath[getCurrentUri()?.fsPath ?? '']?.length ?? 0}
+
File {(editCodeService._sortedUrisWithDiffs.findIndex(u => u.fsPath === currentUri?.fsPath) ?? 0) + 1} of {editCodeService._sortedUrisWithDiffs.length}
+
Diff {(diffIdxOfFspath[currentUri?.fsPath ?? ''] ?? 0) + 1} of {editCodeService._sortedDiffsOfFspath[currentUri?.fsPath ?? '']?.length ?? 0}