mirror of
https://github.com/qvacua/vimr.git
synced 2024-10-28 03:38:54 +03:00
Guard against invalid positions
This commit is contained in:
parent
292e2be410
commit
01cbb584be
@ -198,6 +198,10 @@ class Grid: CustomStringConvertible {
|
||||
}
|
||||
|
||||
func isCellEmpty(position: Position) -> Bool {
|
||||
guard self.isSane(position: position) else {
|
||||
return false
|
||||
}
|
||||
|
||||
if self.cells[position.row][position.column].string.characters.count == 0 {
|
||||
return true
|
||||
}
|
||||
@ -241,4 +245,12 @@ class Grid: CustomStringConvertible {
|
||||
self.cells[i].replaceRange(region.left...region.right, with: clearedRow)
|
||||
}
|
||||
}
|
||||
|
||||
private func isSane(position position: Position) -> Bool {
|
||||
guard position.row < self.size.height && position.column < self.size.width else {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user