Skip to content

Commit 5e31f89

Browse files
committed
Fix #4305
1 parent 4f8ea19 commit 5e31f89

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

python/ycm/tests/vimsupport_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,16 @@ def test_ReplaceChunk_BeyondEndOfFile( self ):
667667
AssertBuffersAreEqualAsBytes( [ 'first line' ], result_buffer )
668668

669669

670+
@patch( 'vim.current.window.cursor', ( 1, 1 ) )
671+
def test_ReplaceChunk_AtOneLinePastEndOfFile( self ):
672+
result_buffer = VimBuffer( 'buffer', contents = [ 'first line' ] )
673+
start, end = _BuildLocations( 2, 1, 2, 1 )
674+
vimsupport.ReplaceChunk( start, end, 'second line', result_buffer )
675+
676+
AssertBuffersAreEqualAsBytes( [ 'first line', 'second line' ],
677+
result_buffer )
678+
679+
670680
@patch( 'vim.current.window.cursor', ( 1, 3 ) )
671681
def test_ReplaceChunk_CursorPosition( self ):
672682
result_buffer = VimBuffer( 'buffer', contents = [ 'bar' ] )

python/ycm/vimsupport.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,10 @@ def ReplaceChunk( start, end, replacement_text, vim_buffer ):
11401140
# so we convert to bytes
11411141
replacement_lines = SplitLines( ToBytes( replacement_text ) )
11421142

1143+
if start_line >= len( vim_buffer ):
1144+
start_line -= 1
1145+
replacement_lines = [ ToBytes( vim_buffer[ -1 ] ) ] + replacement_lines
1146+
11431147
# NOTE: Vim buffers are a list of unicode objects on Python 3.
11441148
start_existing_text = ToBytes( vim_buffer[ start_line ] )[ : start_column ]
11451149
end_line_text = ToBytes( vim_buffer[ end_line ] )

0 commit comments

Comments
 (0)