forked from Shinonome/dots-hyprland
waffles: functioning search
This commit is contained in:
@@ -16,10 +16,72 @@ WBarAttachedPanelContent {
|
||||
property bool searching: false
|
||||
property string searchText: LauncherSearch.query
|
||||
|
||||
StartMenuContext {
|
||||
id: context
|
||||
}
|
||||
|
||||
Keys.onPressed: event => {
|
||||
// Prevent Esc and Backspace from registering
|
||||
if (event.key === Qt.Key_Escape)
|
||||
return;
|
||||
|
||||
// Handle Backspace: focus and delete character if not focused
|
||||
if (event.key === Qt.Key_Backspace) {
|
||||
searchBar.forceFocus();
|
||||
if (event.modifiers & Qt.ControlModifier) {
|
||||
// Delete word before cursor
|
||||
let text = searchBar.text;
|
||||
let pos = searchBar.searchInput.cursorPosition;
|
||||
if (pos > 0) {
|
||||
// Find the start of the previous word
|
||||
let left = text.slice(0, pos);
|
||||
let match = left.match(/(\s*\S+)\s*$/);
|
||||
let deleteLen = match ? match[0].length : 1;
|
||||
searchBar.text = text.slice(0, pos - deleteLen) + text.slice(pos);
|
||||
searchBar.searchInput.cursorPosition = pos - deleteLen;
|
||||
}
|
||||
} else {
|
||||
// Delete character before cursor if any
|
||||
if (searchBar.searchInput.cursorPosition > 0) {
|
||||
searchBar.text = searchBar.text.slice(0, searchBar.searchInput.cursorPosition - 1) + searchBar.text.slice(searchBar.searchInput.cursorPosition);
|
||||
searchBar.searchInput.cursorPosition -= 1;
|
||||
}
|
||||
}
|
||||
// Always move cursor to end after programmatic edit
|
||||
searchBar.searchInput.cursorPosition = searchBar.text.length;
|
||||
event.accepted = true;
|
||||
// If already focused, let TextField handle it
|
||||
return;
|
||||
}
|
||||
|
||||
// Only handle visible printable characters (ignore control chars, arrows, etc.)
|
||||
if (event.text && event.text.length === 1 && event.key !== Qt.Key_Enter && event.key !== Qt.Key_Return && event.key !== Qt.Key_Delete && event.text.charCodeAt(0) >= 0x20) // ignore control chars like Backspace, Tab, etc.
|
||||
{
|
||||
if (!searchBar.searchInput.activeFocus) {
|
||||
searchBar.forceFocus();
|
||||
// Insert the character at the cursor position
|
||||
searchBar.text = searchBar.text.slice(0, searchBar.searchInput.cursorPosition) + event.text + searchBar.text.slice(searchBar.searchInput.cursorPosition);
|
||||
searchBar.searchInput.cursorPosition += 1;
|
||||
event.accepted = true;
|
||||
context.setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Arrow keys for item navigation
|
||||
if (event.key === Qt.Key_Down) {
|
||||
let maxIndex = Math.max(0, LauncherSearch.results.length - 1);
|
||||
context.setCurrentIndex(Math.min(context.currentIndex + 1, maxIndex));
|
||||
event.accepted = true;
|
||||
} else if (event.key === Qt.Key_Up) {
|
||||
context.setCurrentIndex(Math.max(context.currentIndex - 1, 0));
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: WPane {
|
||||
contentItem: WPanelPageColumn {
|
||||
SearchBar {
|
||||
focus: true
|
||||
id: searchBar
|
||||
Layout.fillWidth: true
|
||||
implicitWidth: 832 // TODO: Make sizes naturally inferred
|
||||
horizontalPadding: root.searching ? 24 : 32
|
||||
@@ -27,10 +89,14 @@ WBarAttachedPanelContent {
|
||||
Synchronizer on searching {
|
||||
property alias target: root.searching
|
||||
}
|
||||
focus: true
|
||||
text: root.searchText
|
||||
onTextChanged: {
|
||||
LauncherSearch.query = text;
|
||||
}
|
||||
onAccepted: {
|
||||
context.accepted();
|
||||
}
|
||||
}
|
||||
Item {
|
||||
implicitHeight: root.searching ? 736 : 736 // TODO: Make sizes naturally inferred
|
||||
@@ -46,7 +112,9 @@ WBarAttachedPanelContent {
|
||||
|
||||
Component {
|
||||
id: searchPageComp
|
||||
SearchPageContent {}
|
||||
SearchPageContent {
|
||||
context: context
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
|
||||
Reference in New Issue
Block a user