@@ -18,6 +18,7 @@ class WorkspaceV2SessionProducer {
1818 this . importJsonNode = document . getElementById ( "workspaceV2ImportJson" ) ;
1919 this . importFileNode = document . getElementById ( "workspaceV2ImportFile" ) ;
2020 this . importButton = document . getElementById ( "workspaceV2ImportButton" ) ;
21+ this . importTextareaButton = null ;
2122 this . exportButton = document . getElementById ( "workspaceV2ExportButton" ) ;
2223 this . workspaceJsonNode = this . importJsonNode ;
2324 this . shareUrlNode = document . getElementById ( "workspaceV2ShareUrl" ) ;
@@ -82,6 +83,7 @@ class WorkspaceV2SessionProducer {
8283 this . fullResetButton = document . getElementById ( "workspaceV2FullResetButton" ) ;
8384 this . statusNode = document . getElementById ( "workspaceV2Status" ) ;
8485 this . importExportStatusNode = null ;
86+ this . importFileDialogPending = false ;
8587 this . currentSessionPayload = null ;
8688 this . currentSessionSource = "" ;
8789 this . currentHostContextId = "" ;
@@ -115,6 +117,9 @@ class WorkspaceV2SessionProducer {
115117 this . importFileNode . addEventListener ( "change" , ( ) => {
116118 this . readImportFile ( ) ;
117119 } ) ;
120+ window . addEventListener ( "focus" , ( ) => {
121+ this . handleImportFileDialogFocus ( ) ;
122+ } ) ;
118123 this . saveSessionButton . addEventListener ( "click" , ( ) => {
119124 this . saveNamedSession ( false ) ;
120125 } ) ;
@@ -215,6 +220,7 @@ class WorkspaceV2SessionProducer {
215220 this . registerScrollTextColorRule ( ) ;
216221 this . initializeImportExportSectionStatusNode ( ) ;
217222 this . initializeHiddenImportFileInput ( ) ;
223+ this . initializeImportTextareaButton ( ) ;
218224 this . decodeSessionParamFromUrl ( ) ;
219225 this . initializeWorkspaceProducerSession ( ) ;
220226 this . refreshPaletteOwnershipStateAndUi ( ) ;
@@ -298,21 +304,53 @@ class WorkspaceV2SessionProducer {
298304 this . importFileNode . style . display = "none" ;
299305 }
300306
301- handleImportWorkspaceSessionJsonClick ( ) {
302- const rawJson = typeof this . workspaceJsonNode . value === "string" ? this . workspaceJsonNode . value . trim ( ) : "" ;
303- if ( rawJson ) {
304- this . importWorkspaceSessionJson ( ) ;
305- return ;
307+ initializeImportTextareaButton ( ) {
308+ const existingButton = document . getElementById ( "workspaceV2ImportTextareaButton" ) ;
309+ if ( existingButton instanceof HTMLButtonElement ) {
310+ this . importTextareaButton = existingButton ;
311+ } else {
312+ const importButtonParent = this . importButton ? this . importButton . parentElement : null ;
313+ if ( ! importButtonParent ) {
314+ return ;
315+ }
316+ const textareaImportButton = document . createElement ( "button" ) ;
317+ textareaImportButton . type = "button" ;
318+ textareaImportButton . id = "workspaceV2ImportTextareaButton" ;
319+ textareaImportButton . textContent = "Import Textarea JSON" ;
320+ importButtonParent . insertBefore ( textareaImportButton , this . importButton . nextSibling ) ;
321+ this . importTextareaButton = textareaImportButton ;
306322 }
323+ this . importTextareaButton . addEventListener ( "click" , ( ) => {
324+ this . importWorkspaceSessionJson ( ) ;
325+ } ) ;
326+ }
327+
328+ handleImportWorkspaceSessionJsonClick ( ) {
307329 this . setImportExportStatus ( "Select a workspace session file to import." ) ;
308330 if ( ! this . importFileNode ) {
309331 this . setImportExportStatus ( "Import error: file picker is unavailable." ) ;
310332 return ;
311333 }
334+ this . importFileDialogPending = true ;
312335 this . importFileNode . value = "" ;
313336 this . importFileNode . click ( ) ;
314337 }
315338
339+ handleImportFileDialogFocus ( ) {
340+ if ( ! this . importFileDialogPending ) {
341+ return ;
342+ }
343+ window . setTimeout ( ( ) => {
344+ if ( ! this . importFileDialogPending ) {
345+ return ;
346+ }
347+ if ( ! this . importFileNode . files || this . importFileNode . files . length === 0 ) {
348+ this . importFileDialogPending = false ;
349+ this . setImportExportStatus ( "Import cancelled." ) ;
350+ }
351+ } , 0 ) ;
352+ }
353+
316354 applyDefaultWorkspaceToolSelection ( ) {
317355 if ( ! this . toolSelect ) {
318356 return ;
@@ -3353,15 +3391,21 @@ class WorkspaceV2SessionProducer {
33533391
33543392 readImportFile ( ) {
33553393 if ( ! this . importFileNode . files || this . importFileNode . files . length === 0 ) {
3394+ if ( this . importFileDialogPending ) {
3395+ this . importFileDialogPending = false ;
3396+ this . setImportExportStatus ( "Import cancelled." ) ;
3397+ }
33563398 return ;
33573399 }
3400+ this . importFileDialogPending = false ;
33583401 const file = this . importFileNode . files [ 0 ] ;
33593402 const reader = new FileReader ( ) ;
33603403 reader . addEventListener ( "load" , ( ) => {
33613404 this . importJsonNode . value = typeof reader . result === "string" ? reader . result : "" ;
33623405 this . importWorkspaceSessionJson ( ) ;
33633406 } ) ;
33643407 reader . addEventListener ( "error" , ( ) => {
3408+ this . importFileDialogPending = false ;
33653409 this . setImportExportStatus ( `Import error: ${ file . name } could not be read.` ) ;
33663410 } ) ;
33673411 reader . readAsText ( file ) ;
0 commit comments