fix tabpage errors

This commit is contained in:
Ben Jackson 2019-07-04 00:16:39 +01:00
commit cee10c8187
5 changed files with 97 additions and 29 deletions

View file

@ -35,18 +35,17 @@ class CodeView( object ):
'breakpoints': []
}
vim.current.window = self._window
with utils.LetCurrentWindow( self._window ):
vim.command( 'nnoremenu WinBar.Continue :call vimspector#Continue()<CR>' )
vim.command( 'nnoremenu WinBar.Next :call vimspector#StepOver()<CR>' )
vim.command( 'nnoremenu WinBar.Step :call vimspector#StepInto()<CR>' )
vim.command( 'nnoremenu WinBar.Finish :call vimspector#StepOut()<CR>' )
vim.command( 'nnoremenu WinBar.Pause :call vimspector#Pause()<CR>' )
vim.command( 'nnoremenu WinBar.Stop :call vimspector#Stop()<CR>' )
vim.command( 'nnoremenu WinBar.Restart :call vimspector#Restart()<CR>' )
vim.command( 'nnoremenu WinBar.Reset :call vimspector#Reset()<CR>' )
vim.command( 'nnoremenu WinBar.Continue :call vimspector#Continue()<CR>' )
vim.command( 'nnoremenu WinBar.Next :call vimspector#StepOver()<CR>' )
vim.command( 'nnoremenu WinBar.Step :call vimspector#StepInto()<CR>' )
vim.command( 'nnoremenu WinBar.Finish :call vimspector#StepOut()<CR>' )
vim.command( 'nnoremenu WinBar.Pause :call vimspector#Pause()<CR>' )
vim.command( 'nnoremenu WinBar.Stop :call vimspector#Stop()<CR>' )
vim.command( 'nnoremenu WinBar.Restart :call vimspector#Restart()<CR>' )
vim.command( 'nnoremenu WinBar.Reset :call vimspector#Reset()<CR>' )
vim.command( 'sign define vimspectorPC text=-> texthl=Search' )
vim.command( 'sign define vimspectorPC text=-> texthl=Search' )
def SetCurrentFrame( self, frame ):
@ -61,7 +60,7 @@ class CodeView( object ):
if 'path' not in frame[ 'source' ]:
return False
vim.current.window = self._window
utils.JumpToWindow( self._window )
try:
utils.OpenFileInCurrentWindow( frame[ 'source' ][ 'path' ] )
@ -210,8 +209,7 @@ class CodeView( object ):
buffer_number = None
with utils.TemporaryVimOptions( { 'splitright': True,
'equalalways': False } ):
with utils.RestoreCurrentWindow():
vim.current.window = self._window
with utils.LetCurrentWindow( self._window ):
# TODO/FIXME: Do something about closing this when we reset ?
vim_cmd = 'term_start( {}, {} )'.format( json.dumps( args ),
json.dumps( options ) )

View file

@ -106,7 +106,7 @@ class OutputView( object ):
self._buffers.clear()
def _ShowOutput( self, category ):
vim.current.window = self._window
utils.JumpToWindow( self._window )
vim.command( 'bu {0}'.format( self._buffers[ category ].buf.name ) )
vim.command( 'normal G' )
@ -144,8 +144,7 @@ class OutputView( object ):
def _ToggleFlag( self, category, flag ):
if self._buffers[ category ].flag != flag:
self._buffers[ category ].flag = flag
with utils.RestoreCurrentWindow():
vim.current.window = self._window
with utils.LetCurrentWindow( self._window ):
self._RenderWinBar( category )
@ -154,9 +153,7 @@ class OutputView( object ):
def _CreateBuffer( self, category, file_name = None, cmd = None ):
with utils.RestoreCurrentWindow():
vim.current.window = self._window
with utils.LetCurrentWindow( self._window ):
with utils.RestoreCurrentBuffer( self._window ):
if file_name is not None:

View file

@ -147,11 +147,13 @@ def RestoreCursorPosition():
@contextlib.contextmanager
def RestoreCurrentWindow():
# TODO: Don't trigger autoccommands when shifting windows
# TODO: Don't trigger autocommands when shifting windows
old_tabpage = vim.current.tabpage
old_window = vim.current.window
try:
yield
finally:
vim.current.tabpage = old_tabpage
vim.current.window = old_window
@ -167,6 +169,18 @@ def RestoreCurrentBuffer( window ):
vim.current.buffer = old_buffer
@contextlib.contextmanager
def LetCurrentWindow( window ):
with RestoreCurrentWindow():
JumpToWindow( window )
yield
def JumpToWindow( window ):
vim.current.tabpage = window.tabpage
vim.current.window = window
@contextlib.contextmanager
def TemporaryVimOptions( opts ):
old_value = {}

View file

@ -33,9 +33,9 @@ class VariablesView( object ):
self._connection = connection
# Allows us to hit <CR> to expand/collapse variables
vim.current.window = self._vars.win
vim.command(
'nnoremap <buffer> <CR> :call vimspector#ExpandVariable()<CR>' )
with utils.LetCurrentWindow( self._vars.win ):
vim.command(
'nnoremap <buffer> <CR> :call vimspector#ExpandVariable()<CR>' )
# This is actually the tree (scopes are alwyas the root)
# it's just a list of DAP scope dicts, with one magic key (_variables)
@ -52,11 +52,11 @@ class VariablesView( object ):
self._watches = []
# Allows us to hit <CR> to expand/collapse variables
vim.current.window = self._watch.win
vim.command(
'nnoremap <buffer> <CR> :call vimspector#ExpandVariable()<CR>' )
vim.command(
'nnoremap <buffer> <DEL> :call vimspector#DeleteWatch()<CR>' )
with utils.LetCurrentWindow( self._watch.win ):
vim.command(
'nnoremap <buffer> <CR> :call vimspector#ExpandVariable()<CR>' )
vim.command(
'nnoremap <buffer> <DEL> :call vimspector#DeleteWatch()<CR>' )
utils.SetUpScratchBuffer( self._vars.win.buffer, 'vimspector.Variables' )
utils.SetUpPromptBuffer( self._watch.win.buffer,