File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -92,9 +92,7 @@ def __str__(self):
9292
9393 @property
9494 def lines (self ):
95- # An empty document is much nicer to deal with assuming it has a single
96- # line with no characters and no final newline.
97- return self .source .splitlines (True ) or [u'' ]
95+ return self .source .splitlines (True )
9896
9997 @property
10098 def source (self ):
@@ -118,7 +116,13 @@ def apply_change(self, change):
118116 end_line = change_range ['end' ]['line' ]
119117 end_col = change_range ['end' ]['character' ]
120118
119+ # Check for an edit occuring at the very end of the file
120+ if start_line == len (self .lines ):
121+ self ._source = self .source + text
122+ return
123+
121124 new = io .StringIO ()
125+
122126 # Iterate over the existing document until we hit the edit range,
123127 # at which point we write the new text, then loop until we hit
124128 # the end of the range and continue writing.
Original file line number Diff line number Diff line change @@ -77,3 +77,20 @@ def test_document_multiline_edit():
7777 "def hello(a, b):\n " ,
7878 " print a, b\n "
7979 ]
80+
81+
82+ def test_document_end_of_file_edit ():
83+ old = [
84+ "print 'a'\n " ,
85+ "print 'b'\n "
86+ ]
87+ doc = Document ('file:///uri' , u'' .join (old ))
88+ doc .apply_change ({'text' : u'o' , 'range' : {
89+ 'start' : {'line' : 2 , 'character' : 0 },
90+ 'end' : {'line' : 2 , 'character' : 0 }
91+ }})
92+ assert doc .lines == [
93+ "print 'a'\n " ,
94+ "print 'b'\n " ,
95+ "o" ,
96+ ]
You can’t perform that action at this time.
0 commit comments