From db83864d78ddc362d6de957302b1e2ce59cd88e2 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 22 Aug 2025 16:52:02 +0700 Subject: [PATCH] sidebar: ai: allow pasting image --- .../ii/modules/sidebarLeft/AiChat.qml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml b/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml index dad41919..a2f4a3a0 100644 --- a/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml +++ b/.config/quickshell/ii/modules/sidebarLeft/AiChat.qml @@ -9,6 +9,7 @@ import QtQuick.Controls import QtQuick.Layouts import Qt5Compat.GraphicalEffects import Quickshell +import Quickshell.Io Item { id: root @@ -210,6 +211,26 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\) } } + Process { + id: decodeImageAndAttachProc + property string imageDecodePath: Directories.cliphistDecode + property string imageDecodeFileName: "image" + property string imageDecodeFilePath: `${imageDecodePath}/${imageDecodeFileName}` + function handleEntry(entry: string) { + imageDecodeFileName = parseInt(entry.match(/^(\d+)\t/)[1]) + decodeImageAndAttachProc.exec(["bash", "-c", + `[ -f ${imageDecodeFilePath} ] || echo '${StringUtils.shellSingleQuoteEscape(entry)}' | cliphist decode > '${imageDecodeFilePath}'` + ]) + } + onExited: (exitCode, exitStatus) => { + if (exitCode === 0) { + Ai.attachFile(imageDecodeFilePath); + } else { + console.error("[AiChat] Failed to decode image in clipboard content") + } + } + } + component StatusItem: MouseArea { id: statusItem property string icon @@ -610,6 +631,17 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\) root.handleInput(inputText) event.accepted = true } + } else if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_V) { + // Try image paste first + const currentClipboardEntry = Cliphist.entries[0] + if (/^\d+\t\[\[.*binary data.*\d+x\d+.*\]\]$/.test(currentClipboardEntry)) { // First entry = currently copied entry = image? + print("CLIPBOARD IZ IMAGE, ATTACHING I REPEAT ATTACHING") + decodeImageAndAttachProc.handleEntry(currentClipboardEntry) + event.accepted = true; + return; + } + event.accepted = false; + // fall through to normal paste for text } } }