diff --git a/.config/quickshell/modules/common/functions/string_utils.js b/.config/quickshell/modules/common/functions/string_utils.js index ee7b3eaeb..9fa704ada 100644 --- a/.config/quickshell/modules/common/functions/string_utils.js +++ b/.config/quickshell/modules/common/functions/string_utils.js @@ -10,9 +10,9 @@ function getDomain(url) { } function shellSingleQuoteEscape(str) { - // First escape backslashes, then escape single quotes + // escape single quotes return String(str) - .replace(/\\/g, '\\\\') + // .replace(/\\/g, '\\\\') .replace(/'/g, "'\\''"); } @@ -33,7 +33,3 @@ function splitMarkdownBlocks(markdown) { } return result; } - -function unEscapeBackslashes(str) { - return str.replace(/\\\\/g, '\\'); -} \ No newline at end of file diff --git a/.config/quickshell/modules/sidebarLeft/aiChat/AiMessage.qml b/.config/quickshell/modules/sidebarLeft/aiChat/AiMessage.qml index e09a1a37d..eb85dfd9d 100644 --- a/.config/quickshell/modules/sidebarLeft/aiChat/AiMessage.qml +++ b/.config/quickshell/modules/sidebarLeft/aiChat/AiMessage.qml @@ -27,6 +27,7 @@ Rectangle { property real codeBlockHeaderPadding: 3 property real codeBlockComponentSpacing: 2 + property bool enableMouseSelection: false property bool renderMarkdown: true property bool editing: false @@ -250,6 +251,7 @@ Rectangle { TextArea { Layout.fillWidth: true readOnly: !root.editing + selectByMouse: root.enableMouseSelection || root.editing renderType: Text.NativeRendering font.family: Appearance.font.family.reading font.hintingPreference: Font.PreferNoHinting // Prevent weird bold text @@ -281,7 +283,8 @@ Rectangle { anchors.fill: parent acceptedButtons: Qt.NoButton // Only for hover hoverEnabled: true - cursorShape: parent.hoveredLink !== "" ? Qt.PointingHandCursor : Qt.IBeamCursor + cursorShape: parent.hoveredLink !== "" ? Qt.PointingHandCursor : + (root.enableMouseSelection || root.editing) ? Qt.IBeamCursor : Qt.ArrowCursor } } } @@ -330,9 +333,7 @@ Rectangle { id: copyCodeButton buttonIcon: "content_copy" onClicked: { - Hyprland.dispatch(`exec wl-copy '${StringUtils.unEscapeBackslashes( - StringUtils.shellSingleQuoteEscape(segment.content) - )}'`) + Hyprland.dispatch(`exec wl-copy '${StringUtils.shellSingleQuoteEscape(segment.content)}'`) } StyledToolTip { content: qsTr("Copy code") @@ -422,10 +423,10 @@ Rectangle { } TextArea { // Code - id: codeTextArea Layout.fillWidth: true readOnly: !root.editing + selectByMouse: root.enableMouseSelection || root.editing renderType: Text.NativeRendering font.family: Appearance.font.family.monospace font.hintingPreference: Font.PreferNoHinting // Prevent weird bold text @@ -463,6 +464,16 @@ Rectangle { } } } + + // MouseArea to block scrolling + MouseArea { + id: codeBlockMouseArea + anchors.fill: parent + acceptedButtons: root.editing ? Qt.NoButton : Qt.LeftButton + onWheel: (event) => { + event.accepted = false + } + } } } } diff --git a/.config/quickshell/services/Ai.qml b/.config/quickshell/services/Ai.qml index aac7b8e9e..a4791b04d 100644 --- a/.config/quickshell/services/Ai.qml +++ b/.config/quickshell/services/Ai.qml @@ -249,7 +249,7 @@ Singleton { + ` ${headerString}` + ' -H "Authorization: Bearer ${API_KEY}"' + ` -d '${StringUtils.shellSingleQuoteEscape(JSON.stringify(data))}'` - // console.log("Request command: ", requestCommandString); + console.log("Request command: ", requestCommandString); requester.command = baseCommand.concat([requestCommandString]); /* Reset vars and make the request */ @@ -302,7 +302,7 @@ Singleton { if (dataJson.done) requester.message.done = true; } catch (e) { - console.log("Could not parse response: ", e); + console.log("[AI] Could not parse response from stream: ", e); requester.message.content += cleanData; } } @@ -314,7 +314,7 @@ Singleton { const parsedResponse = JSON.parse(requester.message.content + "]"); requester.message.content = `\`\`\`json\n${JSON.stringify(parsedResponse, null, 2)}\n\`\`\``; } catch (e) { - console.log("Could not parse response: ", e); + console.log("[AI] Could not parse response on exit: ", e); } } }