paste image working

deci committed Jun 23, 2025 at 16:18 UTC 0815ba40b39049bf0f4c823f58a6f9ad85705b2c
1 file changed +13 -8
webui/components/chat/attachments/attachmentsStore.js
+13 -8
@@ -116,16 +116,12 @@ const model = {
116 console.log('Setting up paste handler...');
117 document.addEventListener('paste', (e) => {
118 console.log('Paste event detected, target:', e.target.tagName);
119 - // Only handle paste when not in an input field (to avoid interfering with text pasting)
120 - if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
121 - console.log('Ignoring paste in input field');
122 - return;
123 - }
124 -
119 +
120 const items = e.clipboardData.items;
121 let imageFound = false;
122 console.log('Checking clipboard items:', items.length);
123
124 + // First, check if there are any images in the clipboard
125 for (let i = 0; i < items.length; i++) {
126 const item = items[i];
127 if (item.type.indexOf('image') !== -1) {
@@ -134,12 +130,21 @@ const model = {
130 if (blob) {
131 e.preventDefault(); // Prevent default paste behavior for images
132 this.handleClipboardImage(blob);
133 + console.log('Image detected in clipboard, processing...');
134 }
135 + break; // Only handle the first image found
136 }
137 }
138
141 - if (imageFound) {
142 - console.log('Image detected in clipboard, processing...');
139 + // If no images found and we're in an input field, let normal text paste happen
140 + if (!imageFound && (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA')) {
141 + console.log('No images in clipboard, allowing normal text paste in input field');
142 + return;
143 + }
144 +
145 + // If no images found and not in input field, do nothing
146 + if (!imageFound) {
147 + console.log('No images in clipboard');
148 }
149 });
150 },