forked from Shinonome/dots-hyprland
fix string escaping
This commit is contained in:
@@ -10,9 +10,9 @@ function getDomain(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function shellSingleQuoteEscape(str) {
|
function shellSingleQuoteEscape(str) {
|
||||||
// First escape backslashes, then escape single quotes
|
// escape single quotes
|
||||||
return String(str)
|
return String(str)
|
||||||
.replace(/\\/g, '\\\\')
|
// .replace(/\\/g, '\\\\')
|
||||||
.replace(/'/g, "'\\''");
|
.replace(/'/g, "'\\''");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,3 @@ function splitMarkdownBlocks(markdown) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function unEscapeBackslashes(str) {
|
|
||||||
return str.replace(/\\\\/g, '\\');
|
|
||||||
}
|
|
||||||
@@ -27,6 +27,7 @@ Rectangle {
|
|||||||
property real codeBlockHeaderPadding: 3
|
property real codeBlockHeaderPadding: 3
|
||||||
property real codeBlockComponentSpacing: 2
|
property real codeBlockComponentSpacing: 2
|
||||||
|
|
||||||
|
property bool enableMouseSelection: false
|
||||||
property bool renderMarkdown: true
|
property bool renderMarkdown: true
|
||||||
property bool editing: false
|
property bool editing: false
|
||||||
|
|
||||||
@@ -250,6 +251,7 @@ Rectangle {
|
|||||||
TextArea {
|
TextArea {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
readOnly: !root.editing
|
readOnly: !root.editing
|
||||||
|
selectByMouse: root.enableMouseSelection || root.editing
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
font.family: Appearance.font.family.reading
|
font.family: Appearance.font.family.reading
|
||||||
font.hintingPreference: Font.PreferNoHinting // Prevent weird bold text
|
font.hintingPreference: Font.PreferNoHinting // Prevent weird bold text
|
||||||
@@ -281,7 +283,8 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
acceptedButtons: Qt.NoButton // Only for hover
|
acceptedButtons: Qt.NoButton // Only for hover
|
||||||
hoverEnabled: true
|
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
|
id: copyCodeButton
|
||||||
buttonIcon: "content_copy"
|
buttonIcon: "content_copy"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Hyprland.dispatch(`exec wl-copy '${StringUtils.unEscapeBackslashes(
|
Hyprland.dispatch(`exec wl-copy '${StringUtils.shellSingleQuoteEscape(segment.content)}'`)
|
||||||
StringUtils.shellSingleQuoteEscape(segment.content)
|
|
||||||
)}'`)
|
|
||||||
}
|
}
|
||||||
StyledToolTip {
|
StyledToolTip {
|
||||||
content: qsTr("Copy code")
|
content: qsTr("Copy code")
|
||||||
@@ -422,10 +423,10 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextArea { // Code
|
TextArea { // Code
|
||||||
|
|
||||||
id: codeTextArea
|
id: codeTextArea
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
readOnly: !root.editing
|
readOnly: !root.editing
|
||||||
|
selectByMouse: root.enableMouseSelection || root.editing
|
||||||
renderType: Text.NativeRendering
|
renderType: Text.NativeRendering
|
||||||
font.family: Appearance.font.family.monospace
|
font.family: Appearance.font.family.monospace
|
||||||
font.hintingPreference: Font.PreferNoHinting // Prevent weird bold text
|
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}`
|
+ ` ${headerString}`
|
||||||
+ ' -H "Authorization: Bearer ${API_KEY}"'
|
+ ' -H "Authorization: Bearer ${API_KEY}"'
|
||||||
+ ` -d '${StringUtils.shellSingleQuoteEscape(JSON.stringify(data))}'`
|
+ ` -d '${StringUtils.shellSingleQuoteEscape(JSON.stringify(data))}'`
|
||||||
// console.log("Request command: ", requestCommandString);
|
console.log("Request command: ", requestCommandString);
|
||||||
requester.command = baseCommand.concat([requestCommandString]);
|
requester.command = baseCommand.concat([requestCommandString]);
|
||||||
|
|
||||||
/* Reset vars and make the request */
|
/* Reset vars and make the request */
|
||||||
@@ -302,7 +302,7 @@ Singleton {
|
|||||||
|
|
||||||
if (dataJson.done) requester.message.done = true;
|
if (dataJson.done) requester.message.done = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Could not parse response: ", e);
|
console.log("[AI] Could not parse response from stream: ", e);
|
||||||
requester.message.content += cleanData;
|
requester.message.content += cleanData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +314,7 @@ Singleton {
|
|||||||
const parsedResponse = JSON.parse(requester.message.content + "]");
|
const parsedResponse = JSON.parse(requester.message.content + "]");
|
||||||
requester.message.content = `\`\`\`json\n${JSON.stringify(parsedResponse, null, 2)}\n\`\`\``;
|
requester.message.content = `\`\`\`json\n${JSON.stringify(parsedResponse, null, 2)}\n\`\`\``;
|
||||||
} catch (e) {
|
} 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