safe indexing

This commit is contained in:
Marko Andjelic 2026-02-09 03:31:09 +00:00
commit be79979183

View file

@ -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