mirror of
https://github.com/andrepimenta/claude-code-chat.git
synced 2025-12-09 10:59:53 +00:00
Fix paste function in chat box
This commit is contained in:
3150
package-lock.json
generated
3150
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@@ -181,14 +181,15 @@
|
|||||||
"test": "vscode-test"
|
"test": "vscode-test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/vscode": "^1.95.0",
|
|
||||||
"@types/mocha": "^10.0.10",
|
"@types/mocha": "^10.0.10",
|
||||||
"@types/node": "20.x",
|
"@types/node": "20.x",
|
||||||
|
"@types/vscode": "^1.95.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
||||||
"@typescript-eslint/parser": "^8.31.1",
|
"@typescript-eslint/parser": "^8.31.1",
|
||||||
"eslint": "^9.25.1",
|
|
||||||
"typescript": "^5.8.3",
|
|
||||||
"@vscode/test-cli": "^0.0.10",
|
"@vscode/test-cli": "^0.0.10",
|
||||||
"@vscode/test-electron": "^2.5.2"
|
"@vscode/test-electron": "^2.5.2",
|
||||||
|
"@vscode/vsce": "^3.5.0",
|
||||||
|
"eslint": "^9.25.1",
|
||||||
|
"typescript": "^5.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,6 +206,9 @@ class ClaudeChatProvider {
|
|||||||
case 'updateSettings':
|
case 'updateSettings':
|
||||||
this._updateSettings(message.settings);
|
this._updateSettings(message.settings);
|
||||||
return;
|
return;
|
||||||
|
case 'getClipboardText':
|
||||||
|
this._getClipboardText();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
@@ -1146,6 +1149,18 @@ class ClaudeChatProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _getClipboardText(): Promise<void> {
|
||||||
|
try {
|
||||||
|
const text = await vscode.env.clipboard.readText();
|
||||||
|
this._panel?.webview.postMessage({
|
||||||
|
type: 'clipboardText',
|
||||||
|
data: text
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to read clipboard:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public dispose() {
|
public dispose() {
|
||||||
if (this._panel) {
|
if (this._panel) {
|
||||||
this._panel.dispose();
|
this._panel.dispose();
|
||||||
|
|||||||
92
src/ui.ts
92
src/ui.ts
@@ -1665,9 +1665,79 @@ const html = `<!DOCTYPE html>
|
|||||||
} else if (e.key === 'Escape' && filePickerModal.style.display === 'flex') {
|
} else if (e.key === 'Escape' && filePickerModal.style.display === 'flex') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
hideFilePicker();
|
hideFilePicker();
|
||||||
|
} else if (e.key === 'v' && (e.ctrlKey || e.metaKey)) {
|
||||||
|
// Handle Ctrl+V/Cmd+V explicitly in case paste event doesn't fire
|
||||||
|
// Don't prevent default - let browser handle it first
|
||||||
|
setTimeout(() => {
|
||||||
|
// If value hasn't changed, manually trigger paste
|
||||||
|
const currentValue = messageInput.value;
|
||||||
|
setTimeout(() => {
|
||||||
|
if (messageInput.value === currentValue) {
|
||||||
|
// Value didn't change, request clipboard from VS Code
|
||||||
|
vscode.postMessage({
|
||||||
|
type: 'getClipboardText'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add explicit paste event handler for better clipboard support in VSCode webviews
|
||||||
|
messageInput.addEventListener('paste', async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to get clipboard data from the event first
|
||||||
|
const clipboardData = e.clipboardData;
|
||||||
|
let text = '';
|
||||||
|
|
||||||
|
if (clipboardData) {
|
||||||
|
text = clipboardData.getData('text/plain');
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no text from event, try navigator.clipboard API
|
||||||
|
if (!text && navigator.clipboard && navigator.clipboard.readText) {
|
||||||
|
try {
|
||||||
|
text = await navigator.clipboard.readText();
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Clipboard API failed:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If still no text, request from VS Code extension
|
||||||
|
if (!text) {
|
||||||
|
vscode.postMessage({
|
||||||
|
type: 'getClipboardText'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert text at cursor position
|
||||||
|
const start = messageInput.selectionStart;
|
||||||
|
const end = messageInput.selectionEnd;
|
||||||
|
const currentValue = messageInput.value;
|
||||||
|
|
||||||
|
const newValue = currentValue.substring(0, start) + text + currentValue.substring(end);
|
||||||
|
messageInput.value = newValue;
|
||||||
|
|
||||||
|
// Set cursor position after pasted text
|
||||||
|
const newCursorPos = start + text.length;
|
||||||
|
messageInput.setSelectionRange(newCursorPos, newCursorPos);
|
||||||
|
|
||||||
|
// Trigger input event to adjust height
|
||||||
|
messageInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Paste error:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle context menu paste
|
||||||
|
messageInput.addEventListener('contextmenu', (e) => {
|
||||||
|
// Don't prevent default - allow context menu to show
|
||||||
|
// but ensure paste will work when selected
|
||||||
|
});
|
||||||
|
|
||||||
// Initialize textarea height
|
// Initialize textarea height
|
||||||
adjustTextareaHeight();
|
adjustTextareaHeight();
|
||||||
|
|
||||||
@@ -1978,6 +2048,9 @@ const html = `<!DOCTYPE html>
|
|||||||
case 'conversationList':
|
case 'conversationList':
|
||||||
displayConversationList(message.data);
|
displayConversationList(message.data);
|
||||||
break;
|
break;
|
||||||
|
case 'clipboardText':
|
||||||
|
handleClipboardText(message.data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2345,6 +2418,25 @@ const html = `<!DOCTYPE html>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleClipboardText(text) {
|
||||||
|
if (!text) return;
|
||||||
|
|
||||||
|
// Insert text at cursor position
|
||||||
|
const start = messageInput.selectionStart;
|
||||||
|
const end = messageInput.selectionEnd;
|
||||||
|
const currentValue = messageInput.value;
|
||||||
|
|
||||||
|
const newValue = currentValue.substring(0, start) + text + currentValue.substring(end);
|
||||||
|
messageInput.value = newValue;
|
||||||
|
|
||||||
|
// Set cursor position after pasted text
|
||||||
|
const newCursorPos = start + text.length;
|
||||||
|
messageInput.setSelectionRange(newCursorPos, newCursorPos);
|
||||||
|
|
||||||
|
// Trigger input event to adjust height
|
||||||
|
messageInput.dispatchEvent(new Event('input', { bubbles: true }));
|
||||||
|
}
|
||||||
|
|
||||||
// Settings functions
|
// Settings functions
|
||||||
|
|
||||||
function toggleSettings() {
|
function toggleSettings() {
|
||||||
|
|||||||
Reference in New Issue
Block a user