diff --git a/README.md b/README.md index d580440..08b95eb 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,7 @@ monitor-input-cycle "$1" && echo "Switching display" | `Shift+↵` | Open a new window of an app (`↵` switches to the one already open) | | `Ctrl+K` | Open the action panel (type to filter it; each action shows its shortcut) | | `Ctrl+1`…`9` | Pick a result | +| `←` / `→`, `Home` / `End` | Move the query cursor (`Shift` to select text) | | `↑` / `↓`, `Super+J` / `Super+K` | Move through results | | `Ctrl+N` / `Ctrl+P` | Next / previous (emacs bindings; `Ctrl+P` moves up only inside popups) | | `PageUp` / `PageDown` | Move eight results at a time | @@ -378,6 +379,9 @@ tests/smoke.sh # live checks against the running shell omacast dev # reload on every save ``` +Query editing tests also run headlessly when Qt 6's `qmltestrunner` is installed +at `/usr/lib/qt6/bin/qmltestrunner`. Set `QMLTESTRUNNER` to use another path. + Remove a marketplace install first (`omarchy plugin remove typecraft.omacast`); both use the same plugin id. Quickshell caches QML for the life of the process, so run `omacast reload` after editing a checkout. See [`CLAUDE.md`](CLAUDE.md) for the layout and conventions. diff --git a/tests/launcher-input.test.js b/tests/launcher-input.test.js new file mode 100644 index 0000000..268d1ac --- /dev/null +++ b/tests/launcher-input.test.js @@ -0,0 +1,249 @@ +const test = require("node:test") +const assert = require("node:assert/strict") +const fs = require("node:fs") +const path = require("node:path") +const vm = require("node:vm") +const { spawnSync } = require("node:child_process") + +const source = fs.readFileSync(path.join(__dirname, "../ui/LauncherWindow.qml"), "utf8") + +function body(signature) { + const start = source.indexOf(signature) + assert.ok(start >= 0, signature) + const open = source.indexOf("{", start) + 1 + const end = source.indexOf("\n }", open) + assert.ok(end > open, signature) + return "(function() {\n" + source.slice(open, end) + "\n})()" +} + +function harness() { + let next = 100 + const Qt = new Proxy({ NoModifier: 0, ControlModifier: 1, ShiftModifier: 2, AltModifier: 4, MetaModifier: 8, KeypadModifier: 16 }, { + get(target, key) { if (!(key in target)) target[key] = next++; return target[key] } + }) + const events = [] + const window = { + query: "12+34", atRoot: true, view: { kind: "root" }, actionPanelOpen: false, + historyIndex: -1, selectedIndex: 0, argFocus: -1, argDefs: [], vim: false, + setQuery(query) { this.query = query }, + pop: () => events.push("pop"), move: n => events.push(["move", n]), + nextSelectable: () => 0, rebuild: reset => events.push(["rebuild", reset]), + toggleActionPanel: () => events.push("actions"), + toggleDropdown: () => events.push("dropdown"), + backend: { callSync: () => ({ ok: true, data: ["firefox", "12+34"] }) } + } + const context = vm.createContext({ Qt, window, event: null }) + for (const name of ["direction", "isActionPanelKey", "superOnly"]) { + const start = source.indexOf("function " + name + "(") + const end = source.indexOf("\n }", start) + 4 + window[name] = vm.runInContext("(" + source.slice(start, end) + ")", context) + } + window.recallHistory = direction => { + context.direction = direction + return vm.runInContext(body("function recallHistory(direction)"), context) + } + return { + Qt, window, events, + press(key, modifiers = Qt.NoModifier, text = "") { + context.event = { key: Qt["Key_" + key], modifiers, text } + return vm.runInContext(body("function handleKey(event)"), context) + } + } +} + +test("query editing is delegated to TextInput without changing the query", () => { + const h = harness() + for (const key of ["Left", "Right", "Home", "End", "Backspace", "Delete"]) { + assert.equal(h.press(key), false, key) + } + assert.equal(h.press("5", 0, "5"), false) + assert.equal(h.press("Backspace", h.Qt.ControlModifier), false) + assert.equal(h.press("Left", h.Qt.ShiftModifier), false) + assert.equal(h.window.query, "12+34") +}) + +test("Ctrl+U clears the query and empty Backspace still goes back", () => { + const h = harness() + assert.equal(h.press("U", h.Qt.ControlModifier), true) + assert.equal(h.window.query, "") + assert.equal(h.press("U", h.Qt.ControlModifier | h.Qt.ShiftModifier), false) + assert.equal(h.press("Backspace"), false) + h.window.atRoot = false + assert.equal(h.press("Backspace"), true) + assert.deepEqual(h.events, ["pop"]) +}) + +test("list navigation and action shortcuts retain priority over text editing", () => { + const h = harness() + assert.equal(h.press("Up"), true) + assert.equal(h.press("Down"), true) + assert.equal(h.press("K", h.Qt.ControlModifier), true) + assert.equal(h.press("P", h.Qt.ControlModifier), true) + assert.deepEqual(h.events, [["move", -1], ["move", 1], "actions", "dropdown"]) + assert.equal(h.window.query, "12+34") +}) + +test("vim navigation keeps Alt+K for actions while query arrows remain native", () => { + const h = harness() + h.window.vim = true + assert.equal(h.press("J", h.Qt.ControlModifier), true) + assert.equal(h.press("K", h.Qt.ControlModifier), true) + assert.equal(h.press("K", h.Qt.AltModifier), true) + assert.equal(h.press("Left"), false) + assert.deepEqual(h.events, [["move", 1], ["move", -1], "actions"]) +}) + +test("Super navigation and query clearing keep their upstream bindings", () => { + const h = harness() + assert.equal(h.press("J", h.Qt.MetaModifier), true) + assert.equal(h.press("K", h.Qt.MetaModifier), true) + assert.equal(h.press("Backspace", h.Qt.MetaModifier), true) + assert.equal(h.window.query, "") + assert.deepEqual(h.events, [["move", 1], ["move", -1]]) +}) + +test("popups and arguments transfer focus away from the query and back", () => { + const calls = [] + const window = { argFocus: -1 } + const context = vm.createContext({ + window, + queryText: { forceActiveFocus: () => calls.push("query") }, + keyCatcher: { forceActiveFocus: () => calls.push("keys") } + }) + const expression = source.match(/readonly property bool queryInputActive: ([^\n]*(?:\n &&[^\n]*)*)/)[1] + function focus() { + window.queryInputActive = vm.runInContext(expression, context) + vm.runInContext(body("function focusInput()"), context) + } + for (const [key, active, inactive] of [ + ["actionPanelOpen", true, false], ["dropdownOpen", true, false], + ["toastPanelOpen", true, false], ["aboutOpen", true, false], + ["alert", {}, null], ["argFocus", 0, -1] + ]) { + window[key] = active + focus() + window[key] = inactive + focus() + } + assert.deepEqual(calls, Array(6).fill(["keys", "query"]).flat()) +}) + +test("clicking script dropdown arguments preserves cycling and query focus restoration", () => { + const events = [] + const window = { query: "unchanged", argFocus: -1, argValues: { mode: "one" } } + Object.defineProperty(window, "queryInputActive", { get: () => window.argFocus < 0 }) + const pill = { + index: 0, focused: false, value: "one", + modelData: { name: "mode", type: "dropdown", options: [{ value: "one" }, { value: "two" }] } + } + const context = vm.createContext({ + window, pill, ScriptCommands: require("../core/ScriptCommands.js"), + queryText: { forceActiveFocus: () => events.push("query") }, + keyCatcher: { forceActiveFocus: () => events.push("argument") } + }) + window.focusInput = () => vm.runInContext(body("function focusInput()"), context) + const at = source.indexOf('if (pill.modelData.type === "dropdown" && pill.focused)') + const start = source.lastIndexOf("onClicked: {", at) + "onClicked: {".length + const end = source.indexOf("\n }", at) + assert.ok(at >= 0 && start > 0 && end > start) + const click = "(function() {" + source.slice(start, end) + "})()" + vm.runInContext(click, context) + assert.equal(window.argValues.mode, "one") + pill.focused = true + vm.runInContext(click, context) + assert.equal(window.argValues.mode, "two") + assert.equal(window.query, "unchanged") + window.argFocus = -1 + window.focusInput() + assert.deepEqual(events, ["argument", "argument", "query"]) +}) + +test("history recall survives cursor movement and editing exits history browsing", () => { + const h = harness() + h.window.query = "" + assert.equal(h.press("Up"), true) + assert.equal(h.window.query, "firefox") + assert.equal(h.window.historyIndex, 0) + assert.equal(h.press("Left"), false) + assert.equal(h.window.historyIndex, 0) + assert.equal(h.press("Up"), true) + assert.equal(h.window.query, "12+34") + assert.equal(h.window.historyIndex, 1) + assert.equal(h.press("Down"), true) + assert.equal(h.window.query, "firefox") + h.window.query = "12+34" + const context = vm.createContext({ window: h.window, next: "12+534" }) + vm.runInContext(body("function setQuery(next)"), context) + assert.equal(h.window.query, "12+534") + assert.equal(h.window.historyIndex, -1) +}) + +test("aliases keep native editing while rejecting spaces", () => { + const h = harness() + h.window.view.kind = "alias" + assert.equal(h.press("Left"), false) + assert.equal(h.press("5", 0, "5"), false) + assert.equal(h.press("Space", 0, " "), true) +}) + +test("hiding resets input composition and cancels pending search results", () => { + const events = [] + const window = { + shown: false, mapped: true, searchSerial: 5, searchPending: true, + backend: { cancelSearch: () => events.push("cancel") }, + closePopups: () => events.push("close-popups"), + general: { popToRootTimeout: 90 } + } + const popTimer = { restart: () => events.push("timer") } + const Qt = { inputMethod: { reset: () => events.push("reset-input") } } + const Hyprland = { dispatch: command => events.push(command) } + vm.runInNewContext(body("onShownChanged:"), { window, Qt, popTimer, Hyprland }) + assert.equal(window.searchSerial, 6) + assert.equal(window.searchPending, false) + assert.equal(window.mapped, true) + assert.deepEqual(events, ['hl.dsp.submap("reset")', "reset-input", "cancel", "close-popups", "timer"]) +}) + +test("showing keeps the mapped-surface path without cancelling search or composition", () => { + const events = [] + const screen = {} + const window = { shown: true, mapped: false, pinnedScreen: null, focusedScreen: () => screen } + const Hyprland = { dispatch: command => events.push(command) } + const glassToggle = { reload: () => events.push("glassy") } + vm.runInNewContext(body("onShownChanged:"), { window, Hyprland, glassToggle }) + assert.equal(window.mapped, true) + assert.equal(window.pinnedScreen, screen) + assert.deepEqual(events, ['hl.dsp.submap("omacast")', "glassy"]) +}) + +test("prepare reuses cached root results while restoring query input focus", () => { + for (const [payload, builtRootKey, rebuild] of [[{}, "cached", false], [{ query: "12+34" }, "cached", true], [{}, "old", true]]) { + const events = [] + const window = { + builtRootKey, historyIndex: 0, rootKey: () => "cached", + closePopups() {}, rebuild: () => events.push("rebuild"), + nextSelectable: () => 1, select: () => events.push("restore"), + focusInput: () => events.push("focus") + } + const Qt = { callLater: callback => callback() } + const popTimer = { stop() {} } + vm.runInNewContext(body("function prepare(payload)"), { window, Qt, popTimer, payload }) + assert.equal(window.historyIndex, -1) + assert.deepEqual(events, [rebuild ? "rebuild" : "restore", "focus"]) + } +}) + +test("native query input regression tests", t => { + const runner = process.env.QMLTESTRUNNER || "/usr/lib/qt6/bin/qmltestrunner" + const result = spawnSync(runner, ["-input", path.join(__dirname, "qml")], { + encoding: "utf8", timeout: 30000, + env: { ...process.env, QT_QPA_PLATFORM: "offscreen", QT_QPA_PLATFORMTHEME: "", QT_IM_MODULE: "", QSG_RHI_BACKEND: "software", DBUS_SESSION_BUS_ADDRESS: "" } + }) + if (result.error && result.error.code === "ENOENT") { + t.skip("Qt 6 qmltestrunner is not installed; set QMLTESTRUNNER for a custom path") + return + } + assert.ifError(result.error) + assert.ok(result.status === 0, result.stdout + result.stderr) + assert.match(result.stdout, /QueryInput::test_issue25_insertAtCursor\(\)/) +}) diff --git a/tests/launcher-paste.test.js b/tests/launcher-paste.test.js index 18b7982..356e019 100644 --- a/tests/launcher-paste.test.js +++ b/tests/launcher-paste.test.js @@ -26,11 +26,19 @@ function harness(text) { isActionPanelKey: () => false, direction: () => 0, superOnly: () => false } const actionPanel = { item: { filter: "" } } + let cursor = window.query.length + const queryText = { + selectionStart: cursor, selectionEnd: cursor, + get cursorPosition() { return cursor }, + set cursorPosition(value) { cursor = value; this.selectionStart = value; this.selectionEnd = value }, + deselect() { this.cursorPosition = cursor } + } const clipboardInput = { text: "", clear() { this.text = "" }, paste() { this.text = text } } - const context = vm.createContext({ Qt, window, actionPanel, clipboardInput, Util: { editsFilter: () => false } }) + const context = vm.createContext({ Qt, window, actionPanel, queryText, clipboardInput, Util: { editsFilter: () => false } }) window.setQuery = next => { context.next = next vm.runInContext(body("function setQuery(next)"), context) + queryText.cursorPosition = window.query.length } window.pasteClipboard = () => vm.runInContext(body("function pasteClipboard()"), context) window.insertText = text => { @@ -38,7 +46,7 @@ function harness(text) { vm.runInContext(body("function insertText(text)"), context) } return { - Qt, window, actionPanel, clipboardInput, changes, + Qt, window, actionPanel, queryText, clipboardInput, changes, press(key, modifiers) { context.event = { key: Qt["Key_" + key], modifiers } return vm.runInContext(body("function handleKey(event)"), context) @@ -94,10 +102,25 @@ test("clipboard paste also works in submenu queries and alias editing", () => { assert.equal(h.window.query, "prefix some text with\tspaces") h.window.view.kind = "alias" h.window.query = "" + h.queryText.cursorPosition = 0 h.press("Insert", h.Qt.ShiftModifier) assert.equal(h.window.query, "sometextwithspaces") }) +test("query paste inserts at the cursor and replaces the selected text", () => { + const h = harness("5") + h.window.query = "12+34" + h.queryText.cursorPosition = 3 + h.press("V", h.Qt.ControlModifier) + assert.equal(h.window.query, "12+534") + assert.equal(h.queryText.cursorPosition, 4) + h.queryText.selectionStart = 3 + h.queryText.selectionEnd = 6 + h.press("Insert", h.Qt.ShiftModifier) + assert.equal(h.window.query, "12+5") + assert.equal(h.queryText.cursorPosition, 4) +}) + test("action-panel paste edits its filter without changing the query", () => { const h = harness("Copy\nResult") h.window.actionPanelOpen = true @@ -125,3 +148,17 @@ test("input-method text (fcitx5, dictation) inserts like a paste, without the cl h.window.insertText("") assert.deepEqual(h.changes, [true]) }) + +test("input-method commits insert at the query cursor and replace a selection", () => { + const h = harness("clipboard stays out of it") + h.window.query = "12+34" + h.queryText.cursorPosition = 3 + h.window.insertText("你好") + assert.equal(h.window.query, "12+你好34") + assert.equal(h.queryText.cursorPosition, 5) + h.queryText.selectionStart = 3 + h.queryText.selectionEnd = 5 + h.window.insertText("5") + assert.equal(h.window.query, "12+534") + assert.equal(h.queryText.cursorPosition, 4) +}) diff --git a/tests/qml/tst_queryinput.qml b/tests/qml/tst_queryinput.qml new file mode 100644 index 0000000..69d7bb1 --- /dev/null +++ b/tests/qml/tst_queryinput.qml @@ -0,0 +1,131 @@ +import QtQuick +import QtTest +import "../../ui" + +Item { + width: 500 + height: 100 + + QueryInput { + id: input + width: 200 + height: 40 + font.pixelSize: 20 + text: tests.query + placeholderText: "Search…" + onTextEdited: tests.query = text + } + + TestCase { + id: tests + name: "QueryInput" + when: windowShown + property string query: "" + + function init() { + query = "" + input.forceActiveFocus() + verify(input.activeFocus) + } + + function typeText(text) { + for (var i = 0; i < text.length; i++) keyClick(text[i]) + } + + function test_issue25_insertAtCursor() { + typeText("12+34") + keyClick(Qt.Key_Left) + keyClick(Qt.Key_Left) + compare(input.cursorPosition, 3) + typeText("5") + compare(query, "12+534") + compare(input.cursorPosition, 4) + keyClick(Qt.Key_Right) + typeText("6") + compare(query, "12+5364") + } + + function test_deleteAtCursor() { + query = "12+34" + keyClick(Qt.Key_Left) + keyClick(Qt.Key_Backspace) + compare(query, "12+4") + keyClick(Qt.Key_Delete) + compare(query, "12+") + } + + function test_selectionReplacement() { + query = "12+34" + keyClick(Qt.Key_Left, Qt.ShiftModifier) + keyClick(Qt.Key_Left, Qt.ShiftModifier) + compare(input.selectedText, "34") + typeText("5") + compare(query, "12+5") + keyClick(Qt.Key_A, Qt.ControlModifier) + keyClick(Qt.Key_Backspace) + compare(query, "") + } + + function test_homeEndAndBoundaries() { + query = "12+34" + keyClick(Qt.Key_Home) + keyClick(Qt.Key_Left) + compare(input.cursorPosition, 0) + typeText("5") + compare(query, "512+34") + keyClick(Qt.Key_End) + keyClick(Qt.Key_Right) + compare(input.cursorPosition, query.length) + } + + function test_wordDeletion() { + query = "first second third" + keyClick(Qt.Key_Left, Qt.ControlModifier) + compare(input.cursorPosition, 13) + keyClick(Qt.Key_Backspace, Qt.ControlModifier) + compare(query, "first third") + } + + function test_externalQueryReplacement() { + query = "old query" + keyClick(Qt.Key_Home) + query = "12+34" + compare(input.cursorPosition, query.length) + keyClick(Qt.Key_Left) + typeText("5") + compare(query, "12+354") + query = "" + compare(input.text, "") + compare(input.cursorPosition, 0) + } + + function test_focusPreservesCursor() { + query = "12+34" + keyClick(Qt.Key_Left) + keyClick(Qt.Key_Left) + input.focus = false + input.forceActiveFocus() + compare(input.cursorPosition, 3) + typeText("5") + compare(query, "12+534") + } + + function test_unicodeDeletion() { + query = "a😀b" + keyClick(Qt.Key_Left) + keyClick(Qt.Key_Backspace) + compare(query, "ab") + compare(input.cursorPosition, 1) + } + + function test_longQueryScrollsWithCursor() { + query = "1234567890".repeat(10) + verify(input.contentWidth > input.width) + verify(input.cursorRectangle.x >= 0 && input.cursorRectangle.x <= input.width) + keyClick(Qt.Key_Home) + verify(input.cursorRectangle.x >= 0 && input.cursorRectangle.x <= input.width) + typeText("5") + compare(query, "5" + "1234567890".repeat(10)) + } + } +} diff --git a/ui/LauncherWindow.qml b/ui/LauncherWindow.qml index 1071842..7e47b78 100644 --- a/ui/LauncherWindow.qml +++ b/ui/LauncherWindow.qml @@ -145,11 +145,12 @@ PanelWindow { property var argValues: ({}) property int argFocus: -1 property string argsForId: "" + readonly property bool queryInputActive: !window.actionPanelOpen && !window.dropdownOpen && !window.toastPanelOpen + && !window.aboutOpen && !window.alert && window.argFocus < 0 // Navigation bindings (ref 04 §2.8): emacs moves with Ctrl+N (Ctrl+P is the // dropdown); vim-motions with Ctrl+J/K, which moves the action panel to - // Alt+K. Ctrl+B/F and Ctrl+H/L move a text cursor in Raycast; our search - // field has none, so they do nothing here. [D] + // Alt+K. readonly property bool vim: window.general.navigationBindings === "vim-motions" readonly property string actionPanelKeys: window.vim ? "Alt K" : "Ctrl K" @@ -201,9 +202,16 @@ PanelWindow { // and the card shows on the next frame instead of after a search. if (typeof payload.query === "string" || window.rootKey() !== window.builtRootKey) window.rebuild(true) else window.select(window.nextSelectable(-1, 1), 0) - Qt.callLater(function() { keyCatcher.forceActiveFocus() }) + Qt.callLater(window.focusInput) } + function focusInput() { + if (window.queryInputActive) queryText.forceActiveFocus() + else keyCatcher.forceActiveFocus() + } + + onQueryInputActiveChanged: window.focusInput() + // Hold the content transparent until the surface has the output's size and // scale, as Omarchy's OverlayWindow does. Qt draws the first frame after // mapping at scale 1, which showed stretched and soft, with scale-dependent @@ -246,6 +254,7 @@ PanelWindow { glassToggle.reload() return } + Qt.inputMethod.reset() window.searchSerial++ window.backend.cancelSearch() window.searchPending = false @@ -681,7 +690,11 @@ PanelWindow { window.argValues = values } else { if (window.view.kind === "alias") text = text.replace(/\s/g, "") - window.setQuery(window.query + text) + var start = queryText.selectionStart + var end = queryText.selectionEnd + window.setQuery(window.query.slice(0, start) + text + window.query.slice(end)) + queryText.deselect() + queryText.cursorPosition = start + text.length } } @@ -845,11 +858,10 @@ PanelWindow { } } - if (Util.editsFilter(event, window.query)) { window.setQuery(Util.editedFilter(event, window.query)); return true } + if (event.modifiers === Qt.ControlModifier && key === Qt.Key_U) { window.setQuery(""); return true } // Super+Backspace (Omarchy's delete to line start) arrives raw under the submap: clear the query. if (key === Qt.Key_Backspace && window.superOnly(event)) { window.setQuery(""); return true } if (key === Qt.Key_Backspace && !window.query && !window.atRoot) { window.pop(); return true } - if (window.isTyping(event)) { window.setQuery(window.query + event.text); return true } return false } @@ -888,7 +900,7 @@ PanelWindow { borderSpec: window.borderSpec clip: true - MouseArea { anchors.fill: parent; onClicked: { window.closePopups(); keyCatcher.forceActiveFocus() } } + MouseArea { anchors.fill: parent; onClicked: { window.closePopups(); window.argFocus = -1; window.focusInput() } } // A TextInput rather than a plain Item so input-method commits (fcitx5, // dictation apps) reach the launcher; key presses still go to handleKey @@ -897,7 +909,6 @@ PanelWindow { id: keyCatcher width: 0 height: 0 - focus: true color: "transparent" cursorDelegate: Item {} Keys.priority: Keys.BeforeItem @@ -952,36 +963,24 @@ PanelWindow { // typed text (ref 04 §2.2 WidthSizer). readonly property real queryRoom: (filterButton.visible ? filterButton.x - window.px(12) : header.width - window.px(20)) - queryText.x - Text { + QueryInput { id: queryText - textFormat: Text.PlainText x: lead.x + lead.width + window.px(12) - width: Math.min(implicitWidth, header.queryRoom - (pills.visible ? pills.width + window.px(10) : 0)) + width: Math.max(window.px(4), pills.visible ? Math.min(implicitWidth + window.px(4), header.queryRoom - pills.width - window.px(10)) : header.queryRoom) anchors.verticalCenter: parent.verticalCenter - text: window.query || (pills.visible ? "" : window.placeholder) + text: window.query + placeholderText: pills.visible ? "" : window.placeholder color: window.look.foreground - opacity: window.query ? 1 : 0.45 + accentColor: window.look.accent + selectionColor: window.look.accent + selectedTextColor: window.look.background + enabled: window.queryInputActive font.family: window.look.fontFamily font.pixelSize: Math.round(Style.font.heading * 1.15 * window.zoom) - elide: Text.ElideLeft - } - - Rectangle { - width: Math.max(1, Style.space(2)) - height: queryText.font.pixelSize + Style.space(4) - anchors.verticalCenter: parent.verticalCenter - x: queryText.x + (window.query ? Math.min(queryText.contentWidth, queryText.width) + Style.space(1) : 0) - color: window.look.accent - visible: window.shown && !window.actionPanelOpen && window.argFocus < 0 - - SequentialAnimation on opacity { - running: window.shown - loops: Animation.Infinite - NumberAnimation { to: 1; duration: 0 } - PauseAnimation { duration: 530 } - NumberAnimation { to: 0; duration: 0 } - PauseAnimation { duration: 530 } - } + focus: true + onTextEdited: window.setQuery(text) + Keys.priority: Keys.BeforeItem + Keys.onPressed: function(event) { event.accepted = window.handleKey(event) } } Row { @@ -1047,7 +1046,7 @@ PanelWindow { window.argValues = values } window.argFocus = pill.index - keyCatcher.forceActiveFocus() + window.focusInput() } } } @@ -1094,7 +1093,7 @@ PanelWindow { MouseArea { anchors.fill: parent cursorShape: Qt.PointingHandCursor - onClicked: { window.toggleDropdown(); keyCatcher.forceActiveFocus() } + onClicked: window.toggleDropdown() } } diff --git a/ui/QueryInput.qml b/ui/QueryInput.qml new file mode 100644 index 0000000..2658ddc --- /dev/null +++ b/ui/QueryInput.qml @@ -0,0 +1,39 @@ +pragma ComponentBehavior: Bound + +import QtQuick + +TextInput { + id: input + + property string placeholderText: "" + property color accentColor: color + + clip: true + selectByMouse: true + + Text { + anchors.fill: parent + textFormat: Text.PlainText + text: input.placeholderText + font: input.font + color: input.color + opacity: 0.45 + elide: Text.ElideLeft + visible: !input.text && !input.preeditText + } + + cursorDelegate: Rectangle { + width: 2 + color: input.accentColor + visible: input.cursorVisible + + SequentialAnimation on opacity { + running: input.cursorVisible + loops: Animation.Infinite + NumberAnimation { to: 1; duration: 0 } + PauseAnimation { duration: 530 } + NumberAnimation { to: 0; duration: 0 } + PauseAnimation { duration: 530 } + } + } +}