web: auto-blockquote pasted text when cursor is on a blockquote marker (#85)
When the cursor is positioned on a line that is just ">" or "> " (a blockquote marker), pasting text will automatically prefix each line with "> " so the entire pasted content becomes blockquoted. This makes it easy to quote multi-line content without manual formatting.
1 file changed,
+22
−1
web/static/chat.js+22 −1
diff --git a/web/static/chat.js b/web/static/chat.js| index c10afbf..2685bfd 100644 |
| --- a/web/static/chat.js |
| +++ b/web/static/chat.js |
| @@ -1030,7 +1030,28 @@ function renderApp() { |
| }); |
| text.addEventListener("paste", (e) => { |
| const item = [...(e.clipboardData?.items || [])].find((i) => i.type.startsWith("image/")); |
| - if (item) addAttachment(item.getAsFile()); |
| + if (item) { |
| + addAttachment(item.getAsFile()); |
| + return; |
| + } |
| + const textItem = [...(e.clipboardData?.items || [])].find((i) => i.type === "text/plain"); |
| + if (textItem) { |
| + const start = text.selectionStart; |
| + const beforeCursor = text.value.substring(0, start); |
| + const currentLine = beforeCursor.split("\n").pop(); |
| + if (/^>\s*$/.test(currentLine)) { |
| + e.preventDefault(); |
| + textItem.getAsString((pastedText) => { |
| + const blockquoted = pastedText.split("\n").map((line) => "> " + line).join("\n"); |
| + const end = text.selectionEnd; |
| + const before = text.value.substring(0, start); |
| + const after = text.value.substring(end); |
| + text.value = before + blockquoted + after; |
| + text.selectionStart = text.selectionEnd = start + blockquoted.length; |
| + text.dispatchEvent(new Event("input", { bubbles: true })); |
| + }); |
| + } |
| + } |
| }); |
| renderThreadList(); |