Skip to content

Commit daf9647

Browse files
authored
Implements audio cues for diff editor (microsoft#188274)
* Implements audio cues for diff editor * Fixes CI * Fixes import
1 parent b0689b4 commit daf9647

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import { DiffEditorEditors } from './diffEditorEditors';
4242
import { DiffEditorOptions } from './diffEditorOptions';
4343
import { DiffEditorViewModel, DiffMapping, DiffState } from './diffEditorViewModel';
4444
import { AccessibleDiffViewer } from 'vs/editor/browser/widget/diffEditorWidget2/accessibleDiffViewer';
45+
import { CursorChangeReason } from 'vs/editor/common/cursorEvents';
46+
import { AudioCue, IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService';
4547

4648
export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
4749
private readonly elements = h('div.monaco-diff-editor.side-by-side', { style: { position: 'relative', height: '100%' } }, [
@@ -83,6 +85,7 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
8385
@IContextKeyService private readonly _parentContextKeyService: IContextKeyService,
8486
@IInstantiationService private readonly _parentInstantiationService: IInstantiationService,
8587
@ICodeEditorService codeEditorService: ICodeEditorService,
88+
@IAudioCueService private readonly _audioCueService: IAudioCueService,
8689
) {
8790
super();
8891
codeEditorService.willCreateDiffEditor();
@@ -235,6 +238,19 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
235238
event.event.stopPropagation();
236239
}
237240
}));
241+
242+
this._register(Event.runAndSubscribe(this._editors.modified.onDidChangeCursorPosition, (e) => {
243+
if (e?.reason === CursorChangeReason.Explicit) {
244+
const diff = this._diffModel.get()?.diff.get()?.mappings.find(m => m.lineRangeMapping.modifiedRange.contains(e.position.lineNumber));
245+
if (diff?.lineRangeMapping.modifiedRange.isEmpty) {
246+
this._audioCueService.playAudioCue(AudioCue.diffLineDeleted);
247+
} else if (diff?.lineRangeMapping.originalRange.isEmpty) {
248+
this._audioCueService.playAudioCue(AudioCue.diffLineInserted);
249+
} else if (diff) {
250+
this._audioCueService.playAudioCue(AudioCue.diffLineModified);
251+
}
252+
}
253+
}));
238254
}
239255

240256
public getContentHeight() {
@@ -429,6 +445,14 @@ export class DiffEditorWidget2 extends DelegatingEditor implements IDiffEditor {
429445
diff = findLast(diffs, d => d.lineRangeMapping.modifiedRange.startLineNumber < curLineNumber) ?? diffs[diffs.length - 1];
430446
}
431447
this._goTo(diff);
448+
449+
if (diff.lineRangeMapping.modifiedRange.isEmpty) {
450+
this._audioCueService.playAudioCue(AudioCue.diffLineDeleted);
451+
} else if (diff.lineRangeMapping.originalRange.isEmpty) {
452+
this._audioCueService.playAudioCue(AudioCue.diffLineInserted);
453+
} else if (diff) {
454+
this._audioCueService.playAudioCue(AudioCue.diffLineModified);
455+
}
432456
}
433457

434458
revealFirstDiff(): void {

src/vs/editor/browser/widget/embeddedCodeEditorWidget.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IEditorProgressService } from 'vs/platform/progress/common/progress';
2121
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
2222
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
2323
import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';
24+
import { IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService';
2425

2526
export class EmbeddedCodeEditorWidget extends CodeEditorWidget {
2627

@@ -132,8 +133,9 @@ export class EmbeddedDiffEditorWidget2 extends DiffEditorWidget2 {
132133
@IContextKeyService contextKeyService: IContextKeyService,
133134
@IInstantiationService instantiationService: IInstantiationService,
134135
@ICodeEditorService codeEditorService: ICodeEditorService,
136+
@IAudioCueService audioCueService: IAudioCueService,
135137
) {
136-
super(domElement, parentEditor.getRawOptions(), codeEditorWidgetOptions, contextKeyService, instantiationService, codeEditorService);
138+
super(domElement, parentEditor.getRawOptions(), codeEditorWidgetOptions, contextKeyService, instantiationService, codeEditorService, audioCueService);
137139

138140
this._parentEditor = parentEditor;
139141
this._overwriteOptions = options;

src/vs/editor/standalone/browser/standaloneCodeEditor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { ILanguageConfigurationService } from 'vs/editor/common/languages/langua
3838
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
3939
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
4040
import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';
41+
import { IAudioCueService } from 'vs/platform/audioCues/browser/audioCueService';
4142

4243
/**
4344
* Description of an action contribution
@@ -572,7 +573,8 @@ export class StandaloneDiffEditor2 extends DiffEditorWidget2 implements IStandal
572573
@IConfigurationService configurationService: IConfigurationService,
573574
@IContextMenuService contextMenuService: IContextMenuService,
574575
@IEditorProgressService editorProgressService: IEditorProgressService,
575-
@IClipboardService clipboardService: IClipboardService
576+
@IClipboardService clipboardService: IClipboardService,
577+
@IAudioCueService audioCueService: IAudioCueService,
576578
) {
577579
const options = { ..._options };
578580
updateConfigurationService(configurationService, options, true);
@@ -591,6 +593,7 @@ export class StandaloneDiffEditor2 extends DiffEditorWidget2 implements IStandal
591593
contextKeyService,
592594
instantiationService,
593595
codeEditorService,
596+
audioCueService,
594597
);
595598

596599
this._configurationService = configurationService;

0 commit comments

Comments
 (0)