Skip to content

Commit 36dac88

Browse files
committed
Fix some crashes in diff and wrap map
1 parent b4c783e commit 36dac88

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/text/diff_map.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ proc `$`*(self: DiffMapSnapshot): string =
152152
inc i
153153

154154
proc toDiffPoint*(self: DiffMapChunkCursor, point: InputPoint): DiffPoint =
155+
if not (point.row in self.startPos.src...self.endPos.src):
156+
return self.startPos.dst.diffPoint
155157
assert point.row in self.startPos.src...self.endPos.src
156158
# if self.startPos.dst == self.endPos.dst:
157159
# return diffPoint(self.startPos.dst)

src/text/wrap_map.nim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,17 +678,20 @@ proc next*(self: var WrapChunkIterator): Option[WrapChunk] =
678678
dst: self.wrapMapCursor.startPos.dst...self.wrapMapCursor.endPos.dst)
679679

680680
if currentChunk.endOutputPoint <= map.src.b:
681-
self.localOffset = currentChunk.len
681+
self.localOffset = max(currentChunk.len, 0)
682+
if self.localOffset < startOffset:
683+
self.wrapChunk = WrapChunk(inputChunk: currentChunk, wrapPoint: self.wrapPoint).some
684+
return self.wrapChunk
682685
assert self.localOffset >= 0
683686
var newChunk = currentChunk.split(startOffset).suffix.split(self.localOffset - startOffset).prefix
684687
newChunk.outputPoint = currentInputPoint
685688
self.wrapChunk = WrapChunk(inputChunk: newChunk, wrapPoint: self.wrapPoint).some
686689

687690
else:
688-
self.localOffset = map.src.b.column.int - currentChunk.outputPoint.column.int
689-
if self.localOffset < 0:
691+
self.localOffset = max(map.src.b.column.int - currentChunk.outputPoint.column.int, 0)
692+
if self.localOffset < startOffset:
690693
self.wrapChunk = WrapChunk(inputChunk: currentChunk, wrapPoint: self.wrapPoint).some
691-
return
694+
return self.wrapChunk
692695

693696
assert self.localOffset >= 0
694697
var newChunk = currentChunk.split(startOffset).suffix.split(self.localOffset - startOffset).prefix

0 commit comments

Comments
 (0)