Launcher: improved/fixed keyboard controls (Ctrl+J / Ctrl+K)
This commit is contained in:
parent
97b016b21b
commit
7b26e38f33
1 changed files with 63 additions and 34 deletions
|
|
@ -170,6 +170,7 @@ NPanel {
|
|||
|
||||
function selectFirst() {
|
||||
selectedIndex = 0
|
||||
console.log("selectFirst")
|
||||
}
|
||||
|
||||
function selectLast() {
|
||||
|
|
@ -202,6 +203,42 @@ NPanel {
|
|||
}
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "Ctrl+K"
|
||||
onActivated: ui.selectPrevious()
|
||||
enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "Ctrl+J"
|
||||
onActivated: ui.selectNext()
|
||||
enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "PgDown" // or "PageDown"
|
||||
onActivated: ui.selectNextPage()
|
||||
enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "PgUp" // or "PageUp"
|
||||
onActivated: ui.selectPreviousPage()
|
||||
enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "Home"
|
||||
onActivated: ui.selectFirst()
|
||||
enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "End"
|
||||
onActivated: ui.selectLast()
|
||||
enabled: root.opened && searchInput.inputItem && searchInput.inputItem.activeFocus
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: Style.marginL * scaling
|
||||
|
|
@ -223,45 +260,37 @@ NPanel {
|
|||
text: searchText
|
||||
placeholderText: "Search entries... or use > for commands"
|
||||
|
||||
onTextChanged: searchText = text
|
||||
|
||||
Component.onCompleted: {
|
||||
if (searchInput.inputItem && searchInput.inputItem.visible) {
|
||||
searchInput.inputItem.forceActiveFocus()
|
||||
|
||||
// Override the TextField's default Home/End behavior
|
||||
searchInput.inputItem.Keys.priority = Keys.BeforeItem
|
||||
searchInput.inputItem.Keys.onPressed.connect(function (event) {
|
||||
// Intercept Home and End BEFORE the TextField handles them
|
||||
if (event.key === Qt.Key_Home) {
|
||||
ui.selectFirst()
|
||||
event.accepted = true
|
||||
return
|
||||
} else if (event.key === Qt.Key_End) {
|
||||
ui.selectLast()
|
||||
event.accepted = true
|
||||
return
|
||||
}
|
||||
})
|
||||
searchInput.inputItem.Keys.onDownPressed.connect(function (event) {
|
||||
ui.selectNext()
|
||||
})
|
||||
searchInput.inputItem.Keys.onUpPressed.connect(function (event) {
|
||||
ui.selectPrevious()
|
||||
})
|
||||
searchInput.inputItem.Keys.onReturnPressed.connect(function (event) {
|
||||
ui.activate()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onTextChanged: searchText = text
|
||||
Keys.onEscapePressed: root.close()
|
||||
Keys.onReturnPressed: ui.activate()
|
||||
Keys.onDownPressed: ui.selectNext()
|
||||
Keys.onUpPressed: ui.selectPrevious()
|
||||
Keys.onPressed: event => {
|
||||
if (event.key === Qt.Key_PageDown) {
|
||||
ui.selectNextPage()
|
||||
event.accepted = true
|
||||
} else if (event.key === Qt.Key_PageUp) {
|
||||
ui.selectPreviousPage()
|
||||
event.accepted = true
|
||||
} else if (event.key === Qt.Key_Home) {
|
||||
ui.selectFirst()
|
||||
event.accepted = true
|
||||
} else if (event.key === Qt.Key_End) {
|
||||
ui.selectLast()
|
||||
event.accepted = true
|
||||
}
|
||||
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
switch (event.key) {
|
||||
case Qt.Key_K:
|
||||
ui.selectPrevious()
|
||||
event.accepted = true
|
||||
break
|
||||
case Qt.Key_J:
|
||||
ui.selectNext()
|
||||
event.accepted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue