Set window height according to the wrap option

This commit is contained in:
micbou 2018-08-29 21:39:31 +02:00
parent e018777b38
commit b6583623a0
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05
3 changed files with 30 additions and 8 deletions

View File

@ -466,6 +466,7 @@ class VimWindow( object ):
self.number = number self.number = number
self.buffer = buffer_object self.buffer = buffer_object
self.cursor = cursor self.cursor = cursor
self.options = {}
class VimWindows( object ): class VimWindows( object ):

View File

@ -173,13 +173,26 @@ def OpenLocationList_test( vim_command, fitting_height, variable_exists ):
variable_exists.assert_called_once_with( '#User#YcmLocationOpened' ) variable_exists.assert_called_once_with( '#User#YcmLocationOpened' )
@patch( 'ycm.vimsupport.GetIntValue', return_value = 120 )
@patch( 'vim.command' ) @patch( 'vim.command' )
def SetFittingHeightForCurrentWindow_test( vim_command, *args ): def SetFittingHeightForCurrentWindow_LineWrapOn_test( vim_command, *args ):
# Create a buffer with one line that is longer than the window width. # Create a two lines buffer whose first line is longer than the window width.
current_buffer = VimBuffer( 'buffer', current_buffer = VimBuffer( 'buffer',
contents = [ 'a' * 140 ] ) contents = [ 'a' * 140, 'b' * 80 ] )
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ): with MockVimBuffers( [ current_buffer ], [ current_buffer ] ) as vim:
vim.current.window.width = 120
vim.current.window.options[ 'wrap' ] = True
vimsupport.SetFittingHeightForCurrentWindow()
vim_command.assert_called_once_with( '3wincmd _' )
@patch( 'vim.command' )
def SetFittingHeightForCurrentWindow_LineWrapOff_test( vim_command, *args ):
# Create a two lines buffer whose first line is longer than the window width.
current_buffer = VimBuffer( 'buffer',
contents = [ 'a' * 140, 'b' * 80 ] )
with MockVimBuffers( [ current_buffer ], [ current_buffer ] ) as vim:
vim.current.window.width = 120
vim.current.window.options[ 'wrap' ] = False
vimsupport.SetFittingHeightForCurrentWindow() vimsupport.SetFittingHeightForCurrentWindow()
vim_command.assert_called_once_with( '2wincmd _' ) vim_command.assert_called_once_with( '2wincmd _' )

View File

@ -364,12 +364,20 @@ def OpenQuickFixList( focus = False, autoclose = False ):
JumpToPreviousWindow() JumpToPreviousWindow()
def SetFittingHeightForCurrentWindow(): def ComputeFittingHeightForCurrentWindow():
window_width = GetIntValue( 'winwidth( 0 )' ) current_window = vim.current.window
if not current_window.options[ 'wrap' ]:
return len( vim.current.buffer )
window_width = current_window.width
fitting_height = 0 fitting_height = 0
for line in vim.current.buffer: for line in vim.current.buffer:
fitting_height += len( line ) // window_width + 1 fitting_height += len( line ) // window_width + 1
vim.command( '{0}wincmd _'.format( fitting_height ) ) return fitting_height
def SetFittingHeightForCurrentWindow():
vim.command( '{0}wincmd _'.format( ComputeFittingHeightForCurrentWindow() ) )
def ConvertDiagnosticsToQfList( diagnostics ): def ConvertDiagnosticsToQfList( diagnostics ):