Skip to content

Commit 6c63b9e

Browse files
authored
joh/interesting catfish (microsoft#183338)
* quickly toggle diff while holding `alt` key * make status bar configurable (wrt hide) * tweak discard keybinding, tweak diff toggle * fix mangle check
1 parent 0adddd8 commit 6c63b9e

File tree

6 files changed

+54
-43
lines changed

6 files changed

+54
-43
lines changed

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorActions.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
1212
import { InteractiveEditorController, InteractiveEditorRunOptions } from 'vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController';
1313
import { CTX_INTERACTIVE_EDITOR_FOCUSED, CTX_INTERACTIVE_EDITOR_HAS_ACTIVE_REQUEST, CTX_INTERACTIVE_EDITOR_HAS_PROVIDER, CTX_INTERACTIVE_EDITOR_INNER_CURSOR_FIRST, CTX_INTERACTIVE_EDITOR_INNER_CURSOR_LAST, CTX_INTERACTIVE_EDITOR_EMPTY, CTX_INTERACTIVE_EDITOR_OUTER_CURSOR_POSITION, CTX_INTERACTIVE_EDITOR_VISIBLE, MENU_INTERACTIVE_EDITOR_WIDGET, MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD, MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, CTX_INTERACTIVE_EDITOR_LAST_FEEDBACK, CTX_INTERACTIVE_EDITOR_SHOWING_DIFF, CTX_INTERACTIVE_EDITOR_EDIT_MODE, EditMode, CTX_INTERACTIVE_EDITOR_LAST_RESPONSE_TYPE, MENU_INTERACTIVE_EDITOR_WIDGET_MARKDOWN_MESSAGE, CTX_INTERACTIVE_EDITOR_MESSAGE_CROP_STATE, CTX_INTERACTIVE_EDITOR_DOCUMENT_CHANGED, CTX_INTERACTIVE_EDITOR_DID_EDIT } from 'vs/workbench/contrib/interactiveEditor/common/interactiveEditor';
1414
import { localize } from 'vs/nls';
15-
import { IAction2Options } from 'vs/platform/actions/common/actions';
15+
import { IAction2Options, MenuRegistry } from 'vs/platform/actions/common/actions';
1616
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
1717
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
1818
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
@@ -252,6 +252,17 @@ export class NextFromHistory extends AbstractInteractiveEditorAction {
252252
}
253253
}
254254

