Don't change the value of equalalways

We were trying to avoid equalalways from changing the UI layout by
unsetting it and resetting it after changes. However, re-setting
equalalways actually resizes all the windows, so this never worked.

Instead we judiciously use rightbelow, leftabove, etc. and specify the
exact window sizes we want.

As a side-effect we make the terminal sizing a little more pleasant by
default, ensuring that it is no wider than 80 chars, and tries to use
any remianing vertical space after reserving 80 chars for the code
window.
This commit is contained in:
Ben Jackson 2020-07-16 15:25:28 +01:00
commit 7a9f75a06e
4 changed files with 49 additions and 40 deletions

View file

@ -48,7 +48,7 @@ endfunction
function! vimspector#internal#neoterm#Start( cmd, opts ) abort function! vimspector#internal#neoterm#Start( cmd, opts ) abort
" Prepare current buffer to be turned into a term if curwin is not set " Prepare current buffer to be turned into a term if curwin is not set
if ! get( a:opts, 'curwin', 0 ) if ! get( a:opts, 'curwin', 0 )
let mods = '' let mods = 'rightbelow '
if get( a:opts, 'vertical', 0 ) if get( a:opts, 'vertical', 0 )
let mods .= 'vertical ' let mods .= 'vertical '
let mods .= get( a:opts, 'term_cols', '' ) let mods .= get( a:opts, 'term_cols', '' )

View file

@ -20,7 +20,7 @@ set cpoptions&vim
" }}} " }}}
function! vimspector#internal#term#Start( cmd, opts ) abort function! vimspector#internal#term#Start( cmd, opts ) abort
return term_start( a:cmd, a:opts ) rightbelow return term_start( a:cmd, a:opts )
endfunction endfunction
function! vimspector#internal#term#IsFinished( bufno ) abort function! vimspector#internal#term#IsFinished( bufno ) abort

View file

@ -233,24 +233,33 @@ class CodeView( object ):
if self._terminal_window is not None and self._terminal_window.valid: if self._terminal_window is not None and self._terminal_window.valid:
assert self._terminal_buffer_number assert self._terminal_buffer_number
window_for_start = self._terminal_window
if ( self._terminal_window.buffer.number == self._terminal_buffer_number if ( self._terminal_window.buffer.number == self._terminal_buffer_number
and int( utils.Call( 'vimspector#internal#{}term#IsFinished'.format( and int( utils.Call( 'vimspector#internal#{}term#IsFinished'.format(
self._api_prefix ), self._api_prefix ),
self._terminal_buffer_number ) ) ): self._terminal_buffer_number ) ) ):
window_for_start = self._terminal_window
options[ 'curwin' ] = 1 options[ 'curwin' ] = 1
else:
options[ 'vertical' ] = 0
buffer_number = None buffer_number = None
terminal_window = None terminal_window = None
with utils.TemporaryVimOptions( { 'splitright': True, with utils.LetCurrentWindow( window_for_start ):
'equalalways': False } ): # If we're making a vertical split from the code window, make it no more
with utils.LetCurrentWindow( window_for_start ): # than 80 columns and no fewer than 10. Also try and keep the code window
buffer_number = int( # at least 82 columns
utils.Call( if options[ 'vertical' ] and not options.get( 'curwin', 0 ):
'vimspector#internal#{}term#Start'.format( self._api_prefix ), options[ 'term_cols' ] = max(
args, min ( int( vim.eval( 'winwidth( 0 ) - 82' ) ), 80 ),
options ) ) 10
terminal_window = vim.current.window )
buffer_number = int(
utils.Call(
'vimspector#internal#{}term#Start'.format( self._api_prefix ),
args,
options ) )
terminal_window = vim.current.window
if buffer_number is None or buffer_number <= 0: if buffer_number is None or buffer_number <= 0:
# TODO: Do something better like reject the request? # TODO: Do something better like reject the request?

View file

@ -487,39 +487,39 @@ class DebugSession( object ):
self._codeView = code.CodeView( code_window, self._api_prefix ) self._codeView = code.CodeView( code_window, self._api_prefix )
# Call stack # Call stack
with utils.TemporaryVimOptions( { 'splitright': False, vim.command( 'topleft vertical 50new' )
'equalalways': False, } ): stack_trace_window = vim.current.window
vim.command( 'topleft vertical 50new' ) one_third = int( vim.eval( 'winheight( 0 )' ) ) / 3
stack_trace_window = vim.current.window self._stackTraceView = stack_trace.StackTraceView( self,
self._stackTraceView = stack_trace.StackTraceView( self, self._connection,
self._connection, stack_trace_window )
stack_trace_window )
with utils.TemporaryVimOptions( { 'splitbelow': False, # Watches
'eadirection': 'ver', vim.command( 'leftabove new' )
'equalalways': True } ): watch_window = vim.current.window
# Watches
vim.command( 'new' )
watch_window = vim.current.window
# Variables # Variables
vim.command( 'new' ) vim.command( 'leftabove new' )
vars_window = vim.current.window vars_window = vim.current.window
self._variablesView = variables.VariablesView( self._connection, with utils.LetCurrentWindow( vars_window ):
vars_window, vim.command( f'{ one_third }wincmd _' )
watch_window ) with utils.LetCurrentWindow( watch_window ):
vim.command( f'{ one_third }wincmd _' )
with utils.LetCurrentWindow( stack_trace_window ):
vim.command( f'{ one_third }wincmd _' )
self._variablesView = variables.VariablesView( self._connection,
vars_window,
watch_window )
with utils.TemporaryVimOption( 'splitbelow', True ): # Output/logging
vim.current.window = code_window vim.current.window = code_window
vim.command( 'rightbelow 10new' )
# Output/logging output_window = vim.current.window
vim.command( '10new' ) self._outputView = output.OutputView( self._connection,
output_window = vim.current.window output_window,
self._outputView = output.OutputView( self._connection, self._api_prefix )
output_window,
self._api_prefix )
# TODO: If/when we support multiple sessions, we'll need some way to # TODO: If/when we support multiple sessions, we'll need some way to
# indicate which tab was created and store all the tabs # indicate which tab was created and store all the tabs