@@ -21,7 +21,14 @@ function log(message, data) {
2121 if ( data !== undefined ) console . dir ( data ) ;
2222}
2323
24+ // Save the current view state.
25+ // Use this to restore the view when it is revealed.
2426var docs_filter = "" ;
27+ function saveWebViewState ( ) {
28+ const data = { filter : docs_filter } ;
29+ log ( 'saveWebViewState' , data ) ;
30+ vscode . setState ( data ) ;
31+ }
2532
2633//
2734// Declare a marlinfwSearch singleton
@@ -85,9 +92,6 @@ var marlinfwSearch = (() => {
8592 if ( k >= 32 || k == 8 ) self . onSearchKeyUp ( ) ;
8693 } )
8794
88- // Search the provided string on load
89- self . searchFromField ( ) ;
90-
9195 // Focus the search field, and also select all chars
9296 $searchInput . focus ( ) . select ( ) ;
9397 } ,
@@ -97,6 +101,12 @@ var marlinfwSearch = (() => {
97101 return $searchInput . val ( ) . trim ( ) ;
98102 } ,
99103
104+ // Set the search field value
105+ setFilter : ( val ) => {
106+ $searchInput . val ( val ) . select ( ) . focus ( ) ;
107+ self . searchFromField ( ) ;
108+ } ,
109+
100110 // Convert a string to a regex pattern
101111 searchPattern : ( str ) => {
102112 const patt = str . toLowerCase ( ) . replace ( ignore_pattern , '' ) . trim ( ) . replace ( / \s + / gm, '.+' ) . replace ( / ( [ ( [ \\ ] ) / gm, '\\$1' ) ;
@@ -141,6 +151,7 @@ var marlinfwSearch = (() => {
141151 if ( newq == '' ) return ;
142152
143153 docs_filter = newq ;
154+ saveWebViewState ( ) ;
144155 qmatch = newm ;
145156
146157 let resultsCount = 0 , results = '' , prevclass = '' ;
@@ -229,14 +240,6 @@ $(function () {
229240 marlinfwSearch . init ( ) ;
230241 }
231242
232- // Save the current view state.
233- // Use this to restore the view when it is revealed.
234- function saveWebViewState ( ) {
235- const data = { data : { } } ;
236- log ( 'saveWebViewState' , data ) ;
237- vscode . setState ( data ) ;
238- }
239-
240243 /**
241244 * @brief Handle messages sent from the provider with iview.postMessage(msg)
242245 * @description Handle 'message' events sent directly to the view.
@@ -275,9 +278,9 @@ $(function () {
275278 const state = vscode . getState ( ) ;
276279 if ( state ) {
277280 log ( "Got VSCode state" , state ) ;
278- if ( 'data ' in state ) {
281+ if ( 'filter ' in state ) {
279282 log ( "Init Marlin Docs Webview with stored data" )
280- initDocsView ( ) ;
283+ marlinfwSearch . setFilter ( state . filter ) ;
281284 }
282285 }
283286
0 commit comments