Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/vs/workbench/contrib/scm/browser/scm.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { RepositoryPicker, SCMViewService } from './scmViewService.js';
import { SCMRepositoriesViewPane } from './scmRepositoriesViewPane.js';
import { IInstantiationService, ServicesAccessor } from '../../../../platform/instantiation/common/instantiation.js';
import { Context as SuggestContext } from '../../../../editor/contrib/suggest/browser/suggest.js';
import { InlineCompletionContextKeys } from '../../../../editor/contrib/inlineCompletions/browser/controller/inlineCompletionContextKeys.js';
import { MANAGE_TRUST_COMMAND_ID, WorkspaceTrustContext } from '../../workspace/common/workspace.js';
import { IQuickDiffService } from '../common/quickDiff.js';
import { QuickDiffService } from '../common/quickDiffService.js';
Expand Down Expand Up @@ -459,10 +460,28 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({
}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'scm.clearValidation',
weight: KeybindingWeight.WorkbenchContrib,
when: ContextKeyExpr.and(
ContextKeyExpr.has('scmRepository'),
ContextKeys.SCMInputHasValidationMessage),
primary: KeyCode.Escape,
handler: async (accessor) => {
const scmViewService = accessor.get(ISCMViewService);
scmViewService.activeRepository.get()?.repository.input.clearValidation();
}
});

KeybindingsRegistry.registerCommandAndKeybindingRule({
id: 'scm.clearInput',
weight: KeybindingWeight.WorkbenchContrib,
when: ContextKeyExpr.and(ContextKeyExpr.has('scmRepository'), SuggestContext.Visible.toNegated(), EditorContextKeys.hasNonEmptySelection.toNegated()),
when: ContextKeyExpr.and(
ContextKeyExpr.has('scmRepository'),
SuggestContext.Visible.toNegated(),
InlineCompletionContextKeys.inlineSuggestionVisible.toNegated(),
ContextKeys.SCMInputHasValidationMessage.toNegated(),
EditorContextKeys.hasNonEmptySelection.toNegated()),
primary: KeyCode.Escape,
handler: async (accessor) => {
const scmService = accessor.get(ISCMService);
Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ export const ContextKeys = {
SCMCurrentHistoryItemRefInFilter: new RawContextKey<boolean>('scmCurrentHistoryItemRefInFilter', false),
RepositoryCount: new RawContextKey<number>('scmRepositoryCount', 0),
RepositoryVisibilityCount: new RawContextKey<number>('scmRepositoryVisibleCount', 0),
SCMInputHasValidationMessage: new RawContextKey<boolean>('scmInputHasValidationMessage', false),
RepositoryVisibility(repository: ISCMRepository) {
return new RawContextKey<boolean>(`scmRepositoryVisible:${repository.provider.id}`, false);
}
Expand Down Expand Up @@ -1692,6 +1693,7 @@ class SCMInputWidget {

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

private validation: IInputValidation | undefined;
Expand Down Expand Up @@ -1773,6 +1775,7 @@ class SCMInputWidget {
this.repositoryDisposables.add(input.onDidChangeFocus(() => this.focus()));
this.repositoryDisposables.add(input.onDidChangeValidationMessage((e) => this.setValidation(e, { focus: true, timeout: true })));
this.repositoryDisposables.add(input.onDidChangeValidateInput((e) => triggerValidation()));
this.repositoryDisposables.add(input.onDidClearValidation(() => this.clearValidation()));

// Keep API in sync with model and validate
this.repositoryDisposables.add(textModel.onDidChangeContent(() => {
Expand Down Expand Up @@ -1902,6 +1905,7 @@ class SCMInputWidget {

this.contextKeyService = contextKeyService.createScoped(this.element);
this.repositoryIdContextKey = this.contextKeyService.createKey('scmRepository', undefined);
this.validationMessageContextKey = ContextKeys.SCMInputHasValidationMessage.bindTo(this.contextKeyService);

this.inputEditorOptions = new SCMInputWidgetEditorOptions(overflowWidgetsDomNode, this.configurationService);
this.disposables.add(this.inputEditorOptions.onDidChange(this.onDidChangeEditorOptions, this));
Expand Down Expand Up @@ -2065,6 +2069,7 @@ class SCMInputWidget {
return;
}

this.validationMessageContextKey.set(true);
const disposables = new DisposableStore();

this.validationContextView = this.contextViewService.showContextView({
Expand Down Expand Up @@ -2142,6 +2147,7 @@ class SCMInputWidget {
this.validationContextView?.close();
this.validationContextView = undefined;
this.validationHasFocus = false;
this.validationMessageContextKey.set(false);
}

dispose(): void {
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/scm/common/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export interface ISCMInput {
showValidationMessage(message: string | IMarkdownString, type: InputValidationType): void;
readonly onDidChangeValidationMessage: Event<IInputValidation>;

clearValidation(): void;
readonly onDidClearValidation: Event<void>;

showNextHistoryValue(): void;
showPreviousHistoryValue(): void;
}
Expand Down
7 changes: 7 additions & 0 deletions src/vs/workbench/contrib/scm/common/scmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class SCMInput extends Disposable implements ISCMInput {
private readonly _onDidChangeValidationMessage = new Emitter<IInputValidation>();
readonly onDidChangeValidationMessage: Event<IInputValidation> = this._onDidChangeValidationMessage.event;

clearValidation(): void {
this._onDidClearValidation.fire();
}

private readonly _onDidClearValidation = new Emitter<void>();
readonly onDidClearValidation: Event<void> = this._onDidClearValidation.event;

private _validateInput: IInputValidator = () => Promise.resolve(undefined);

get validateInput(): IInputValidator {
Expand Down
Loading