Update lookandfeel/runcommand/RunCommand.qml
See the breath
issue for more details: https://gitlab.manjaro.org/artwork/themes/breath/-/issues/22
Here's RunCommand.qml
diff of breath2@master
and breeze@Plasma/5.21
.
diff --git a/./RunCommand-breath2.qml b/./RunCommand-5.21.qml
index 609a7bc77..27170d9d8 100644
--- a/./RunCommand-breath2.qml
+++ b/./RunCommand-5.21.qml
@@ -29,7 +29,7 @@ ColumnLayout {
property string query
property string runner
property bool showHistory: false
- property string priorSearch
+ property alias runnerManager: results.runnerManager
LayoutMirroring.enabled: Qt.application.layoutDirection === Qt.RightToLeft
LayoutMirroring.childrenInherit: true
@@ -40,20 +40,20 @@ ColumnLayout {
Connections {
target: runnerWindow
- onVisibleChanged: {
+ function onVisibleChanged() {
if (runnerWindow.visible) {
queryField.forceActiveFocus();
listView.currentIndex = -1
- if (runnerWindow.retainPriorSearch) {
+ if (runnerManager.retainPriorSearch) {
// If we manually specified a query(D-Bus invocation) we don't want to retain the prior search
if (!query) {
- queryField.text = priorSearch
+ queryField.text = runnerManager.priorSearch
queryField.select(root.query.length, 0)
}
}
} else {
- if (runnerWindow.retainPriorSearch) {
- priorSearch = root.query
+ if (runnerManager.retainPriorSearch) {
+ runnerManager.priorSearch = root.query
}
root.runner = ""
root.query = ""
@@ -62,6 +62,18 @@ ColumnLayout {
}
}
+ Connections {
+ target: root
+ function onShowHistoryChanged() {
+ if (showHistory) {
+ // we store 50 entries in the history but only show 20 in the UI so it doesn't get too huge
+ listView.model = runnerManager.history.slice(0, 20)
+ } else {
+ listView.model = []
+ }
+ }
+ }
+
RowLayout {
Layout.alignment: Qt.AlignTop
PlasmaComponents3.ToolButton {
@@ -139,20 +151,12 @@ ColumnLayout {
onTextChanged: {
root.query = queryField.text
- if (allowCompletion && length > 0) {
- var history = runnerWindow.history
-
- // search the first item in the history rather than the shortest matching one
- // this way more recently used entries take precedence over older ones (Bug 358985)
- for (var i = 0, j = history.length; i < j; ++i) {
- var item = history[i]
-
- if (item.toLowerCase().indexOf(text.toLowerCase()) === 0) {
- var oldText = text
- text = text + item.substr(oldText.length)
- select(text.length, oldText.length)
- break
- }
+ if (allowCompletion && length > 0 && runnerManager.historyEnabled) {
+ var oldText = text
+ var suggestedText = runnerManager.getHistorySuggestion(text);
+ if (suggestedText.length > 0) {
+ text = text + suggestedText.substr(oldText.length)
+ select(text.length, oldText.length)
}
}
}
@@ -171,8 +175,16 @@ ColumnLayout {
}
Keys.onUpPressed: move_up()
Keys.onDownPressed: move_down()
- Keys.onEnterPressed: results.runCurrentIndex(event)
- Keys.onReturnPressed: results.runCurrentIndex(event)
+ function closeOrRun(event) {
+ // Close KRunner if no text was typed and enter was pressed, FEATURE: 211225
+ if (!root.query) {
+ runnerWindow.visible = false
+ } else {
+ results.runCurrentIndex(event)
+ }
+ }
+ Keys.onEnterPressed: closeOrRun(event)
+ Keys.onReturnPressed: closeOrRun(event)
Keys.onEscapePressed: {
runnerWindow.visible = false
@@ -192,7 +204,7 @@ ColumnLayout {
colorGroup: PlasmaCore.Theme.ButtonColorGroup
}
elementId: "down-arrow"
- visible: queryField.length === 0 && runnerWindow.history.length > 0
+ visible: queryField.length === 0 && runnerManager.historyEnabled
MouseArea {
anchors.fill: parent
@@ -208,14 +220,14 @@ ColumnLayout {
}
}
PlasmaComponents3.ToolButton {
- icon.name: "window-close"
- onClicked: {
- runnerWindow.visible = false
- }
- Accessible.name: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Close")
- Accessible.description: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Close Search")
+ checkable: true
+ checked: runnerWindow.pinned
+ onToggled: runnerWindow.pinned = checked
+ icon.name: "window-pin"
+ Accessible.name: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Pin")
+ Accessible.description: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Pin Search")
PlasmaComponents3.ToolTip {
- text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Close")
+ text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Keep Open")
}
}
}
@@ -248,7 +260,6 @@ ColumnLayout {
}
onActivated: {
- runnerWindow.addToHistory(queryString)
runnerWindow.visible = false
}
@@ -273,8 +284,7 @@ ColumnLayout {
highlight: PlasmaComponents.Highlight {}
highlightMoveDuration: 0
activeFocusOnTab: true
- // we store 50 entries in the history but only show 20 in the UI so it doesn't get too huge
- model: root.showHistory ? runnerWindow.history.slice(0, 20) : []
+ model: []
delegate: Milou.ResultDelegate {
id: resultDelegate
width: listView.width
@@ -315,7 +325,12 @@ ColumnLayout {
} else if (ctrl && event.key === Qt.Key_K) {
decrementCurrentIndex()
} else if (event.text !== "") {
- queryField.text += event.text;
+ // This prevents unprintable control characters from being inserted
+ if (event.key == Qt.Key_Escape) {
+ root.showHistory = false
+ } else if (!/[\x00-\x1F\x7F]/.test(event.text)) {
+ queryField.text += event.text;
+ }
queryField.focus = true;
}
}
@@ -324,7 +339,7 @@ ColumnLayout {
Keys.onDownPressed: incrementCurrentIndex()
function runCurrentIndex(event) {
- var entry = runnerWindow.history[currentIndex]
+ var entry = runnerManager.history[currentIndex]
if (entry) {
// If user presses Shift+Return to invoke an action, invoke the first runner action
if (event && event.modifiers === Qt.ShiftModifier
@@ -342,7 +357,8 @@ ColumnLayout {
if (actionIndex === 0) {
// QStringList changes just reset the model, so we'll remember the index and set it again
var currentIndex = listView.currentIndex
- runnerWindow.removeFromHistory(currentIndex)
+ runnerManager.removeFromHistory(currentIndex)
+ model = runnerManager.history
listView.currentIndex = currentIndex
}
}