diff --git a/aicodebot/input.py b/aicodebot/input.py index 65c1224..0829c94 100644 --- a/aicodebot/input.py +++ b/aicodebot/input.py @@ -108,7 +108,7 @@ def copy(self, human_input): if not self.code_blocks: self.console.print("No code blocks to copy.", style=self.console.error_style) else: - pyperclip.copy(self.code_blocks) + pyperclip.copy("\n".join(self.code_blocks)) self.console.print(Panel("✅ Copied code blocks to clipboard.")) return self.CONTINUE diff --git a/tests/test_input.py b/tests/test_input.py index 1b5cd5d..ca24ab7 100644 --- a/tests/test_input.py +++ b/tests/test_input.py @@ -4,7 +4,7 @@ from io import StringIO from pathlib import Path from tests.conftest import in_temp_directory -import pytest, textwrap +import pyperclip, pytest, textwrap class MockConsole: @@ -88,3 +88,14 @@ def test_apply_subcommand(chat, temp_git_repo): # Check if the file was properly modified assert "It is now even better!" in mod_file.read_text() + + +def test_copy_subcommand(chat, temp_git_repo): + with in_temp_directory(temp_git_repo.working_dir): + # Add the patch to the chat (simulating it coming in from the LM response) + chat.code_blocks = ["code block 1", "code block 2"] + + # Apply the patch using the /apply command + assert chat.parse_human_input("/copy") == chat.CONTINUE + + assert pyperclip.paste() is "\n".join(chat.code_blocks)