@@ -31,6 +31,7 @@ import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storag
31
31
import { defaultButtonStyles } from 'vs/platform/theme/browser/defaultStyles' ;
32
32
import { foreground } from 'vs/platform/theme/common/colorRegistry' ;
33
33
import { DEFAULT_FONT_FAMILY } from 'vs/workbench/browser/style' ;
34
+ import { Memento } from 'vs/workbench/common/memento' ;
34
35
import { getSimpleCodeEditorWidgetOptions , getSimpleEditorOptions } from 'vs/workbench/contrib/codeEditor/browser/simpleEditorOptions' ;
35
36
import { IInteractiveSessionExecuteActionContext } from 'vs/workbench/contrib/interactiveSession/browser/actions/interactiveSessionExecuteActions' ;
36
37
import { IInteractiveSessionWidget } from 'vs/workbench/contrib/interactiveSession/browser/interactiveSession' ;
@@ -62,6 +63,11 @@ function revealLastElement(list: WorkbenchObjectTree<any>) {
62
63
list . scrollTop = list . scrollHeight - list . renderHeight ;
63
64
}
64
65
66
+ interface IViewState {
67
+ history : string [ ] ;
68
+ inputValue : string ;
69
+ }
70
+
65
71
const HISTORY_STORAGE_KEY = 'interactiveSession.history' ;
66
72
const INPUT_EDITOR_MAX_HEIGHT = 250 ;
67
73
@@ -138,6 +144,9 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
138
144
private lastSlashCommands : IInteractiveSlashCommand [ ] | undefined ;
139
145
private slashCommandsPromise : Promise < IInteractiveSlashCommand [ ] | undefined > | undefined ;
140
146
147
+ private memento : Memento ;
148
+ private viewState : IViewState ;
149
+
141
150
constructor (
142
151
private readonly providerId : string ,
143
152
readonly viewId : string | undefined ,
@@ -160,7 +169,12 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
160
169
this . _register ( ( interactiveSessionWidgetService as InteractiveSessionWidgetService ) . register ( this ) ) ;
161
170
this . initializeSessionModel ( true ) ;
162
171
163
- this . history = new HistoryNavigator ( JSON . parse ( this . storageService . get ( this . getHistoryStorageKey ( ) , StorageScope . WORKSPACE , '[]' ) ) , 50 ) ;
172
+ const oldPersistedHistory = JSON . parse ( this . storageService . get ( this . getHistoryStorageKey ( ) , StorageScope . WORKSPACE , '[]' ) ) ;
173
+ this . memento = new Memento ( 'interactive-session-' + this . providerId , storageService ) ;
174
+ this . viewState = this . memento . getMemento ( StorageScope . WORKSPACE , StorageTarget . USER ) as IViewState ;
175
+
176
+ const history = this . viewState . history ?? oldPersistedHistory ;
177
+ this . history = new HistoryNavigator ( history , 50 ) ;
164
178
}
165
179
166
180
get element ( ) : HTMLElement {
@@ -247,8 +261,13 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
247
261
if ( ! this . inputModel ) {
248
262
this . inputModel = this . modelService . getModel ( this . inputUri ) || this . modelService . createModel ( '' , null , this . inputUri , true ) ;
249
263
this . inputModel . updateOptions ( { bracketColorizationOptions : { enabled : false , independentColorPoolPerBracketType : false } } ) ;
264
+ this . _inputEditor . setModel ( this . inputModel ) ;
265
+ if ( this . viewState . inputValue ) {
266
+ this . inputModel . setValue ( this . viewState . inputValue ) ;
267
+ const lineNumber = this . inputModel . getLineCount ( ) ;
268
+ this . _inputEditor . setPosition ( { lineNumber, column : this . inputModel . getLineMaxColumn ( lineNumber ) } ) ;
269
+ }
250
270
}
251
- this . _inputEditor . setModel ( this . inputModel ) ;
252
271
253
272
// Not sure why this is needed- the view is being rendered before it's visible, and then the list content doesn't show up
254
273
this . onDidChangeItems ( ) ;
@@ -613,14 +632,13 @@ export class InteractiveSessionWidget extends Disposable implements IInteractive
613
632
614
633
saveState ( ) : void {
615
634
const inputHistory = this . history . getHistory ( ) ;
616
- if ( inputHistory . length ) {
617
- this . storageService . store ( this . getHistoryStorageKey ( ) , JSON . stringify ( inputHistory ) , StorageScope . WORKSPACE , StorageTarget . USER ) ;
618
- } else {
619
- this . storageService . remove ( this . getHistoryStorageKey ( ) , StorageScope . WORKSPACE ) ;
620
- }
635
+ this . viewState . history = inputHistory ;
636
+ this . viewState . inputValue = this . _inputEditor . getValue ( ) ;
637
+ this . memento . saveMemento ( ) ;
621
638
}
622
639
623
640
public override dispose ( ) : void {
641
+ this . saveState ( ) ;
624
642
super . dispose ( ) ;
625
643
626
644
if ( this . viewModel ) {
0 commit comments