File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,16 @@ public static ITextSnapshotLine GetStartLine(this SnapshotSpan span)
4141 /// </summary>
4242 public static ITextSnapshotLine GetLastLine ( this SnapshotSpan span )
4343 {
44+ var snapshot = span . Snapshot ;
45+ var snapshotEndPoint = new SnapshotPoint ( snapshot , snapshot . Length ) ;
46+ if ( snapshotEndPoint == span . End )
47+ {
48+ var line = span . End . GetContainingLine ( ) ;
49+ if ( line . Length == 0 )
50+ {
51+ return line ;
52+ }
53+ }
4454 return span . Length > 0
4555 ? span . End . Subtract ( 1 ) . GetContainingLine ( )
4656 : GetStartLine ( span ) ;
Original file line number Diff line number Diff line change 1- using System . Collections . Generic ;
2- using System . Linq ;
3- using Microsoft . VisualStudio . Text . Projection ;
1+ using System . Linq ;
42using Microsoft . VisualStudio . Utilities ;
53using Xunit ;
64
@@ -80,5 +78,26 @@ public void TryGetPropertySafe_WrongType()
8078 string value ;
8179 Assert . False ( col . TryGetPropertySafe ( key , out value ) ) ;
8280 }
81+
82+ [ Fact ]
83+ public void GetLastLine_WithNonEmptyLastLine_ReturnsCorrectLastLine ( )
84+ {
85+ var textBuffer = CreateTextBuffer ( "hello" , "World" , "Foo" ) ;
86+ var lastLine = textBuffer . GetSpan ( 0 , textBuffer . CurrentSnapshot . Length ) . GetLastLine ( ) ;
87+
88+ Assert . True ( lastLine . LineNumber == 2 ) ;
89+ }
90+
91+ [ Fact ]
92+ public void GetLastLine_WithEmptyLastLine_ReturnsCorrectLastLine ( )
93+ {
94+ var textBuffer = CreateTextBuffer ( "hello" , "World" , "" ) ;
95+ var lastLine = textBuffer . GetSpan ( 0 , textBuffer . CurrentSnapshot . Length ) . GetLastLine ( ) ;
96+
97+ Assert . True ( lastLine . LineNumber == 2 ) ;
98+ }
99+
100+
101+
83102 }
84103}
You can’t perform that action at this time.
0 commit comments