forked from Shinonome/dots-hyprland
fix string escaping
This commit is contained in:
@@ -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, '\\');
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user