From db20584a1952c8d1a9525d9cd8d6764a967b0423 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Thu, 9 Jan 2025 22:29:30 -0800 Subject: [PATCH] separate open sidebar from select for sidebar --- .../contrib/void/browser/sidebarActions.ts | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/sidebarActions.ts b/src/vs/workbench/contrib/void/browser/sidebarActions.ts index 6dcaa6a9..da7eac5e 100644 --- a/src/vs/workbench/contrib/void/browser/sidebarActions.ts +++ b/src/vs/workbench/contrib/void/browser/sidebarActions.ts @@ -27,6 +27,7 @@ import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js'; import { Disposable } from '../../../../base/common/lifecycle.js'; import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js'; import { URI } from '../../../../base/common/uri.js'; +import { localize2 } from '../../../../nls.js'; // ---------- Register commands and keybindings ---------- @@ -65,10 +66,28 @@ const getContentInRange = (model: ITextModel, range: IRange | null) => { return trimmedContent } -// Action: when press ctrl+L, show the sidebar chat and add to the selection + + +const VOID_OPEN_SIDEBAR_ACTION_ID = 'void.sidebar.open' registerAction2(class extends Action2 { constructor() { - super({ id: VOID_CTRL_L_ACTION_ID, title: 'Void: Add to Sidebar', keybinding: { primary: KeyMod.CtrlCmd | KeyCode.KeyL, weight: KeybindingWeight.BuiltinExtension } }); + super({ id: VOID_OPEN_SIDEBAR_ACTION_ID, title: localize2('voidOpenSidebar', 'Void: Open Sidebar'), f1: true }); + } + async run(accessor: ServicesAccessor): Promise { + const stateService = accessor.get(ISidebarStateService) + stateService.setState({ isHistoryOpen: false, currentTab: 'chat' }) + stateService.fireFocusChat() + } +}) + + + + +// Action: when press ctrl+L, show the sidebar chat and add to the selection +const VOID_ADD_SELECTION_TO_SIDEBAR_ACTION_ID = 'void.sidebar.select' +registerAction2(class extends Action2 { + constructor() { + super({ id: VOID_ADD_SELECTION_TO_SIDEBAR_ACTION_ID, title: localize2('voidAddToSidebar', 'Void: Add Selection to Sidebar'), f1: true }); } async run(accessor: ServicesAccessor): Promise { @@ -76,15 +95,11 @@ registerAction2(class extends Action2 { if (!model) return - const stateService = accessor.get(ISidebarStateService) const metricsService = accessor.get(IMetricsService) const editorService = accessor.get(ICodeEditorService) metricsService.capture('User Action', { type: 'Ctrl+L' }) - stateService.setState({ isHistoryOpen: false, currentTab: 'chat' }) - stateService.fireFocusChat() - const editor = editorService.getActiveCodeEditor() // accessor.get(IEditorService).activeTextEditorControl?.getSelection() const selectionRange = roundRangeToLines(editor?.getSelection(), { emptySelectionBehavior: 'null' }) @@ -135,6 +150,21 @@ registerAction2(class extends Action2 { }); +registerAction2(class extends Action2 { + constructor() { + super({ id: VOID_CTRL_L_ACTION_ID, title: 'Void: Press Ctrl+L', keybinding: { primary: KeyMod.CtrlCmd | KeyCode.KeyL, weight: KeybindingWeight.BuiltinExtension } }); + } + async run(accessor: ServicesAccessor): Promise { + const commandService = accessor.get(ICommandService) + await commandService.executeCommand(VOID_OPEN_SIDEBAR_ACTION_ID) + await commandService.executeCommand(VOID_ADD_SELECTION_TO_SIDEBAR_ACTION_ID) + } +}) + + + + + // New chat menu button registerAction2(class extends Action2 { constructor() { @@ -233,16 +263,16 @@ class TabSwitchContribution implements IWorkbenchContribution { @IInstantiationService private readonly instantiationService: IInstantiationService, @ICommandService private readonly commandService: ICommandService, ) { - const onSwitchTab = () => { - this.commandService.executeCommand(VOID_CTRL_L_ACTION_ID) - } - this.instantiationService.createInstance(TabSwitchListener, onSwitchTab) + + this.instantiationService.createInstance(TabSwitchListener, () => { + this.commandService.executeCommand(VOID_ADD_SELECTION_TO_SIDEBAR_ACTION_ID) + }) // run on current tab if it exists - this.commandService.executeCommand(VOID_CTRL_L_ACTION_ID) + this.commandService.executeCommand(VOID_ADD_SELECTION_TO_SIDEBAR_ACTION_ID) } } -registerWorkbenchContribution2(TabSwitchContribution.ID, TabSwitchContribution, WorkbenchPhase.AfterRestored); +registerWorkbenchContribution2(TabSwitchContribution.ID, TabSwitchContribution, WorkbenchPhase.BlockRestore);