Skip to content

Commit

Permalink
Don't allow large levels to wrap around multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Mar 16, 2024
1 parent b9784d2 commit 92fbf32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/drawlevel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2615,7 +2615,7 @@ proc drawSelection(ctx) =

# }}}
# {{{ drawSelectionHighlight()
proc drawSelectionHighlight(ctx) =
proc drawSelectionHighlight(levelRows, levelCols: Natural; ctx) =
alias(dp, ctx.dp)
alias(lt, ctx.lt)

Expand All @@ -2634,9 +2634,14 @@ proc drawSelectionHighlight(ctx) =
for c in 0..<cols:
if sel[r,c] and (viewSelStartRow + r >= 0 and
viewSelStartCol + c >= 0):
# Don't allow large levels to wrap around multiple times
if r >= levelRows or c >= levelCols:
continue

let
wrapCol = (viewSelStartCol + c).floorMod(dp.viewCols)
wrapRow = (viewSelStartRow + r).floorMod(dp.viewRows)
wrapRow = (viewSelStartRow + r).floorMod(levelRows)
wrapCol = (viewSelStartCol + c).floorMod(levelCols)

x = cellX(wrapCol, dp)
y = cellY(wrapRow, dp)

Expand Down Expand Up @@ -2785,7 +2790,7 @@ proc drawLevel*(map: Map, level: Natural; ctx) =
drawLabels(viewBuf, ctx)

if dp.selection.isSome: drawSelection(ctx)
if drawSelectionBuffer: drawSelectionHighlight(ctx)
if drawSelectionBuffer: drawSelectionHighlight(l.rows, l.cols, ctx)
if dp.drawCursorGuides: drawCursorGuides(ctx)

setLevelClippingRect(l, ctx)
Expand Down
4 changes: 4 additions & 0 deletions src/level.nim
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ proc pasteWithWraparound*(l; destRow, destCol: int, srcLevel: Level,
for srcRow in 0..<srcLevel.rows:
for srcCol in 0..<srcLevel.cols:
if sel[srcRow, srcCol]:
# Don't allow large levels to wrap around multiple times
if srcRow >= levelRows or srcCol >= levelCols:
continue

let
wrappedRow = (selStartRow + srcRow).floorMod(levelRows)
wrappedCol = (selStartCol + srcCol).floorMod(levelCols)
Expand Down

0 comments on commit 92fbf32

Please sign in to comment.