Skip to content

Commit bc483e7

Browse files
author
Kapil Borle
committed
Handle line addition to empty TextLines object
1 parent 4ed988b commit bc483e7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

Engine/TextLines.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,19 @@ public int IndexOf(string item)
159159
/// </summary>
160160
public void Insert(int index, string item)
161161
{
162-
ValidateIndex(index);
163162
ThrowIfNull(item, nameof(item));
164-
SetLastAccessed(index, lines.AddBefore(GetNodeAt(index), item));
163+
LinkedListNode<string> itemInserted;
164+
if (Count == 0 && index == 0)
165+
{
166+
itemInserted = lines.AddFirst(item);
167+
}
168+
else
169+
{
170+
ValidateIndex(index);
171+
itemInserted = lines.AddBefore(GetNodeAt(index), item);
172+
}
173+
174+
SetLastAccessed(index, itemInserted);
165175
Count++;
166176
}
167177

0 commit comments

Comments
 (0)