Skip to content

Commit 64fc920

Browse files
sandy081mrleemurray
authored andcommitted
- remember draft state in new chat (#298983)
- move changes action to title
1 parent 07d15fd commit 64fc920

File tree

6 files changed

+193
-160
lines changed

6 files changed

+193
-160
lines changed

src/vs/sessions/contrib/changesView/browser/changesViewActions.ts

Lines changed: 6 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,19 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import './media/changesViewActions.css';
7-
import { $, reset } from '../../../../base/browser/dom.js';
8-
import { BaseActionViewItem, IBaseActionViewItemOptions } from '../../../../base/browser/ui/actionbar/actionViewItems.js';
96
import { Codicon } from '../../../../base/common/codicons.js';
10-
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
11-
import { autorun, observableFromEvent } from '../../../../base/common/observable.js';
12-
import { ThemeIcon } from '../../../../base/common/themables.js';
13-
import { localize, localize2 } from '../../../../nls.js';
14-
import { IActionViewItemService } from '../../../../platform/actions/browser/actionViewItemService.js';
7+
import { Disposable } from '../../../../base/common/lifecycle.js';
8+
import { observableFromEvent } from '../../../../base/common/observable.js';
9+
import { localize2 } from '../../../../nls.js';
1510
import { Action2, IAction2Options, registerAction2 } from '../../../../platform/actions/common/actions.js';
16-
import { IInstantiationService, ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
11+
import { ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
1712
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../../workbench/common/contributions.js';
18-
import { getAgentChangesSummary, hasValidDiff } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js';
13+
import { hasValidDiff } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsModel.js';
1914
import { IAgentSessionsService } from '../../../../workbench/contrib/chat/browser/agentSessions/agentSessionsService.js';
2015
import { IViewsService } from '../../../../workbench/services/views/common/viewsService.js';
21-
import { Menus } from '../../../browser/menus.js';
2216
import { ISessionsManagementService } from '../../sessions/browser/sessionsManagementService.js';
2317
import { CHANGES_VIEW_ID } from './changesView.js';
24-
import { IAction } from '../../../../base/common/actions.js';
25-
import { getDefaultHoverDelegate } from '../../../../base/browser/ui/hover/hoverDelegateFactory.js';
26-
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
27-
import { ContextKeyExpr, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
18+
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
2819
import { bindContextKey } from '../../../../platform/observable/common/platformObservableUtils.js';
2920

3021
import { activeSessionHasChangesContextKey } from '../common/changes.js';
@@ -34,12 +25,6 @@ const openChangesViewActionOptions: IAction2Options = {
3425
title: localize2('openChangesView', "Changes"),
3526
icon: Codicon.diffMultiple,
3627
f1: false,
37-
menu: {
38-
id: Menus.TitleBarSessionMenu,
39-
group: 'navigation',
40-
order: 1,
41-
when: ContextKeyExpr.equals(activeSessionHasChangesContextKey.key, true),
42-
},
4328
};
4429

4530
class OpenChangesViewAction extends Action2 {
@@ -58,111 +43,17 @@ class OpenChangesViewAction extends Action2 {
5843

5944
registerAction2(OpenChangesViewAction);
6045

61-
/**
62-
* Custom action view item that renders the changes summary as:
63-
* [diff-icon] +insertions -deletions
64-
*/
65-
class ChangesActionViewItem extends BaseActionViewItem {
66-
67-
private _container: HTMLElement | undefined;
68-
private readonly _renderDisposables = this._register(new DisposableStore());
69-
70-
constructor(
71-
action: IAction,
72-
options: IBaseActionViewItemOptions | undefined,
73-
@ISessionsManagementService private readonly sessionManagementService: ISessionsManagementService,
74-
@IAgentSessionsService private readonly agentSessionsService: IAgentSessionsService,
75-
@IHoverService private readonly hoverService: IHoverService,
76-
) {
77-
super(undefined, action, options);
78-
79-
this._register(autorun(reader => {
80-
this.sessionManagementService.activeSession.read(reader);
81-
this._updateLabel();
82-
}));
83-
84-
this._register(this.agentSessionsService.model.onDidChangeSessions(() => {
85-
this._updateLabel();
86-
}));
87-
}
88-
89-
override render(container: HTMLElement): void {
90-
super.render(container);
91-
this._container = container;
92-
container.classList.add('changes-action-view-item');
93-
this._updateLabel();
94-
}
95-
96-
private _updateLabel(): void {
97-
if (!this._container) {
98-
return;
99-
}
100-
101-
this._renderDisposables.clear();
102-
reset(this._container);
103-
104-
const activeSession = this.sessionManagementService.getActiveSession();
105-
if (!activeSession) {
106-
this._container.style.display = 'none';
107-
return;
108-
}
109-
110-
const agentSession = this.agentSessionsService.getSession(activeSession.resource);
111-
const changes = agentSession?.changes;
112-
113-
if (!changes || !hasValidDiff(changes)) {
114-
this._container.style.display = 'none';
115-
return;
116-
}
117-
118-
const summary = getAgentChangesSummary(changes);
119-
if (!summary) {
120-
this._container.style.display = 'none';
121-
return;
122-
}
123-
124-
this._container.style.display = '';
125-
126-
// Diff icon
127-
const iconEl = $('span.changes-action-icon' + ThemeIcon.asCSSSelector(Codicon.diffMultiple));
128-
this._container.appendChild(iconEl);
129-
130-
// Insertions
131-
const addedEl = $('span.changes-action-added');
132-
addedEl.textContent = `+${summary.insertions}`;
133-
this._container.appendChild(addedEl);
134-
135-
// Deletions
136-
const removedEl = $('span.changes-action-removed');
137-
removedEl.textContent = `-${summary.deletions}`;
138-
this._container.appendChild(removedEl);
139-
140-
// Hover
141-
this._renderDisposables.add(this.hoverService.setupManagedHover(
142-
getDefaultHoverDelegate('mouse'),
143-
this._container,
144-
localize('agentSessions.viewChanges', "View All Changes")
145-
));
146-
}
147-
}
148-
14946
class ChangesViewActionsContribution extends Disposable implements IWorkbenchContribution {
15047

15148
static readonly ID = 'workbench.contrib.changesViewActions';
15249

15350
constructor(
154-
@IActionViewItemService actionViewItemService: IActionViewItemService,
155-
@IInstantiationService instantiationService: IInstantiationService,
15651
@IContextKeyService contextKeyService: IContextKeyService,
15752
@ISessionsManagementService sessionManagementService: ISessionsManagementService,
15853
@IAgentSessionsService agentSessionsService: IAgentSessionsService,
15954
) {
16055
super();
16156

162-
this._register(actionViewItemService.register(Menus.TitleBarSessionMenu, OpenChangesViewAction.ID, (action, options) => {
163-
return instantiationService.createInstance(ChangesActionViewItem, action, options);
164-
}));
165-
16657
// Bind context key: true when the active session has changes
16758
const sessionsChanged = observableFromEvent(this, agentSessionsService.model.onDidChangeSessions, () => { });
16859
this._register(bindContextKey(activeSessionHasChangesContextKey, contextKeyService, reader => {

src/vs/sessions/contrib/chat/browser/branchPicker.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ interface IBranchItem {
3131
export class BranchPicker extends Disposable {
3232

3333
private _selectedBranch: string | undefined;
34+
private _preferredBranch: string | undefined;
3435
private _newSession: INewSession | undefined;
3536
private _branches: string[] = [];
3637

@@ -48,6 +49,13 @@ export class BranchPicker extends Disposable {
4849
return this._selectedBranch;
4950
}
5051

52+
/**
53+
* Sets a preferred branch to select when branches are loaded.
54+
*/
55+
setPreferredBranch(branch: string | undefined): void {
56+
this._preferredBranch = branch;
57+
}
58+
5159
constructor(
5260
@IActionWidgetService private readonly actionWidgetService: IActionWidgetService,
5361
) {
@@ -85,8 +93,11 @@ export class BranchPicker extends Disposable {
8593
.filter((name): name is string => !!name)
8694
.filter(name => !name.includes(COPILOT_WORKTREE_PATTERN));
8795

88-
// Select active branch, main, master, or the first branch by default
89-
const defaultBranch = this._branches.find(b => b === repository.state.get().HEAD?.name)
96+
// Select preferred branch (from draft), active branch, main, master, or the first branch
97+
const preferred = this._preferredBranch;
98+
this._preferredBranch = undefined;
99+
const defaultBranch = (preferred ? this._branches.find(b => b === preferred) : undefined)
100+
?? this._branches.find(b => b === repository.state.get().HEAD?.name)
90101
?? this._branches.find(b => b === 'main')
91102
?? this._branches.find(b => b === 'master')
92103
?? this._branches[0];

0 commit comments

Comments
 (0)