Skip to content

Commit ed42d0e

Browse files
committed
Simplified code and added explaining comments.
1 parent e463c04 commit ed42d0e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

PSReadLine/StringBuilderLinewiseExtensions.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,24 @@ internal static Range GetRange(this StringBuilder buffer, int lineIndex, int lin
8282
/// <returns></returns>
8383
public static bool IsLogigalLineEmpty(this StringBuilder buffer, int cursor)
8484
{
85+
// the cursor is on a logical line considered empty if...
86+
8587
return
88+
89+
// the entire buffer is empty (by definition), or
90+
8691
buffer.Length == 0 ||
92+
93+
// the cursor sits at the start of the empty last line,
94+
// meaning that it is past the end of the buffer and the
95+
// last character in the buffer is a newline character, or
96+
8797
(cursor == buffer.Length && buffer[cursor - 1] == '\n') ||
88-
(cursor > 0 && buffer[cursor] == '\n') ||
89-
(cursor > 0 && buffer[cursor] == '\n' && cursor < buffer.Length - 1 && buffer[cursor - 1] == '\n')
98+
99+
// if the cursor is on a newline character, or
100+
101+
(cursor > 0 && buffer[cursor] == '\n')
102+
90103
;
91104
}
92105
}

0 commit comments

Comments
 (0)