Skip to content

Commit 9005f7c

Browse files
author
Kapil Borle
committed
Add a range validator public method to EditableText class
1 parent 10742f9 commit 9005f7c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Engine/EditableText.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public EditableText ApplyEdit(TextEdit textEdit)
106106

107107
// TODO Add a method that takes multiple edits, checks if they are unique and applies them.
108108

109+
public bool IsValidRange(Range range)
110+
{
111+
return range.Start.Line <= Lines.Length
112+
&& range.End.Line <= Lines.Length
113+
&& range.Start.Column <= Lines[range.Start.Line - 1].Length
114+
&& range.End.Column <= Lines[range.End.Line - 1].Length + 1;
115+
}
116+
109117
public override string ToString()
110118
{
111119
return Text;
@@ -123,10 +131,7 @@ private void ValidateTextEdit(TextEdit textEdit)
123131

124132
private void ValidateTextEditExtent(TextEdit textEdit)
125133
{
126-
if (textEdit.StartLineNumber > Lines.Length
127-
|| textEdit.EndLineNumber > Lines.Length
128-
|| textEdit.StartColumnNumber > Lines[textEdit.StartLineNumber - 1].Length
129-
|| textEdit.EndColumnNumber > Lines[textEdit.EndLineNumber - 1].Length + 1)
134+
if (IsValidRange(textEdit))
130135
{
131136
throw new ArgumentException(String.Format(
132137
CultureInfo.CurrentCulture,

0 commit comments

Comments
 (0)