@@ -283,8 +283,9 @@ export class ChatWidget extends Disposable implements IChatWidget {
283283
284284 private welcomeMessageContainer ! : HTMLElement ;
285285 private readonly welcomePart : MutableDisposable < ChatViewWelcomePart > = this . _register ( new MutableDisposable ( ) ) ;
286+ private readonly historyViewStore = this . _register ( new DisposableStore ( ) ) ;
286287 private readonly chatTodoListWidget : ChatTodoListWidget ;
287- private historyList ! : WorkbenchList < IChatHistoryListItem > ;
288+ private historyList : WorkbenchList < IChatHistoryListItem > | undefined ;
288289
289290 private bodyDimension : dom . Dimension | undefined ;
290291 private visibleChangeCount = 0 ;
@@ -944,6 +945,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
944945 welcomeContent . tips = tips ;
945946 }
946947 if ( ! this . welcomePart . value || this . welcomePart . value . needsRerender ( welcomeContent ) ) {
948+ this . historyViewStore . clear ( ) ;
947949 dom . clearNode ( this . welcomeMessageContainer ) ;
948950
949951 // Optional: recent chat history above welcome content when enabled
@@ -1004,17 +1006,20 @@ export class ChatWidget extends Disposable implements IChatWidget {
10041006 showAllButton . setAttribute ( 'role' , 'button' ) ;
10051007 const showAllHover = localize ( 'chat.history.showAllHover' , 'Show history...' ) ;
10061008 showAllButton . setAttribute ( 'aria-label' , showAllHover ) ;
1007- const showAllHoverEl = dom . $ ( 'div.chat-history-button-hover' ) ;
1008- showAllHoverEl . textContent = showAllHover ;
1009- this . _register ( this . hoverService . setupDelayedHover ( showAllButton , { content : showAllHoverEl , appearance : { showPointer : false , compact : true } } ) ) ;
1010- this . _register ( dom . addDisposableListener ( showAllButton , dom . EventType . CLICK , e => {
1009+ const showAllHoverText = dom . $ ( 'div.chat-history-button-hover' ) ;
1010+ showAllHoverText . textContent = showAllHover ;
1011+
1012+ this . historyViewStore . add ( this . hoverService . setupDelayedHover ( showAllButton , { content : showAllHoverText , appearance : { showPointer : false , compact : true } } ) ) ;
1013+
1014+ this . historyViewStore . add ( dom . addDisposableListener ( showAllButton , dom . EventType . CLICK , e => {
10111015 e . preventDefault ( ) ;
10121016 e . stopPropagation ( ) ;
10131017 setTimeout ( ( ) => {
10141018 this . instantiationService . invokeFunction ( accessor => accessor . get ( ICommandService ) . executeCommand ( 'workbench.action.chat.history' ) ) ;
10151019 } , 0 ) ;
10161020 } ) ) ;
1017- this . _register ( dom . addStandardDisposableListener ( showAllButton , dom . EventType . KEY_DOWN , e => {
1021+
1022+ this . historyViewStore . add ( dom . addStandardDisposableListener ( showAllButton , dom . EventType . KEY_DOWN , e => {
10181023 if ( e . equals ( KeyCode . Enter ) || e . equals ( KeyCode . Space ) ) {
10191024 e . preventDefault ( ) ;
10201025 e . stopPropagation ( ) ;
@@ -1023,7 +1028,7 @@ export class ChatWidget extends Disposable implements IChatWidget {
10231028 } , 0 ) ;
10241029 }
10251030 } ) ) ;
1026- const welcomeHistoryList = dom . append ( container , $ ( '.chat-welcome-history-list' ) ) ;
1031+ const welcomeHistoryContainer = dom . append ( container , $ ( '.chat-welcome-history-list' ) ) ;
10271032
10281033 this . welcomeMessageContainer . classList . toggle ( 'has-chat-history' , filtered . length > 0 ) ;
10291034
@@ -1040,38 +1045,46 @@ export class ChatWidget extends Disposable implements IChatWidget {
10401045 isActive : item . isActive
10411046 } ) ) ;
10421047
1043- const delegate = new ChatHistoryListDelegate ( ) ;
1044- const renderer = new ChatHistoryListRenderer (
1045- async ( item ) => await this . openHistorySession ( item . sessionId ) ,
1046- this . hoverService ,
1047- ( timestamp , todayMs ) => this . formatHistoryTimestamp ( timestamp , todayMs ) ,
1048- todayMidnightMs
1049- ) ;
10501048 const listHeight = historyItems . length * 22 ;
1051- welcomeHistoryList . style . height = `${ listHeight } px` ;
1052- welcomeHistoryList . style . minHeight = `${ listHeight } px` ;
1053- welcomeHistoryList . style . overflow = 'hidden' ;
1054-
1055- this . historyList = this . _register ( this . instantiationService . createInstance (
1056- WorkbenchList < IChatHistoryListItem > ,
1057- 'ChatHistoryList' ,
1058- welcomeHistoryList ,
1059- delegate ,
1060- [ renderer ] ,
1061- {
1062- horizontalScrolling : false ,
1063- keyboardSupport : true ,
1064- mouseSupport : true ,
1065- multipleSelectionSupport : false ,
1066- overrideStyles : {
1067- listBackground : this . styles . listBackground
1068- } ,
1069- accessibilityProvider : {
1070- getAriaLabel : ( item : IChatHistoryListItem ) => item . title ,
1071- getWidgetAriaLabel : ( ) => localize ( 'chat.history.list' , 'Chat History' )
1049+ welcomeHistoryContainer . style . height = `${ listHeight } px` ;
1050+ welcomeHistoryContainer . style . minHeight = `${ listHeight } px` ;
1051+ welcomeHistoryContainer . style . overflow = 'hidden' ;
1052+
1053+ if ( ! this . historyList ) {
1054+ const delegate = new ChatHistoryListDelegate ( ) ;
1055+ const renderer = new ChatHistoryListRenderer (
1056+ async ( item ) => await this . openHistorySession ( item . sessionId ) ,
1057+ this . hoverService ,
1058+ ( timestamp , todayMs ) => this . formatHistoryTimestamp ( timestamp , todayMs ) ,
1059+ todayMidnightMs
1060+ ) ;
1061+ const list = this . instantiationService . createInstance (
1062+ WorkbenchList < IChatHistoryListItem > ,
1063+ 'ChatHistoryList' ,
1064+ welcomeHistoryContainer ,
1065+ delegate ,
1066+ [ renderer ] ,
1067+ {
1068+ horizontalScrolling : false ,
1069+ keyboardSupport : true ,
1070+ mouseSupport : true ,
1071+ multipleSelectionSupport : false ,
1072+ overrideStyles : {
1073+ listBackground : this . styles . listBackground
1074+ } ,
1075+ accessibilityProvider : {
1076+ getAriaLabel : ( item : IChatHistoryListItem ) => item . title ,
1077+ getWidgetAriaLabel : ( ) => localize ( 'chat.history.list' , 'Chat History' )
1078+ }
10721079 }
1080+ ) ;
1081+ this . historyList = this . _register ( list ) ;
1082+ } else {
1083+ const currentHistoryList = this . historyList . getHTMLElement ( ) ;
1084+ if ( currentHistoryList && currentHistoryList . parentElement !== welcomeHistoryContainer ) {
1085+ welcomeHistoryContainer . appendChild ( currentHistoryList ) ;
10731086 }
1074- ) ) ;
1087+ }
10751088
10761089 this . historyList . splice ( 0 , 0 , historyItems ) ;
10771090 this . historyList . layout ( undefined , listHeight ) ;
0 commit comments