forked from marko/svitak
safe indexing
This commit is contained in:
parent
d65a483878
commit
be79979183
1 changed files with 4 additions and 1 deletions
|
|
@ -32,6 +32,7 @@ updateUI window webView view = do
|
|||
handleAction :: TVar AppState -> Gtk.ApplicationWindow -> WebKit.WebView -> UserAction -> IO ()
|
||||
handleAction stateTVar window webView action = do
|
||||
st <- atomically $ readTVar stateTVar
|
||||
let totalChapters = length (cAllChapters st)
|
||||
case action of
|
||||
ZoomIn -> updateZoom stateTVar webView (zoomlvl st + 0.1)
|
||||
ZoomOut -> updateZoom stateTVar webView (max 0.1 (zoomlvl st - 0.1))
|
||||
|
|
@ -42,7 +43,9 @@ handleAction stateTVar window webView action = do
|
|||
LoadSpecific i -> i
|
||||
_ -> cIdx st
|
||||
|
||||
case prepareView st nextIdx of
|
||||
let safeIdx = max 0 (min (totalChapters -1 ) nextIdx)
|
||||
|
||||
case prepareView st safeIdx of
|
||||
Nothing -> pure ()
|
||||
Just view -> do
|
||||
updateUI window webView view
|
||||
|
|
|
|||
Loading…
Reference in a new issue