Add up/down history browsing to DebugConsole

This commit is contained in:
miruka 2019-09-19 18:26:52 -04:00
parent 7b482de727
commit c1a27328d9
2 changed files with 27 additions and 5 deletions

View File

@ -46,6 +46,7 @@
- When qml syntax highlighting supports ES6 string interpolation, use that - When qml syntax highlighting supports ES6 string interpolation, use that
- Fixes - Fixes
- Remove usage of `splice()`
- Event delegates changing height don't scroll the list - Event delegates changing height don't scroll the list
- When selecting text and scrolling up, selection stops working after a while - When selecting text and scrolling up, selection stops working after a while
- Ensure all the text that should be copied is copied - Ensure all the text that should be copied is copied

View File

@ -16,9 +16,12 @@ Window {
property var target: null property var target: null
property alias t: debugConsole.target property alias t: debugConsole.target
property var history: []
property alias his: debugConsole.history
property int historyEntry: -1
Component.onCompleted: { Component.onCompleted: {
print(parent)
mainUI.shortcuts.debugConsole = debugConsole mainUI.shortcuts.debugConsole = debugConsole
commandsView.model.insert(0, { commandsView.model.insert(0, {
input: "target = " + String(target), input: "target = " + String(target),
@ -28,14 +31,26 @@ Window {
visible = true visible = true
} }
onHistoryEntryChanged:
inputField.text =
historyEntry === -1 ? "" : history.slice(-historyEntry - 1)[0]
function runJS(input) { function runJS(input) {
if (history.slice(-1)[0] !== input) history.push(input)
let error = false let error = false
try { try {
var output = input.startsWith("j ") ? if (input.startsWith("j ")) {
JSON.stringify(eval(input.substring(2)), null, 4) : var output = JSON.stringify(eval(input.substring(2)), null, 4)
String(eval(input))
} else {
let result = eval(input)
var output = result instanceof Array ?
"[" + String(result) + "]" : String(result)
}
} catch (err) { } catch (err) {
error = true error = true
var output = err.toString() var output = err.toString()
@ -99,13 +114,19 @@ Window {
} }
HTextField { HTextField {
id: inputField
focus: true focus: true
onAccepted: if (text) runJS(text) onAccepted: if (text) { runJS(text); text = "" }
backgroundColor: Qt.hsla(0, 0, 0, 0.85) backgroundColor: Qt.hsla(0, 0, 0, 0.85)
bordered: false bordered: false
placeholderText: qsTr("Type some JavaScript...") placeholderText: qsTr("Type some JavaScript...")
font.family: theme.fontFamily.mono font.family: theme.fontFamily.mono
Keys.onUpPressed:
if (historyEntry + 1 < history.length ) historyEntry += 1
Keys.onDownPressed:
if (historyEntry - 1 >= -1) historyEntry -= 1
Layout.fillWidth: true Layout.fillWidth: true
} }