@@ -31,6 +31,7 @@ import { forceLoad } from '../transforms';
3131import  {  isAllowedAction ,  isAllowedMessage ,  postActionToExtension  }  from  './helpers' ; 
3232import  {  generatePostOfficeSendReducer  }  from  './postOffice' ; 
3333import  {  generateMonacoReducer ,  IMonacoState  }  from  './reducers/monaco' ; 
34+ import  {  CommonActionType  }  from  './reducers/types' ; 
3435import  {  generateVariableReducer ,  IVariableState  }  from  './reducers/variables' ; 
3536
3637function  generateDefaultState ( 
@@ -109,19 +110,21 @@ function createSendInfoMiddleware(): Redux.Middleware<{}, IStore> {
109110 } 
110111
111112 // If cell vm count changed or selected cell changed, send the message 
112-  const  currentSelection  =  getSelectedAndFocusedInfo ( afterState . main ) ; 
113-  if  ( 
114-  prevState . main . cellVMs . length  !==  afterState . main . cellVMs . length  || 
115-  getSelectedAndFocusedInfo ( prevState . main ) . selectedCellId  !==  currentSelection . selectedCellId  || 
116-  prevState . main . undoStack . length  !==  afterState . main . undoStack . length  || 
117-  prevState . main . redoStack . length  !==  afterState . main . redoStack . length 
118-  )  { 
119-  postActionToExtension ( {  queueAction : store . dispatch  } ,  InteractiveWindowMessages . SendInfo ,  { 
120-  cellCount : afterState . main . cellVMs . length , 
121-  undoCount : afterState . main . undoStack . length , 
122-  redoCount : afterState . main . redoStack . length , 
123-  selectedCell : currentSelection . selectedCellId 
124-  } ) ; 
113+  if  ( ! action . type  ||  action . type  !==  CommonActionType . UNMOUNT )  { 
114+  const  currentSelection  =  getSelectedAndFocusedInfo ( afterState . main ) ; 
115+  if  ( 
116+  prevState . main . cellVMs . length  !==  afterState . main . cellVMs . length  || 
117+  getSelectedAndFocusedInfo ( prevState . main ) . selectedCellId  !==  currentSelection . selectedCellId  || 
118+  prevState . main . undoStack . length  !==  afterState . main . undoStack . length  || 
119+  prevState . main . redoStack . length  !==  afterState . main . redoStack . length 
120+  )  { 
121+  postActionToExtension ( {  queueAction : store . dispatch  } ,  InteractiveWindowMessages . SendInfo ,  { 
122+  cellCount : afterState . main . cellVMs . length , 
123+  undoCount : afterState . main . undoStack . length , 
124+  redoCount : afterState . main . redoStack . length , 
125+  selectedCell : currentSelection . selectedCellId 
126+  } ) ; 
127+  } 
125128 } 
126129 return  res ; 
127130 } ; 
@@ -159,21 +162,26 @@ function createTestMiddleware(): Redux.Middleware<{}, IStore> {
159162 } ) ; 
160163 } ; 
161164
162-  // Special case for focusing a cell 
163-  const  previousSelection  =  getSelectedAndFocusedInfo ( prevState . main ) ; 
164-  const  currentSelection  =  getSelectedAndFocusedInfo ( afterState . main ) ; 
165-  if  ( previousSelection . focusedCellId  !==  currentSelection . focusedCellId  &&  currentSelection . focusedCellId )  { 
166-  // Send async so happens after render state changes (so our enzyme wrapper is up to date) 
167-  sendMessage ( InteractiveWindowMessages . FocusedCellEditor ,  {  cellId : action . payload . cellId  } ) ; 
168-  } 
169-  if  ( previousSelection . selectedCellId  !==  currentSelection . selectedCellId  &&  currentSelection . selectedCellId )  { 
170-  // Send async so happens after render state changes (so our enzyme wrapper is up to date) 
171-  sendMessage ( InteractiveWindowMessages . SelectedCell ,  {  cellId : action . payload . cellId  } ) ; 
172-  } 
173-  // Special case for unfocusing a cell 
174-  if  ( previousSelection . focusedCellId  !==  currentSelection . focusedCellId  &&  ! currentSelection . focusedCellId )  { 
175-  // Send async so happens after render state changes (so our enzyme wrapper is up to date) 
176-  sendMessage ( InteractiveWindowMessages . UnfocusedCellEditor ) ; 
165+  if  ( ! action . type  ||  action . type  !==  CommonActionType . UNMOUNT )  { 
166+  // Special case for focusing a cell 
167+  const  previousSelection  =  getSelectedAndFocusedInfo ( prevState . main ) ; 
168+  const  currentSelection  =  getSelectedAndFocusedInfo ( afterState . main ) ; 
169+  if  ( previousSelection . focusedCellId  !==  currentSelection . focusedCellId  &&  currentSelection . focusedCellId )  { 
170+  // Send async so happens after render state changes (so our enzyme wrapper is up to date) 
171+  sendMessage ( InteractiveWindowMessages . FocusedCellEditor ,  {  cellId : action . payload . cellId  } ) ; 
172+  } 
173+  if  ( 
174+  previousSelection . selectedCellId  !==  currentSelection . selectedCellId  && 
175+  currentSelection . selectedCellId 
176+  )  { 
177+  // Send async so happens after render state changes (so our enzyme wrapper is up to date) 
178+  sendMessage ( InteractiveWindowMessages . SelectedCell ,  {  cellId : action . payload . cellId  } ) ; 
179+  } 
180+  // Special case for unfocusing a cell 
181+  if  ( previousSelection . focusedCellId  !==  currentSelection . focusedCellId  &&  ! currentSelection . focusedCellId )  { 
182+  // Send async so happens after render state changes (so our enzyme wrapper is up to date) 
183+  sendMessage ( InteractiveWindowMessages . UnfocusedCellEditor ) ; 
184+  } 
177185 } 
178186
179187 // Indicate settings updates 
@@ -218,7 +226,10 @@ function createTestMiddleware(): Redux.Middleware<{}, IStore> {
218226 sendMessage ( InteractiveWindowMessages . ExecutionRendered ) ; 
219227 } 
220228
221-  if  ( ! action . type  ||  action . type  !==  InteractiveWindowMessages . FinishCell )  { 
229+  if  ( 
230+  ! action . type  || 
231+  ( action . type  !==  InteractiveWindowMessages . FinishCell  &&  action . type  !==  CommonActionType . UNMOUNT ) 
232+  )  { 
222233 // Might be a non finish but still update cells (like an undo or a delete) 
223234 const  prevFinished  =  prevState . main . cellVMs 
224235 . filter ( ( c )  =>  c . cell . state  ===  CellState . finished  ||  c . cell . state  ===  CellState . error ) 
0 commit comments