Skip to content

Commit 076e9df

Browse files
authored
Something should happen when the flashing microphone is clicked (fix microsoft#205670) (microsoft#205842)
* Something should happen when the flashing microphone is clicked (fix microsoft#205670) * switch to action bar * .
1 parent e8aed24 commit 076e9df

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

src/vs/workbench/contrib/codeEditor/browser/dictation/editorDictation.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
max-width: var(--vscode-editor-dictation-widget-width);
1717
}
1818

19-
.monaco-editor .editor-dictation-widget .codicon.codicon-mic-filled {
20-
display: flex;
21-
align-items: center;
22-
width: 16px;
23-
height: 16px;
24-
}
25-
2619
.monaco-editor .editor-dictation-widget.recording .codicon.codicon-mic-filled {
2720
color: var(--vscode-activityBarBadge-background);
2821
animation: editor-dictation-animation 1s infinite;

src/vs/workbench/contrib/codeEditor/browser/dictation/editorDictation.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import 'vs/css!./editorDictation';
7-
import { localize2 } from 'vs/nls';
8-
import { IDimension, h, reset } from 'vs/base/browser/dom';
7+
import { localize, localize2 } from 'vs/nls';
8+
import { IDimension } from 'vs/base/browser/dom';
99
import { CancellationTokenSource } from 'vs/base/common/cancellation';
1010
import { Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
1111
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
1212
import { IEditorContribution } from 'vs/editor/common/editorCommon';
1313
import { ContextKeyExpr, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
1414
import { HasSpeechProvider, ISpeechService, SpeechToTextStatus } from 'vs/workbench/contrib/speech/common/speechService';
15-
import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels';
1615
import { Codicon } from 'vs/base/common/codicons';
1716
import { EditorOption } from 'vs/editor/common/config/editorOptions';
1817
import { EditorAction2, EditorContributionInstantiation, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
@@ -27,6 +26,9 @@ import { Position } from 'vs/editor/common/core/position';
2726
import { Range } from 'vs/editor/common/core/range';
2827
import { registerAction2 } from 'vs/platform/actions/common/actions';
2928
import { assertIsDefined } from 'vs/base/common/types';
29+
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
30+
import { toAction } from 'vs/base/common/actions';
31+
import { ThemeIcon } from 'vs/base/common/themables';
3032

3133
const EDITOR_DICTATION_IN_PROGRESS = new RawContextKey<boolean>('editorDictation.inProgress', false);
3234
const VOICE_CATEGORY = localize2('voiceCategory', "Voice");
@@ -69,9 +71,11 @@ export class EditorDictationStartAction extends EditorAction2 {
6971

7072
export class EditorDictationStopAction extends EditorAction2 {
7173

74+
static readonly ID = 'workbench.action.editorDictation.stop';
75+
7276
constructor() {
7377
super({
74-
id: 'workbench.action.editorDictation.stop',
78+
id: EditorDictationStopAction.ID,
7579
title: localize2('stopDictation', "Stop Dictation in Editor"),
7680
category: VOICE_CATEGORY,
7781
precondition: EDITOR_DICTATION_IN_PROGRESS,
@@ -94,15 +98,21 @@ export class DictationWidget extends Disposable implements IContentWidget {
9498
readonly allowEditorOverflow = true;
9599

96100
private readonly domNode = document.createElement('div');
97-
private readonly elements = h('.editor-dictation-widget@main', [h('span@mic')]);
98101

99-
constructor(private readonly editor: ICodeEditor) {
102+
constructor(private readonly editor: ICodeEditor, keybindingService: IKeybindingService) {
100103
super();
101104

102-
this.domNode.appendChild(this.elements.root);
103-
this.domNode.style.zIndex = '1000';
104-
105-
reset(this.elements.mic, renderIcon(Codicon.micFilled));
105+
const actionBar = this._register(new ActionBar(this.domNode));
106+
const stopActionKeybinding = keybindingService.lookupKeybinding(EditorDictationStopAction.ID)?.getLabel();
107+
actionBar.push(toAction({
108+
id: EditorDictationStopAction.ID,
109+
label: stopActionKeybinding ? localize('stopDictationShort1', "Stop Dictation ({0})", stopActionKeybinding) : localize('stopDictationShort2', "Stop Dictation"),
110+
class: ThemeIcon.asClassName(Codicon.micFilled),
111+
run: () => EditorDictation.get(editor)?.stop()
112+
}), { icon: true, label: false, keybinding: stopActionKeybinding });
113+
114+
this.domNode.classList.add('editor-dictation-widget');
115+
this.domNode.appendChild(actionBar.domNode);
106116
}
107117

108118
getId(): string {
@@ -133,8 +143,8 @@ export class DictationWidget extends Disposable implements IContentWidget {
133143
const lineHeight = this.editor.getOption(EditorOption.lineHeight);
134144
const width = this.editor.getLayoutInfo().contentWidth * 0.7;
135145

136-
this.elements.main.style.setProperty('--vscode-editor-dictation-widget-height', `${lineHeight}px`);
137-
this.elements.main.style.setProperty('--vscode-editor-dictation-widget-width', `${width}px`);
146+
this.domNode.style.setProperty('--vscode-editor-dictation-widget-height', `${lineHeight}px`);
147+
this.domNode.style.setProperty('--vscode-editor-dictation-widget-width', `${width}px`);
138148

139149
return null;
140150
}
@@ -148,11 +158,11 @@ export class DictationWidget extends Disposable implements IContentWidget {
148158
}
149159

150160
active(): void {
151-
this.elements.main.classList.add('recording');
161+
this.domNode.classList.add('recording');
152162
}
153163

154164
hide() {
155-
this.elements.main.classList.remove('recording');
165+
this.domNode.classList.remove('recording');
156166
this.editor.removeContentWidget(this);
157167
}
158168
}
@@ -165,15 +175,16 @@ export class EditorDictation extends Disposable implements IEditorContribution {
165175
return editor.getContribution<EditorDictation>(EditorDictation.ID);
166176
}
167177

168-
private readonly widget = this._register(new DictationWidget(this.editor));
178+
private readonly widget = this._register(new DictationWidget(this.editor, this.keybindingService));
169179
private readonly editorDictationInProgress = EDITOR_DICTATION_IN_PROGRESS.bindTo(this.contextKeyService);
170180

171181
private sessionDisposables = this._register(new MutableDisposable());
172182

173183
constructor(
174184
private readonly editor: ICodeEditor,
175185
@ISpeechService private readonly speechService: ISpeechService,
176-
@IContextKeyService private readonly contextKeyService: IContextKeyService
186+
@IContextKeyService private readonly contextKeyService: IContextKeyService,
187+
@IKeybindingService private readonly keybindingService: IKeybindingService
177188
) {
178189
super();
179190
}

0 commit comments

Comments
 (0)