From 08581f50c34faa72921cdd19358712edd85e088a Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Mon, 5 Oct 2020 21:45:01 +0900 Subject: [PATCH] fix: crash in rare unknown scenario scenario --- src/ui/main-window/ThumbnailsView.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ui/main-window/ThumbnailsView.swift b/src/ui/main-window/ThumbnailsView.swift index bd28b44c..a288475b 100644 --- a/src/ui/main-window/ThumbnailsView.swift +++ b/src/ui/main-window/ThumbnailsView.swift @@ -18,15 +18,17 @@ class ThumbnailsView: NSVisualEffectView { func nextRow(_ direction: Direction) -> [ThumbnailView]? { let step = direction == .down ? 1 : -1 - let currentRow = Windows.focusedWindow()!.row! - let nextRow = (currentRow + step) % rows.count - let nextRow_ = nextRow < 0 ? rows.count + nextRow : nextRow - if ((step > 0 && nextRow_ < currentRow) || (step < 0 && nextRow_ > currentRow)) && - (KeyRepeatTimer.isARepeat || KeyRepeatTimer.timer?.isValid ?? false) { - KeyRepeatTimer.timer?.invalidate() - return nil + if let currentRow = Windows.focusedWindow()?.row { + let nextRow = (currentRow + step) % rows.count + let nextRow_ = nextRow < 0 ? rows.count + nextRow : nextRow + if ((step > 0 && nextRow_ < currentRow) || (step < 0 && nextRow_ > currentRow)) && + (KeyRepeatTimer.isARepeat || KeyRepeatTimer.timer?.isValid ?? false) { + KeyRepeatTimer.timer?.invalidate() + return nil + } + return rows[nextRow_] } - return rows[nextRow_] + return nil } func navigateUpOrDown(_ direction: Direction) {