44 *--------------------------------------------------------------------------------------------*/
55
66import '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' ;
99import { CancellationTokenSource } from 'vs/base/common/cancellation' ;
1010import { Disposable , DisposableStore , MutableDisposable , toDisposable } from 'vs/base/common/lifecycle' ;
1111import { ContentWidgetPositionPreference , ICodeEditor , IContentWidget , IContentWidgetPosition } from 'vs/editor/browser/editorBrowser' ;
1212import { IEditorContribution } from 'vs/editor/common/editorCommon' ;
1313import { ContextKeyExpr , IContextKeyService , RawContextKey } from 'vs/platform/contextkey/common/contextkey' ;
1414import { HasSpeechProvider , ISpeechService , SpeechToTextStatus } from 'vs/workbench/contrib/speech/common/speechService' ;
15- import { renderIcon } from 'vs/base/browser/ui/iconLabel/iconLabels' ;
1615import { Codicon } from 'vs/base/common/codicons' ;
1716import { EditorOption } from 'vs/editor/common/config/editorOptions' ;
1817import { EditorAction2 , EditorContributionInstantiation , registerEditorContribution } from 'vs/editor/browser/editorExtensions' ;
@@ -27,6 +26,9 @@ import { Position } from 'vs/editor/common/core/position';
2726import { Range } from 'vs/editor/common/core/range' ;
2827import { registerAction2 } from 'vs/platform/actions/common/actions' ;
2928import { 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
3133const EDITOR_DICTATION_IN_PROGRESS = new RawContextKey < boolean > ( 'editorDictation.inProgress' , false ) ;
3234const VOICE_CATEGORY = localize2 ( 'voiceCategory' , "Voice" ) ;
@@ -69,9 +71,11 @@ export class EditorDictationStartAction extends EditorAction2 {
6971
7072export 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