@@ -15,27 +15,22 @@ import { ITextModel } from 'vs/editor/common/model';
15
15
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures' ;
16
16
import { localize } from 'vs/nls' ;
17
17
import { Registry } from 'vs/platform/registry/common/platform' ;
18
- import { editorForeground , textCodeBlockBackground , textLinkForeground } from 'vs/platform/theme/common/colorRegistry' ;
18
+ import { editorForeground } from 'vs/platform/theme/common/colorRegistry' ;
19
19
import { IThemeService } from 'vs/platform/theme/common/themeService' ;
20
20
import { IChatWidget , IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat' ;
21
21
import { ChatWidget } from 'vs/workbench/contrib/chat/browser/chatWidget' ;
22
22
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
23
23
import { ChatInputPart } from 'vs/workbench/contrib/chat/browser/chatInputPart' ;
24
24
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService' ;
25
- import { ContentWidgetPositionPreference , IContentWidget } from 'vs/editor/browser/editorBrowser' ;
26
- import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent' ;
27
- import { KeyCode } from 'vs/base/common/keyCodes' ;
28
- import { Selection } from 'vs/editor/common/core/selection' ;
25
+ import { SlashCommandContentWidget } from 'vs/workbench/contrib/chat/browser/chatSlashCommandContentWidget' ;
29
26
30
27
const decorationDescription = 'chat' ;
31
28
const slashCommandPlaceholderDecorationType = 'chat-session-detail' ;
32
29
const slashCommandTextDecorationType = 'chat-session-text' ;
33
- const slashCommandContentWidgetId = 'chat-session-content-widget' ;
34
30
35
31
class InputEditorDecorations extends Disposable {
36
32
37
- private _slashCommandDomNode = document . createElement ( 'div' ) ;
38
- private _slashCommandContentWidget : IContentWidget | undefined ;
33
+ private _slashCommandContentWidget : SlashCommandContentWidget | undefined ;
39
34
private _previouslyUsedSlashCommands = new Set < string > ( ) ;
40
35
41
36
constructor (
@@ -66,7 +61,7 @@ class InputEditorDecorations extends Disposable {
66
61
67
62
private updateRegisteredDecorationTypes ( ) {
68
63
this . codeEditorService . removeDecorationType ( slashCommandTextDecorationType ) ;
69
- this . updateInputEditorContentWidgets ( { hide : true } ) ;
64
+ this . _slashCommandContentWidget ?. hide ( ) ;
70
65
this . codeEditorService . registerDecorationType ( decorationDescription , slashCommandTextDecorationType , {
71
66
opacity : '0' ,
72
67
after : {
@@ -109,7 +104,7 @@ class InputEditorDecorations extends Disposable {
109
104
}
110
105
] ;
111
106
this . widget . inputEditor . setDecorationsByType ( decorationDescription , slashCommandPlaceholderDecorationType , decoration ) ;
112
- this . updateInputEditorContentWidgets ( { hide : true } ) ;
107
+ this . _slashCommandContentWidget ?. hide ( ) ;
113
108
return ;
114
109
}
115
110
@@ -142,9 +137,14 @@ class InputEditorDecorations extends Disposable {
142
137
}
143
138
144
139
if ( command && inputValue . startsWith ( `/${ command . command } ` ) ) {
145
- this . updateInputEditorContentWidgets ( { command : command . command } ) ;
140
+ if ( ! this . _slashCommandContentWidget ) {
141
+ this . _slashCommandContentWidget = new SlashCommandContentWidget ( this . widget . inputEditor ) ;
142
+ this . _store . add ( this . _slashCommandContentWidget ) ;
143
+ }
144
+ this . _slashCommandContentWidget . setCommandText ( command . command ) ;
145
+ this . _slashCommandContentWidget . show ( ) ;
146
146
} else {
147
- this . updateInputEditorContentWidgets ( { hide : true } ) ;
147
+ this . _slashCommandContentWidget ?. hide ( ) ;
148
148
}
149
149
150
150
if ( command && command . detail ) {
@@ -163,40 +163,6 @@ class InputEditorDecorations extends Disposable {
163
163
this . widget . inputEditor . setDecorationsByType ( decorationDescription , slashCommandTextDecorationType , [ ] ) ;
164
164
}
165
165
}
166
-
167
- private async updateInputEditorContentWidgets ( arg : { command : string } | { hide : true } ) {
168
- const domNode = this . _slashCommandDomNode ;
169
-
170
- if ( this . _slashCommandContentWidget && 'hide' in arg ) {
171
- domNode . toggleAttribute ( 'hidden' , true ) ;
172
- this . widget . inputEditor . removeContentWidget ( this . _slashCommandContentWidget ) ;
173
- return ;
174
- } else if ( 'command' in arg ) {
175
- const theme = this . themeService . getColorTheme ( ) ;
176
- domNode . style . padding = '0 0.4em' ;
177
- domNode . style . borderRadius = '3px' ;
178
- domNode . style . backgroundColor = theme . getColor ( textCodeBlockBackground ) ?. toString ( ) ?? '' ;
179
- domNode . style . color = theme . getColor ( textLinkForeground ) ?. toString ( ) ?? '' ;
180
- domNode . innerText = `${ arg . command } ` ;
181
- domNode . toggleAttribute ( 'hidden' , false ) ;
182
-
183
- this . _slashCommandContentWidget = {
184
- getId ( ) { return slashCommandContentWidgetId ; } ,
185
- getDomNode ( ) { return domNode ; } ,
186
- getPosition ( ) {
187
- return {
188
- position : {
189
- lineNumber : 1 ,
190
- column : 1
191
- } ,
192
- preference : [ ContentWidgetPositionPreference . EXACT ]
193
- } ;
194
- } ,
195
- } ;
196
-
197
- this . widget . inputEditor . addContentWidget ( this . _slashCommandContentWidget ) ;
198
- }
199
- }
200
166
}
201
167
202
168
class InputEditorSlashCommandFollowups extends Disposable {
@@ -206,7 +172,6 @@ class InputEditorSlashCommandFollowups extends Disposable {
206
172
) {
207
173
super ( ) ;
208
174
this . _register ( this . chatService . onDidSubmitSlashCommand ( ( { slashCommand, sessionId } ) => this . repopulateSlashCommand ( slashCommand , sessionId ) ) ) ;
209
- this . _register ( this . widget . inputEditor . onKeyUp ( ( e ) => this . handleKeyUp ( e ) ) ) ;
210
175
}
211
176
212
177
private async repopulateSlashCommand ( slashCommand : string , sessionId : string ) {
@@ -227,22 +192,6 @@ class InputEditorSlashCommandFollowups extends Disposable {
227
192
228
193
}
229
194
}
230
-
231
- private handleKeyUp ( e : IKeyboardEvent ) {
232
- if ( e . keyCode !== KeyCode . Backspace ) {
233
- return ;
234
- }
235
-
236
- const value = this . widget . inputEditor . getValue ( ) . split ( ' ' ) [ 0 ] ;
237
- const currentSelection = this . widget . inputEditor . getSelection ( ) ;
238
- if ( ! value . startsWith ( '/' ) || ! currentSelection ?. isEmpty ( ) || currentSelection ?. startLineNumber !== 1 || currentSelection ?. startColumn !== value . length + 1 ) {
239
- return ;
240
- }
241
-
242
- if ( this . widget . getSlashCommandsSync ( ) ?. find ( ( command ) => `/${ command . command } ` === value ) ) {
243
- this . widget . inputEditor . executeEdits ( 'chat-input-editor-slash-commands' , [ { range : new Range ( 1 , 1 , 1 , currentSelection . startColumn ) , text : null } ] , [ new Selection ( 1 , 1 , 1 , 1 ) ] ) ;
244
- }
245
- }
246
195
}
247
196
248
197
ChatWidget . CONTRIBS . push ( InputEditorDecorations , InputEditorSlashCommandFollowups ) ;
0 commit comments