4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
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' ;
9
9
import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
10
10
import { Disposable , DisposableStore , MutableDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
11
11
import { ContentWidgetPositionPreference , ICodeEditor , IContentWidget , IContentWidgetPosition } from 'vs/editor/browser/editorBrowser' ;
12
12
import { IEditorContribution } from 'vs/editor/common/editorCommon' ;
13
13
import { ContextKeyExpr , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
14
14
import { HasSpeechProvider , ISpeechService , SpeechToTextStatus } from 'vs/workbench/contrib/speech/common/speechService' ;
15
- import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels' ;
16
15
import { Codicon } from 'vs/base/common/codicons' ;
17
16
import { EditorOption } from 'vs/editor/common/config/editorOptions' ;
18
17
import { EditorAction2 , EditorContributionInstantiation , registerEditorContribution } from 'vs/editor/browser/editorExtensions' ;
@@ -27,6 +26,9 @@ import { Position } from 'vs/editor/common/core/position';
27
26
import { Range } from 'vs/editor/common/core/range' ;
28
27
import { registerAction2 } from 'vs/platform/actions/common/actions' ;
29
28
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' ;
30
32
31
33
const EDITOR_DICTATION_IN_PROGRESS = new RawContextKey < boolean > ( 'editorDictation.inProgress' , false ) ;
32
34
const VOICE_CATEGORY = localize2 ( 'voiceCategory' , "Voice" ) ;
@@ -69,9 +71,11 @@ export class EditorDictationStartAction extends EditorAction2 {
69
71
70
72
export class EditorDictationStopAction extends EditorAction2 {
71
73
74
+ static readonly ID = 'workbench.action.editorDictation.stop' ;
75
+
72
76
constructor ( ) {
73
77
super ( {
74
- id : 'workbench.action.editorDictation.stop' ,
78
+ id : EditorDictationStopAction . ID ,
75
79
title : localize2 ( 'stopDictation' , "Stop Dictation in Editor" ) ,
76
80
category : VOICE_CATEGORY ,
77
81
precondition : EDITOR_DICTATION_IN_PROGRESS ,
@@ -94,15 +98,21 @@ export class DictationWidget extends Disposable implements IContentWidget {
94
98
readonly allowEditorOverflow = true ;
95
99
96
100
private readonly domNode = document . createElement ( 'div' ) ;
97
- private readonly elements = h ( '.editor-dictation-widget@main' , [ h ( 'span@mic' ) ] ) ;
98
101
99
- constructor ( private readonly editor : ICodeEditor ) {
102
+ constructor ( private readonly editor : ICodeEditor , keybindingService : IKeybindingService ) {
100
103
super ( ) ;
101
104
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 ) ;
106
116
}
107
117
108
118
getId ( ) : string {
@@ -133,8 +143,8 @@ export class DictationWidget extends Disposable implements IContentWidget {
133
143
const lineHeight = this . editor . getOption ( EditorOption . lineHeight ) ;
134
144
const width = this . editor . getLayoutInfo ( ) . contentWidth * 0.7 ;
135
145
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` ) ;
138
148
139
149
return null ;
140
150
}
@@ -148,11 +158,11 @@ export class DictationWidget extends Disposable implements IContentWidget {
148
158
}
149
159
150
160
active ( ) : void {
151
- this . elements . main . classList . add ( 'recording' ) ;
161
+ this . domNode . classList . add ( 'recording' ) ;
152
162
}
153
163
154
164
hide ( ) {
155
- this . elements . main . classList . remove ( 'recording' ) ;
165
+ this . domNode . classList . remove ( 'recording' ) ;
156
166
this . editor . removeContentWidget ( this ) ;
157
167
}
158
168
}
@@ -165,15 +175,16 @@ export class EditorDictation extends Disposable implements IEditorContribution {
165
175
return editor . getContribution < EditorDictation > ( EditorDictation . ID ) ;
166
176
}
167
177
168
- private readonly widget = this . _register ( new DictationWidget ( this . editor ) ) ;
178
+ private readonly widget = this . _register ( new DictationWidget ( this . editor , this . keybindingService ) ) ;
169
179
private readonly editorDictationInProgress = EDITOR_DICTATION_IN_PROGRESS . bindTo ( this . contextKeyService ) ;
170
180
171
181
private sessionDisposables = this . _register ( new MutableDisposable ( ) ) ;
172
182
173
183
constructor (
174
184
private readonly editor : ICodeEditor ,
175
185
@ISpeechService private readonly speechService : ISpeechService ,
176
- @IContextKeyService private readonly contextKeyService : IContextKeyService
186
+ @IContextKeyService private readonly contextKeyService : IContextKeyService ,
187
+ @IKeybindingService private readonly keybindingService : IKeybindingService
177
188
) {
178
189
super ( ) ;
179
190
}
0 commit comments