Skip to content

Commit 4c7491a

Browse files
committed
find_marker_or_segment: fix for unhandled case of RangeSpec.EMPTY (needs to be transformed into an absolute range)
1 parent 0ac457e commit 4c7491a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/cedarscript_editor/cedarscript_editor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ def find_marker_or_segment(
289289
# TODO Handle segment's start and end as a marker and support identifier markers
290290
search_range = segment.to_search_range(lines, search_range)
291291
marker = None
292+
case BodyOrWhole():
293+
if search_range.end == -1:
294+
search_range = search_range._replace(end=len(lines))
295+
292296
return marker, search_range
293297

294298

src/text_manipulation/range_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def read(self, src: Sequence[str]) -> Sequence[str]:
9191

9292
def write(self, src: Sequence[str], target: Sequence[str]):
9393
"""Write the source lines into the target sequence at the index position specified by this range."""
94-
target[self.start:self.end] = src
94+
target[self.start:self.end if self.end >= 0 else len(target)] = src
9595

9696
def delete(self, src: Sequence[str]) -> Sequence[str]:
9797
"""Delete the lines specified by this range from the source sequence and return the deleted lines."""

0 commit comments

Comments
 (0)