255+
MenuRegistry.appendMenuItem(MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, {
256+
submenu: MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD,
257+
title: localize('discardMenu', "Discard..."),
258+
icon: Codicon.discard,
259+
group: '0_main',
260+
order: 2,
261+
when: CTX_INTERACTIVE_EDITOR_EDIT_MODE.notEqualsTo(EditMode.Preview),
262+
rememberDefaultAction: true
263+
});
264+
265+
255266
export class DicardAction extends AbstractInteractiveEditorAction {
256267

257268
constructor() {
@@ -262,7 +273,7 @@ export class DicardAction extends AbstractInteractiveEditorAction {
262273
precondition: CTX_INTERACTIVE_EDITOR_VISIBLE,
263274
keybinding: {
264275
weight: KeybindingWeight.EditorContrib,
265-
primary: KeyMod.Shift + KeyCode.Escape
276+
primary: KeyMod.CtrlCmd + KeyCode.Escape
266277
},
267278
menu: {
268279
id: MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD,

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class InteractiveEditorController implements IEditorContribution {
276276
this._activeSession!.recordExternalEditOccurred(editIsOutsideOfWholeRange);
277277

278278
if (editIsOutsideOfWholeRange) {
279-
this._logService.trace('[IE] text changed outside of whole range, FINISH session');
279+
this._logService.info('[IE] text changed outside of whole range, FINISH session');
280280
this._finishExistingSession();
281281
}
282282
}));

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorLivePreviewWidget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export class InteractiveEditorLivePreviewWidget extends ZoneWidget {
124124
override hide(): void {
125125
this._cleanupFullDiff();
126126
this._cleanupInlineDiff();
127+
this._sessionStore.clear();
127128
super.hide();
128129
this._isVisible = false;
129130
}

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorStrategies.ts

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

6+
import { ModifierKeyEmitter } from 'vs/base/browser/dom';
67
import { Event } from 'vs/base/common/event';
78
import { IDisposable } from 'vs/base/common/lifecycle';
89
import 'vs/css!./interactiveEditor';
@@ -29,7 +30,7 @@ import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/
2930

3031
export abstract class EditModeStrategy {
3132

32-
dispose(): void { }
33+
abstract dispose(): void;
3334

3435
abstract checkChanges(response: EditResponse): boolean;
3536

@@ -67,7 +68,6 @@ export class PreviewStrategy extends EditModeStrategy {
6768
override dispose(): void {
6869
this._listener.dispose();
6970
this._ctxDocumentChanged.reset();
70-
super.dispose();
7171
}
7272

7373
checkChanges(response: EditResponse): boolean {
@@ -201,10 +201,11 @@ class InlineDiffDecorations {
201201
export class LiveStrategy extends EditModeStrategy {
202202

203203
private static _inlineDiffStorageKey: string = 'interactiveEditor.storage.inlineDiff';
204-
private _inlineDiffEnabled: boolean = false;
204+
protected _diffEnabled: boolean = false;
205205

206206
private readonly _inlineDiffDecorations: InlineDiffDecorations;
207-
protected readonly _ctxShowingDiff: IContextKey<boolean>;
207+
private readonly _ctxShowingDiff: IContextKey<boolean>;
208+
private readonly _diffToggleListener: IDisposable;
208209
private _lastResponse?: EditResponse;
209210
private _editCount: number = 0;
210211

@@ -219,28 +220,36 @@ export class LiveStrategy extends EditModeStrategy {
219220
@IInstantiationService private readonly _instaService: IInstantiationService,
220221
) {
221222
super();
222-
this._inlineDiffDecorations = new InlineDiffDecorations(this._editor, this._inlineDiffEnabled);
223+
this._inlineDiffDecorations = new InlineDiffDecorations(this._editor, this._diffEnabled);
223224
this._ctxShowingDiff = CTX_INTERACTIVE_EDITOR_SHOWING_DIFF.bindTo(contextKeyService);
224225

225-
this._inlineDiffEnabled = _storageService.getBoolean(LiveStrategy._inlineDiffStorageKey, StorageScope.PROFILE, false);
226-
this._ctxShowingDiff.set(this._inlineDiffEnabled);
227-
this._inlineDiffDecorations.visible = this._inlineDiffEnabled;
226+
this._diffEnabled = _storageService.getBoolean(LiveStrategy._inlineDiffStorageKey, StorageScope.PROFILE, false);
227+
this._ctxShowingDiff.set(this._diffEnabled);
228+
this._inlineDiffDecorations.visible = this._diffEnabled;
229+
this._diffToggleListener = ModifierKeyEmitter.getInstance().event(e => {
230+
if (e.altKey || e.lastKeyReleased === 'alt') {
231+
this.toggleDiff();
232+
}
233+
});
228234
}
229235

230236
override dispose(): void {
231-
this._inlineDiffEnabled = this._inlineDiffDecorations.visible;
232-
this._storageService.store(LiveStrategy._inlineDiffStorageKey, this._inlineDiffEnabled, StorageScope.PROFILE, StorageTarget.USER);
237+
this._diffToggleListener.dispose();
238+
this._diffEnabled = this._inlineDiffDecorations.visible;
239+
this._storageService.store(LiveStrategy._inlineDiffStorageKey, this._diffEnabled, StorageScope.PROFILE, StorageTarget.USER);
233240
this._inlineDiffDecorations.clear();
234241
this._ctxShowingDiff.reset();
235-
236-
super.dispose();
237242
}
238243

239244
toggleDiff(): void {
240-
this._inlineDiffEnabled = !this._inlineDiffEnabled;
241-
this._ctxShowingDiff.set(this._inlineDiffEnabled);
242-
this._inlineDiffDecorations.visible = this._inlineDiffEnabled;
243-
this._storageService.store(LiveStrategy._inlineDiffStorageKey, this._inlineDiffEnabled, StorageScope.PROFILE, StorageTarget.USER);
245+
this._diffEnabled = !this._diffEnabled;
246+
this._ctxShowingDiff.set(this._diffEnabled);
247+
this._storageService.store(LiveStrategy._inlineDiffStorageKey, this._diffEnabled, StorageScope.PROFILE, StorageTarget.USER);
248+
this._doToggleDiff();
249+
}
250+
251+
protected _doToggleDiff(): void {
252+
this._inlineDiffDecorations.visible = this._diffEnabled;
244253
}
245254

246255
checkChanges(response: EditResponse): boolean {
@@ -364,9 +373,10 @@ export class LivePreviewStrategy extends LiveStrategy {
364373

365374
override async renderChanges(response: EditResponse) {
366375

367-
this._diffZone.show();
368376
this._updateSummaryMessage();
369-
this._ctxShowingDiff.set(true);
377+
if (this._diffEnabled) {
378+
this._diffZone.show();
379+
}
370380

371381
if (response.singleCreateFileEdit) {
372382
this._previewZone.showCreation(this._session.wholeRange, response.singleCreateFileEdit.uri, await Promise.all(response.singleCreateFileEdit.edits));
@@ -375,17 +385,16 @@ export class LivePreviewStrategy extends LiveStrategy {
375385
}
376386
}
377387

378-
override toggleDiff(): void {
379-
// TODO@jrieken should this be persisted like we do in live-mode?
380-
const scrollState = StableEditorScrollState.capture(this._editor);
381-
if (this._diffZone.isVisible) {
382-
this._diffZone.hide();
383-
this._ctxShowingDiff.set(false);
384-
} else {
385-
this._diffZone.show();
386-
this._ctxShowingDiff.set(true);
388+
protected override _doToggleDiff(): void {
389+
if (this._diffEnabled !== this._diffZone.isVisible) {
390+
const scrollState = StableEditorScrollState.capture(this._editor);
391+
if (this._diffEnabled) {
392+
this._diffZone.show();
393+
} else {
394+
this._diffZone.hide();
395+
}
396+
scrollState.restore(this._editor);
387397
}
388-
scrollState.restore(this._editor);
389398
}
390399
}
391400

src/vs/workbench/contrib/interactiveEditor/browser/interactiveEditorWidget.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export class InteractiveEditorWidget {
289289
return createActionViewItem(this._instantiationService, action, options);
290290
}
291291
};
292-
const statusToolbar = this._instantiationService.createInstance(MenuWorkbenchToolBar, this._elements.statusToolbar, MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, workbenchToolbarOptions);
292+
const statusToolbar = this._instantiationService.createInstance(MenuWorkbenchToolBar, this._elements.statusToolbar, MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, { ...workbenchToolbarOptions, hiddenItemStrategy: HiddenItemStrategy.Ignore });
293293
this._store.add(statusToolbar.onDidChangeMenuItems(() => this._onDidChangeHeight.fire()));
294294
this._store.add(statusToolbar);
295295

src/vs/workbench/contrib/interactiveEditor/common/interactiveEditor.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { CancellationToken } from 'vs/base/common/cancellation';
7-
import { Codicon } from 'vs/base/common/codicons';
87
import { IMarkdownString } from 'vs/base/common/htmlContent';
98
import { IDisposable } from 'vs/base/common/lifecycle';
109
import { IRange } from 'vs/editor/common/core/range';
1110
import { ISelection } from 'vs/editor/common/core/selection';
1211
import { ProviderResult, TextEdit, WorkspaceEdit } from 'vs/editor/common/languages';
1312
import { ITextModel } from 'vs/editor/common/model';
1413
import { localize } from 'vs/nls';
15-
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
14+
import { MenuId } from 'vs/platform/actions/common/actions';
1615
import { Extensions, IConfigurationRegistry } from 'vs/platform/configuration/common/configurationRegistry';
1716
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
1817
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
@@ -123,15 +122,6 @@ export const MENU_INTERACTIVE_EDITOR_WIDGET = MenuId.for('interactiveEditorWidge
123122
export const MENU_INTERACTIVE_EDITOR_WIDGET_MARKDOWN_MESSAGE = MenuId.for('interactiveEditorWidget.markdownMessage');
124123
export const MENU_INTERACTIVE_EDITOR_WIDGET_STATUS = MenuId.for('interactiveEditorWidget.status');
125124
export const MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD = MenuId.for('interactiveEditorWidget.undo');
126-
MenuRegistry.appendMenuItem(MENU_INTERACTIVE_EDITOR_WIDGET_STATUS, {
127-
submenu: MENU_INTERACTIVE_EDITOR_WIDGET_DISCARD,
128-
title: localize('discard', "Discard..."),
129-
icon: Codicon.discard,
130-
group: '0_main',
131-
order: 2,
132-
when: CTX_INTERACTIVE_EDITOR_EDIT_MODE.notEqualsTo(EditMode.Preview),
133-
rememberDefaultAction: true
134-
});
135125

136126
// --- colors
137127

0 commit comments

Comments
 (0)