diff --git a/python3/vimspector/output.py b/python3/vimspector/output.py index 4599e04..5b6e32a 100644 --- a/python3/vimspector/output.py +++ b/python3/vimspector/output.py @@ -157,11 +157,13 @@ class OutputView( object ): def _CreateBuffer( self, category, file_name = None, cmd = None ): - if not self._window.valid: - return + win = self._window + if not win.valid: + # We need to borrow the current window + win = vim.current.window - with utils.LetCurrentWindow( self._window ): - with utils.RestoreCurrentBuffer( self._window ): + with utils.LetCurrentWindow( win ): + with utils.RestoreCurrentBuffer( win ): if file_name is not None: assert cmd is None diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index d4a7749..7cd9266 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -184,8 +184,10 @@ def RestoreCurrentWindow(): try: yield finally: - vim.current.tabpage = old_tabpage - vim.current.window = old_window + if old_tabpage.valid: + vim.current.tabpage = old_tabpage + if old_window.valid: + vim.current.window = old_window @contextlib.contextmanager @@ -194,9 +196,10 @@ def RestoreCurrentBuffer( window ): try: yield finally: - with RestoreCurrentWindow(): - vim.current.window = window - vim.current.buffer = old_buffer + if window.valid: + with RestoreCurrentWindow(): + vim.current.window = window + vim.current.buffer = old_buffer @contextlib.contextmanager diff --git a/tests/ui.test.vim b/tests/ui.test.vim index 07639e5..82667e2 100644 --- a/tests/ui.test.vim +++ b/tests/ui.test.vim @@ -286,6 +286,36 @@ function! Test_CloseOutput() %bwipe! endfunction +function! Test_CloseOutput_Early() + augroup TestCustomUI + au! + au User VimspectorUICreated + \ call win_execute( g:vimspector_session_windows.output, 'q' ) + augroup END + + call s:StartDebugging() + + call vimspector#StepOver() + call vimspector#test#signs#AssertCursorIsAtLineInBuffer( s:fn, 25, 1 ) + + call assert_equal( + \ [ 'row', [ + \ [ 'col', [ + \ [ 'leaf', g:vimspector_session_windows.variables ], + \ [ 'leaf', g:vimspector_session_windows.watches ], + \ [ 'leaf', g:vimspector_session_windows.stack_trace ], + \ ] ], + \ [ 'leaf', g:vimspector_session_windows.code ], + \ [ 'leaf', g:vimspector_session_windows.terminal ], + \ ] ], + \ winlayout( g:vimspector_session_windows.tabpage ) ) + + au! TestCustomUI + call vimspector#test#setup#Reset() + %bwipe! +endfunction + + function! Test_CustomUI() augroup TestCustomUI au!