add snap when finishing search
This commit is contained in:
parent
6f4a95eb46
commit
1f2a14c5f3
1 changed files with 22 additions and 2 deletions
24
app/UI.hs
24
app/UI.hs
|
|
@ -201,14 +201,14 @@ wireEvents ctx = do
|
|||
case keyval of
|
||||
Gdk.KEY_Down -> WebKit.findControllerSearchNext fc >> pure True
|
||||
Gdk.KEY_Up -> WebKit.findControllerSearchPrevious fc >> pure True
|
||||
Gdk.KEY_Escape -> Gtk.setEditableText entry "" >> WebKit.findControllerSearchFinish fc >> Gtk.widgetGrabFocus (appWebView (ctxWidgets ctx)) >> pure True
|
||||
Gdk.KEY_Escape -> Gtk.setEditableText entry "" >> WebKit.findControllerSearchFinish fc >> Gtk.widgetGrabFocus (appWebView (ctxWidgets ctx)) >> snapPagination ctx >> pure True
|
||||
_ -> pure False
|
||||
Gtk.widgetAddController entry searchKeys
|
||||
|
||||
_ <- on entry #searchChanged $ do
|
||||
q <- Gtk.editableGetText entry
|
||||
if T.null q
|
||||
then WebKit.findControllerSearchFinish fc
|
||||
then WebKit.findControllerSearchFinish fc >> snapPagination ctx
|
||||
else WebKit.findControllerSearch fc q findOpts maxBound
|
||||
let runfwd = runSearch ctx nextMatch
|
||||
_ <- on entry #activate $ runfwd -- pressing enter while having search text
|
||||
|
|
@ -525,6 +525,26 @@ wrapHtml (Html body) start mode =
|
|||
let safe = T.filter (\c -> c /= '"' && c /= '\\') f
|
||||
in "<script>var el=document.getElementById(\"" <> safe <> "\");if(el)goToPage(Math.floor(el.offsetLeft/window.innerWidth));</script>"
|
||||
|
||||
|
||||
-- | Re-align the paginated view after an in-page find. WebKit reveals a match
|
||||
-- by scrolling the (multi-column) layout, which leaves the transform-based
|
||||
-- pager out of sync so several half-pages show at once once the search ends.
|
||||
-- Reset the scroll offset back to zero and re-apply the current page transform.
|
||||
-- No-op in scrolling mode, which scrolls natively and needs no fix-up.
|
||||
snapPagination :: Ctx -> IO ()
|
||||
snapPagination ctx = do
|
||||
mode <- getMode ctx
|
||||
when (mode == Paginated) $
|
||||
evalJSBool
|
||||
(appWebView (ctxWidgets ctx))
|
||||
( T.concat
|
||||
[ "var d=document.documentElement,b=document.body;",
|
||||
"d.scrollLeft=0;d.scrollTop=0;if(b){b.scrollLeft=0;b.scrollTop=0;}",
|
||||
"window.scrollTo(0,0);if(typeof apply==='function'){apply();}true"
|
||||
]
|
||||
)
|
||||
(\_ -> pure ())
|
||||
|
||||
evalJSBool :: WebKit.WebView -> T.Text -> (Bool -> IO ()) -> IO ()
|
||||
evalJSBool wv src k =
|
||||
WebKit.webViewEvaluateJavascript wv src (-1) Nothing Nothing (Nothing :: Maybe Gio.Cancellable)
|
||||
|
|
|
|||
Loading…
Reference in a new issue