Fix not responding next/previous when focus in webview
For some reason in the latest Qt versions the webview took over the focus from the keyboard, once clicked on the webview the arrow keys wouldn't register up and thus you couldn't navigate with them anymore. This patch fixes this problem by using window.location.href and checkinf for those special urls. This is way easier to use than WebChannels.
This commit is contained in:
parent
f025ad4d2a
commit
13c241f3b9
3 changed files with 27 additions and 2 deletions
|
@ -71,3 +71,15 @@ function setNightmode(nightmode) {
|
|||
if(nightmode) document.body.className = "nightmode";
|
||||
else document.body.className = "";
|
||||
}
|
||||
|
||||
document.onkeydown = checkKey;
|
||||
|
||||
function checkKey(e) {
|
||||
e = e || window.event;
|
||||
if (e.keyCode == '37') {
|
||||
window.location.href = "feedthemonkey:previous";
|
||||
}
|
||||
else if (e.keyCode == '39') {
|
||||
window.location.href = "feedthemonkey:next";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,9 +85,14 @@ Item {
|
|||
webView.runJavaScript("if(typeof setNightmode == \"function\") setNightmode(" + (content.nightmode ? "true" : "false") + ")")
|
||||
}
|
||||
|
||||
|
||||
onNavigationRequested: {
|
||||
if (request.navigationType != WebEngineView.LinkClickedNavigation) {
|
||||
if (request.url == "feedthemonkey:previous") {
|
||||
request.action = WebEngineView.IgnoreRequest;
|
||||
app.showPreviousPost();
|
||||
} else if (request.url == "feedthemonkey:next") {
|
||||
request.action = WebEngineView.IgnoreRequest;
|
||||
app.showNextPost();
|
||||
} else if (request.navigationType != WebEngineView.LinkClickedNavigation) {
|
||||
request.action = WebEngineView.AcceptRequest;
|
||||
} else {
|
||||
request.action = WebEngineView.IgnoreRequest;
|
||||
|
|
|
@ -114,6 +114,14 @@ ApplicationWindow {
|
|||
return forEscapingHTML.getText(0, forEscapingHTML.length)
|
||||
}
|
||||
|
||||
function showNextPost() {
|
||||
sidebar.next()
|
||||
}
|
||||
|
||||
function showPreviousPost() {
|
||||
sidebar.previous()
|
||||
}
|
||||
|
||||
function keyPressed(event) {
|
||||
switch (event.key) {
|
||||
case Qt.Key_Right:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue