forked from Shinonome/dots-hyprland
app search qol: enter first item, entry always respond to char keys
This commit is contained in:
@@ -50,7 +50,7 @@ Button {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.leftMargin: root.horizontalMargin
|
anchors.leftMargin: root.horizontalMargin
|
||||||
anchors.rightMargin: root.horizontalMargin
|
anchors.rightMargin: root.horizontalMargin
|
||||||
radius: Appearance.rounding.small
|
radius: Appearance.rounding.normal
|
||||||
color: (root.down || root.keyboardDown) ? Appearance.colors.colLayer1Active : ((root.hovered || root.focus) ? Appearance.colors.colLayer1Hover : Appearance.transparentize(Appearance.m3colors.m3surfaceContainerHigh, 1))
|
color: (root.down || root.keyboardDown) ? Appearance.colors.colLayer1Active : ((root.hovered || root.focus) ? Appearance.colors.colLayer1Hover : Appearance.transparentize(Appearance.m3colors.m3surfaceContainerHigh, 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,21 @@ Item { // Wrapper
|
|||||||
implicitWidth: searchWidgetContent.implicitWidth + Appearance.sizes.elevationMargin * 2
|
implicitWidth: searchWidgetContent.implicitWidth + Appearance.sizes.elevationMargin * 2
|
||||||
implicitHeight: searchWidgetContent.implicitHeight + Appearance.sizes.elevationMargin * 2
|
implicitHeight: searchWidgetContent.implicitHeight + Appearance.sizes.elevationMargin * 2
|
||||||
|
|
||||||
|
Keys.onPressed: {
|
||||||
|
// Only handle printable characters (ignore modifiers, arrows, etc.)
|
||||||
|
if (event.text && event.text.length === 1 && event.key !== Qt.Key_Enter && event.key !== Qt.Key_Return) {
|
||||||
|
if (!searchInput.activeFocus) {
|
||||||
|
searchInput.forceActiveFocus();
|
||||||
|
// Insert the character at the cursor position
|
||||||
|
searchInput.text = searchInput.text.slice(0, searchInput.cursorPosition) +
|
||||||
|
event.text +
|
||||||
|
searchInput.text.slice(searchInput.cursorPosition);
|
||||||
|
searchInput.cursorPosition += 1;
|
||||||
|
event.accepted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle { // Background
|
Rectangle { // Background
|
||||||
id: searchWidgetContent
|
id: searchWidgetContent
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
@@ -53,16 +68,16 @@ Item { // Wrapper
|
|||||||
TextField { // Search box
|
TextField { // Search box
|
||||||
id: searchInput
|
id: searchInput
|
||||||
|
|
||||||
padding: 15
|
focus: root.panelWindow.visible || GlobalStates.overviewOpen
|
||||||
Layout.rightMargin: 15
|
Layout.rightMargin: 15
|
||||||
|
padding: 15
|
||||||
color: activeFocus ? Appearance.m3colors.m3onSurface : Appearance.m3colors.m3onSurfaceVariant
|
color: activeFocus ? Appearance.m3colors.m3onSurface : Appearance.m3colors.m3onSurfaceVariant
|
||||||
selectedTextColor: Appearance.m3colors.m3onSurface
|
selectedTextColor: Appearance.m3colors.m3onSurface
|
||||||
placeholderText: qsTr("Search")
|
placeholderText: qsTr("Search")
|
||||||
placeholderTextColor: Appearance.m3colors.m3outline
|
placeholderTextColor: Appearance.m3colors.m3outline
|
||||||
focus: root.panelWindow.visible || GlobalStates.overviewOpen
|
|
||||||
|
|
||||||
implicitWidth: Appearance.sizes.searchWidth
|
implicitWidth: Appearance.sizes.searchWidth
|
||||||
|
|
||||||
|
|
||||||
onTextChanged: root.searchingText = text
|
onTextChanged: root.searchingText = text
|
||||||
Connections {
|
Connections {
|
||||||
target: root
|
target: root
|
||||||
@@ -72,6 +87,16 @@ Item { // Wrapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onAccepted: {
|
||||||
|
if (appResults.count > 0) {
|
||||||
|
// Get the first visible delegate and trigger its click
|
||||||
|
let firstItem = appResults.itemAtIndex(0);
|
||||||
|
if (firstItem && firstItem.clicked) {
|
||||||
|
firstItem.clicked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
background: Item {}
|
background: Item {}
|
||||||
|
|
||||||
cursorDelegate: Rectangle {
|
cursorDelegate: Rectangle {
|
||||||
@@ -93,7 +118,7 @@ Item { // Wrapper
|
|||||||
id: appResults
|
id: appResults
|
||||||
visible: root.showResults
|
visible: root.showResults
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
implicitHeight: 600
|
implicitHeight: Math.min(600, appResults.contentHeight + topMargin + bottomMargin)
|
||||||
clip: true
|
clip: true
|
||||||
topMargin: 10
|
topMargin: 10
|
||||||
bottomMargin: 10
|
bottomMargin: 10
|
||||||
@@ -101,7 +126,7 @@ Item { // Wrapper
|
|||||||
KeyNavigation.up: searchBar
|
KeyNavigation.up: searchBar
|
||||||
|
|
||||||
model: ScriptModel {
|
model: ScriptModel {
|
||||||
id: model;
|
id: model
|
||||||
values: DesktopEntries.applications.values
|
values: DesktopEntries.applications.values
|
||||||
.filter((entry) => {
|
.filter((entry) => {
|
||||||
if (root.searchingText == "") return false
|
if (root.searchingText == "") return false
|
||||||
|
|||||||
Reference in New Issue
Block a user