3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import type { Terminal as RawXtermTerminal } from '@xterm/xterm' ;
6
7
import { Dimension , IFocusTracker , trackFocus } from 'vs/base/browser/dom' ;
7
8
import { Event } from 'vs/base/common/event' ;
8
9
import { Disposable , toDisposable } from 'vs/base/common/lifecycle' ;
10
+ import { MicrotaskDelay } from 'vs/base/common/symbols' ;
9
11
import 'vs/css!./media/terminalChatWidget' ;
10
12
import { localize } from 'vs/nls' ;
11
13
import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
12
14
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
13
15
import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents' ;
14
16
import { IChatProgress } from 'vs/workbench/contrib/chat/common/chatService' ;
15
17
import { InlineChatWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatWidget' ;
16
- import { ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal' ;
18
+ import { ITerminalInstance , type IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal' ;
17
19
import { MENU_TERMINAL_CHAT_INPUT , MENU_TERMINAL_CHAT_WIDGET , MENU_TERMINAL_CHAT_WIDGET_FEEDBACK , MENU_TERMINAL_CHAT_WIDGET_STATUS , TerminalChatCommandId , TerminalChatContextKeys } from 'vs/workbench/contrib/terminalContrib/chat/browser/terminalChat' ;
20
+ import { TerminalStickyScrollContribution } from 'vs/workbench/contrib/terminalContrib/stickyScroll/browser/terminalStickyScrollContribution' ;
18
21
19
22
const enum Constants {
20
23
HorizontalMargin = 10
@@ -35,6 +38,7 @@ export class TerminalChatWidget extends Disposable {
35
38
constructor (
36
39
private readonly _terminalElement : HTMLElement ,
37
40
private readonly _instance : ITerminalInstance ,
41
+ private readonly _xterm : IXtermTerminal & { raw : RawXtermTerminal } ,
38
42
@IInstantiationService private readonly _instantiationService : IInstantiationService ,
39
43
@IContextKeyService private readonly _contextKeyService : IContextKeyService
40
44
) {
@@ -73,6 +77,7 @@ export class TerminalChatWidget extends Disposable {
73
77
this . _register ( Event . any (
74
78
this . _inlineChatWidget . onDidChangeHeight ,
75
79
this . _instance . onDimensionsChanged ,
80
+ Event . debounce ( this . _xterm . raw . onCursorMove , ( ) => void 0 , MicrotaskDelay ) ,
76
81
) ( ( ) => this . _relayout ( ) ) ) ;
77
82
78
83
const observer = new ResizeObserver ( ( ) => this . _relayout ( ) ) ;
@@ -102,6 +107,7 @@ export class TerminalChatWidget extends Disposable {
102
107
}
103
108
this . _dimension = new Dimension ( width , height ) ;
104
109
this . _inlineChatWidget . layout ( this . _dimension ) ;
110
+
105
111
this . _updateVerticalPosition ( ) ;
106
112
}
107
113
@@ -134,7 +140,9 @@ export class TerminalChatWidget extends Disposable {
134
140
return ;
135
141
}
136
142
if ( top > terminalWrapperHeight - widgetHeight ) {
137
- this . _container . style . top = '' ;
143
+ this . _setTerminalOffset ( top - ( terminalWrapperHeight - widgetHeight ) ) ;
144
+ } else {
145
+ this . _setTerminalOffset ( undefined ) ;
138
146
}
139
147
}
140
148
@@ -154,6 +162,18 @@ export class TerminalChatWidget extends Disposable {
154
162
this . _visibleContextKey . set ( false ) ;
155
163
this . _inlineChatWidget . value = '' ;
156
164
this . _instance . focus ( ) ;
165
+ this . _setTerminalOffset ( undefined ) ;
166
+ }
167
+ private _setTerminalOffset ( offset : number | undefined ) {
168
+ if ( offset === undefined || this . _container . classList . contains ( 'hide' ) ) {
169
+ this . _terminalElement . style . position = '' ;
170
+ this . _terminalElement . style . bottom = '' ;
171
+ TerminalStickyScrollContribution . get ( this . _instance ) ?. hideUnlock ( ) ;
172
+ } else {
173
+ this . _terminalElement . style . position = 'relative' ;
174
+ this . _terminalElement . style . bottom = `${ offset } px` ;
175
+ TerminalStickyScrollContribution . get ( this . _instance ) ?. hideLock ( ) ;
176
+ }
157
177
}
158
178
focus ( ) : void {
159
179
this . _inlineChatWidget . focus ( ) ;
0 commit comments