Fix browsing history

This commit is contained in:
David Rowe 2020-09-06 21:00:45 +12:00
parent 7da2fa1315
commit 1d27c0138c

View file

@ -165,22 +165,32 @@ ScrollingWindow {
focus: true focus: true
colorScheme: hifi.colorSchemes.dark colorScheme: hifi.colorSchemes.dark
placeholderText: "Enter URL" placeholderText: "Enter URL"
inputMethodHints: Qt.ImhUrlCharactersOnly
Component.onCompleted: ScriptDiscoveryService.scriptsModelFilter.filterRegExp = new RegExp("^.*$", "i") Component.onCompleted: ScriptDiscoveryService.scriptsModelFilter.filterRegExp = new RegExp("^.*$", "i")
Keys.onPressed: { Keys.onPressed: {
switch(event.key) { switch(event.key) {
case Qt.Key_Enter: case Qt.Key_Enter:
case Qt.Key_Return: case Qt.Key_Return:
event.accepted = true event.accepted = true
if (text.indexOf("http") != 0) { if (text.indexOf("http") !== 0) {
text = "http://" + text; text = "http://" + text;
} }
// Setting webiew.url directly doesn't add the URL to the navigation history.
//webview.url = text;
// The following works around this bug.
text = encodeURI(text);
text = text.replace(/;/g, "%3b"); // Prevent script injection.
text = text.replace(/'/g, "%25"); // ""
webview.runJavaScript("window.location='" + text + "'");
root.hidePermissionsBar(); root.hidePermissionsBar();
root.keyboardRaised = false; root.keyboardRaised = false;
webview.url = text;
break; break;
} }
} }
} }
} }
Rectangle { Rectangle {
@ -257,7 +267,7 @@ ScrollingWindow {
Keys.onPressed: { Keys.onPressed: {
switch(event.key) { switch(event.key) {
case Qt.Key_L: case Qt.Key_L:
if (event.modifiers == Qt.ControlModifier) { if (event.modifiers === Qt.ControlModifier) {
event.accepted = true event.accepted = true
addressBar.selectAll() addressBar.selectAll()
addressBar.forceActiveFocus() addressBar.forceActiveFocus()
@ -265,4 +275,5 @@ ScrollingWindow {
break; break;
} }
} }
} // dialog } // dialog