diff --git a/src/vs/editor/contrib/format/browser/format.ts b/src/vs/editor/contrib/format/browser/format.ts index 1f7518057ac..2fef1059ac8 100644 --- a/src/vs/editor/contrib/format/browser/format.ts +++ b/src/vs/editor/contrib/format/browser/format.ts @@ -105,7 +105,8 @@ export async function formatDocumentRangesWithSelectedProvider( rangeOrRanges: Range | Range[], mode: FormattingMode, progress: IProgress, - token: CancellationToken + token: CancellationToken, + userGesture: boolean ): Promise { const instaService = accessor.get(IInstantiationService); @@ -115,7 +116,7 @@ export async function formatDocumentRangesWithSelectedProvider( const selected = await FormattingConflicts.select(provider, model, mode); if (selected) { progress.report(selected); - await instaService.invokeFunction(formatDocumentRangesWithProvider, selected, editorOrModel, rangeOrRanges, token); + await instaService.invokeFunction(formatDocumentRangesWithProvider, selected, editorOrModel, rangeOrRanges, token, userGesture); } } @@ -124,10 +125,12 @@ export async function formatDocumentRangesWithProvider( provider: DocumentRangeFormattingEditProvider, editorOrModel: ITextModel | IActiveCodeEditor, rangeOrRanges: Range | Range[], - token: CancellationToken + token: CancellationToken, + userGesture: boolean ): Promise { const workerService = accessor.get(IEditorWorkerService); const logService = accessor.get(ILogService); + const accessibleNotificationService = accessor.get(IAccessibleNotificationService); let model: ITextModel; let cts: CancellationTokenSource; @@ -271,7 +274,7 @@ export async function formatDocumentRangesWithProvider( return null; }); } - + accessibleNotificationService.notify(AccessibleNotificationEvent.Format, userGesture); return true; } diff --git a/src/vs/editor/contrib/format/browser/formatActions.ts b/src/vs/editor/contrib/format/browser/formatActions.ts index 733b909ae6d..1282572b361 100644 --- a/src/vs/editor/contrib/format/browser/formatActions.ts +++ b/src/vs/editor/contrib/format/browser/formatActions.ts @@ -21,6 +21,7 @@ import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeat import { formatDocumentRangesWithSelectedProvider, formatDocumentWithSelectedProvider, FormattingMode, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/browser/format'; import { FormattingEdit } from 'vs/editor/contrib/format/browser/formattingEdit'; import * as nls from 'vs/nls'; +import { AccessibleNotificationEvent, IAccessibleNotificationService } from 'vs/platform/accessibility/common/accessibility'; import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -38,7 +39,8 @@ export class FormatOnType implements IEditorContribution { constructor( private readonly _editor: ICodeEditor, @ILanguageFeaturesService private readonly _languageFeaturesService: ILanguageFeaturesService, - @IEditorWorkerService private readonly _workerService: IEditorWorkerService + @IEditorWorkerService private readonly _workerService: IEditorWorkerService, + @IAccessibleNotificationService private readonly _accessibleNotificationService: IAccessibleNotificationService ) { this._disposables.add(_languageFeaturesService.onTypeFormattingEditProvider.onDidChange(this._update, this)); this._disposables.add(_editor.onDidChangeModel(() => this._update())); @@ -141,6 +143,7 @@ export class FormatOnType implements IEditorContribution { return; } if (isNonEmptyArray(edits)) { + this._accessibleNotificationService.notify(AccessibleNotificationEvent.Format, false); FormattingEdit.execute(this._editor, edits, true); } }).finally(() => { @@ -202,7 +205,7 @@ class FormatOnPaste implements IEditorContribution { if (this.editor.getSelections().length > 1) { return; } - this._instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, this.editor, range, FormattingMode.Silent, Progress.None, CancellationToken.None).catch(onUnexpectedError); + this._instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, this.editor, range, FormattingMode.Silent, Progress.None, CancellationToken.None, false).catch(onUnexpectedError); } } @@ -275,7 +278,7 @@ class FormatSelectionAction extends EditorAction { const progressService = accessor.get(IEditorProgressService); await progressService.showWhile( - instaService.invokeFunction(formatDocumentRangesWithSelectedProvider, editor, ranges, FormattingMode.Explicit, Progress.None, CancellationToken.None), + instaService.invokeFunction(formatDocumentRangesWithSelectedProvider, editor, ranges, FormattingMode.Explicit, Progress.None, CancellationToken.None, true), 250 ); } diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index 83a75496d49..122278e217a 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -258,7 +258,7 @@ class FormatOnSaveParticipant implements ITextFileSaveParticipant { } else if (ranges) { // formatted modified ranges - await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token); + await this.instantiationService.invokeFunction(formatDocumentRangesWithSelectedProvider, editorOrModel, ranges, FormattingMode.Silent, nestedProgress, token, false); } } } diff --git a/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts b/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts index 54e69300018..f84ae6738e4 100644 --- a/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts +++ b/src/vs/workbench/contrib/format/browser/formatActionsMultiple.ts @@ -405,7 +405,7 @@ registerEditorAction(class FormatSelectionMultipleAction extends EditorAction { const provider = languageFeaturesService.documentRangeFormattingEditProvider.ordered(model); const pick = await instaService.invokeFunction(showFormatterPick, model, provider); if (typeof pick === 'number') { - await instaService.invokeFunction(formatDocumentRangesWithProvider, provider[pick], editor, range, CancellationToken.None); + await instaService.invokeFunction(formatDocumentRangesWithProvider, provider[pick], editor, range, CancellationToken.None, true); } logFormatterTelemetry(telemetryService, 'range', provider, typeof pick === 'number' && provider[pick] || undefined); diff --git a/src/vs/workbench/contrib/format/browser/formatModified.ts b/src/vs/workbench/contrib/format/browser/formatModified.ts index 31b7f3395a5..18f492145dc 100644 --- a/src/vs/workbench/contrib/format/browser/formatModified.ts +++ b/src/vs/workbench/contrib/format/browser/formatModified.ts @@ -42,7 +42,8 @@ registerEditorAction(class FormatModifiedAction extends EditorAction { if (isNonEmptyArray(ranges)) { return instaService.invokeFunction( formatDocumentRangesWithSelectedProvider, editor, ranges, - FormattingMode.Explicit, Progress.None, CancellationToken.None + FormattingMode.Explicit, Progress.None, CancellationToken.None, + true ); } }