cessen / ropey

A utf8 text rope for manipulating and editing large texts.
MIT License
1.04k stars 46 forks source link

Fix Line Iterator creation for empty Rope #77

Closed pascalkuthe closed 1 year ago

pascalkuthe commented 1 year ago

Fixes #76.

In #70 I introduced a small oversight in the edge case of an empty Rope. I initialized the Lines iterator with total_lines = 0. However, the Lines iterator always yields atleast a single line (even if that line is empty) which caused the subsequent underflow. This PR fixes that by setting total_lines = 1 in the appropriate edge case. I also added a test case to make sure this doesn't regress in the future.

cessen commented 1 year ago

Looks good to me! Thanks!