Skip to content

Commit 2bba9e4

Browse files
authored
Clear AI suggestion and validation message before clearing commit message input in SCM (microsoft#285420)
* Clear AI suggestion before clearing commit message input in SCM * Avoid clearing the SCM input when validation message is shown (clear validation message instead)
1 parent 43407de commit 2bba9e4

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/vs/workbench/contrib/scm/browser/scm.contribution.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { RepositoryPicker, SCMViewService } from './scmViewService.js';
2929
import { SCMRepositoriesViewPane } from './scmRepositoriesViewPane.js';
3030
import { IInstantiationService, ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
3131
import { Context as SuggestContext } from '../../../../editor/contrib/suggest/browser/suggest.js';
32+
import { InlineCompletionContextKeys } from '../../../../editor/contrib/inlineCompletions/browser/controller/inlineCompletionContextKeys.js';
3233
import { MANAGE_TRUST_COMMAND_ID, WorkspaceTrustContext } from '../../workspace/common/workspace.js';
3334
import { IQuickDiffService } from '../common/quickDiff.js';
3435
import { QuickDiffService } from '../common/quickDiffService.js';
@@ -459,10 +460,28 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
459460
}
460461
});
461462

463+
KeybindingsRegistry.registerCommandAndKeybindingRule({
464+
id: 'scm.clearValidation',
465+
weight: KeybindingWeight.WorkbenchContrib,
466+
when: ContextKeyExpr.and(
467+
ContextKeyExpr.has('scmRepository'),
468+
ContextKeys.SCMInputHasValidationMessage),
469+
primary: KeyCode.Escape,
470+
handler: async (accessor) => {
471+
const scmViewService = accessor.get(ISCMViewService);
472+
scmViewService.activeRepository.get()?.repository.input.clearValidation();
473+
}
474+
});
475+
462476
KeybindingsRegistry.registerCommandAndKeybindingRule({
463477
id: 'scm.clearInput',
464478
weight: KeybindingWeight.WorkbenchContrib,
465-
when: ContextKeyExpr.and(ContextKeyExpr.has('scmRepository'), SuggestContext.Visible.toNegated(), EditorContextKeys.hasNonEmptySelection.toNegated()),
479+
when: ContextKeyExpr.and(
480+
ContextKeyExpr.has('scmRepository'),
481+
SuggestContext.Visible.toNegated(),
482+
InlineCompletionContextKeys.inlineSuggestionVisible.toNegated(),
483+
ContextKeys.SCMInputHasValidationMessage.toNegated(),
484+
EditorContextKeys.hasNonEmptySelection.toNegated()),
466485
primary: KeyCode.Escape,
467486
handler: async (accessor) => {
468487
const scmService = accessor.get(ISCMService);

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ export const ContextKeys = {
981981
SCMCurrentHistoryItemRefInFilter: new RawContextKey<boolean>('scmCurrentHistoryItemRefInFilter', false),
982982
RepositoryCount: new RawContextKey<number>('scmRepositoryCount', 0),
983983
RepositoryVisibilityCount: new RawContextKey<number>('scmRepositoryVisibleCount', 0),
984+
SCMInputHasValidationMessage: new RawContextKey<boolean>('scmInputHasValidationMessage', false),
984985
RepositoryVisibility(repository: ISCMRepository) {
985986
return new RawContextKey<boolean>(`scmRepositoryVisible:${repository.provider.id}`, false);
986987
}
@@ -1696,6 +1697,7 @@ class SCMInputWidget {
16961697

16971698
private model: { readonly input: ISCMInput; readonly textModel: ITextModel } | undefined;
16981699
private repositoryIdContextKey: IContextKey<string | undefined>;
1700+
private validationMessageContextKey: IContextKey<boolean>;
16991701
private readonly repositoryDisposables = new DisposableStore();
17001702

17011703
private validation: IInputValidation | undefined;
@@ -1777,6 +1779,7 @@ class SCMInputWidget {
17771779
this.repositoryDisposables.add(input.onDidChangeFocus(() => this.focus()));
17781780
this.repositoryDisposables.add(input.onDidChangeValidationMessage((e) => this.setValidation(e, { focus: true, timeout: true })));
17791781
this.repositoryDisposables.add(input.onDidChangeValidateInput((e) => triggerValidation()));
1782+
this.repositoryDisposables.add(input.onDidClearValidation(() => this.clearValidation()));
17801783

17811784
// Keep API in sync with model and validate
17821785
this.repositoryDisposables.add(textModel.onDidChangeContent(() => {
@@ -1906,6 +1909,7 @@ class SCMInputWidget {
19061909

19071910
this.contextKeyService = contextKeyService.createScoped(this.element);
19081911
this.repositoryIdContextKey = this.contextKeyService.createKey('scmRepository', undefined);
1912+
this.validationMessageContextKey = ContextKeys.SCMInputHasValidationMessage.bindTo(this.contextKeyService);
19091913

19101914
this.inputEditorOptions = new SCMInputWidgetEditorOptions(overflowWidgetsDomNode, this.configurationService);
19111915
this.disposables.add(this.inputEditorOptions.onDidChange(this.onDidChangeEditorOptions, this));
@@ -2069,6 +2073,7 @@ class SCMInputWidget {
20692073
return;
20702074
}
20712075

2076+
this.validationMessageContextKey.set(true);
20722077
const disposables = new DisposableStore();
20732078

20742079
this.validationContextView = this.contextViewService.showContextView({
@@ -2146,6 +2151,7 @@ class SCMInputWidget {
21462151
this.validationContextView?.close();
21472152
this.validationContextView = undefined;
21482153
this.validationHasFocus = false;
2154+
this.validationMessageContextKey.set(false);
21492155
}
21502156

21512157
dispose(): void {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ export interface ISCMInput {
163163
showValidationMessage(message: string | IMarkdownString, type: InputValidationType): void;
164164
readonly onDidChangeValidationMessage: Event<IInputValidation>;
165165

166+
clearValidation(): void;
167+
readonly onDidClearValidation: Event<void>;
168+
166169
showNextHistoryValue(): void;
167170
showPreviousHistoryValue(): void;
168171
}

src/vs/workbench/contrib/scm/common/scmService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class SCMInput extends Disposable implements ISCMInput {
8686
private readonly _onDidChangeValidationMessage = new Emitter<IInputValidation>();
8787
readonly onDidChangeValidationMessage: Event<IInputValidation> = this._onDidChangeValidationMessage.event;
8888

89+
clearValidation(): void {
90+
this._onDidClearValidation.fire();
91+
}
92+
93+
private readonly _onDidClearValidation = new Emitter<void>();
94+
readonly onDidClearValidation: Event<void> = this._onDidClearValidation.event;
95+
8996
private _validateInput: IInputValidator = () => Promise.resolve(undefined);
9097

9198
get validateInput(): IInputValidator {

0 commit comments

Comments
 (0)