Skip to content

Commit 10e5da2

Browse files
committed
Fix clipboard copy from chat input area: handle TextArea selection and show toast on copy
1 parent 574e7b9 commit 10e5da2

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎albert_code/cli/clipboard.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import pyperclip
1010
from textual.app import App
11+
from textual.widgets import TextArea
1112

1213
_PREVIEW_MAX_LENGTH = 40
1314

@@ -128,6 +129,12 @@ def _get_selected_texts(app: App) -> list[str]:
128129
selected_texts = []
129130

130131
for widget in app.query("*"):
132+
if isinstance(widget, TextArea):
133+
selected_text = widget.selected_text
134+
if selected_text and selected_text.strip():
135+
selected_texts.append(selected_text)
136+
continue
137+
131138
if not hasattr(widget, "text_selection") or not widget.text_selection:
132139
continue
133140

‎albert_code/cli/textual_ui/app.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ async def _check_update(self) -> None:
16831683
)
16841684

16851685
def action_copy_selection(self) -> None:
1686-
copied_text = copy_selection_to_clipboard(self, show_toast=False)
1686+
copied_text = copy_selection_to_clipboard(self, show_toast=True)
16871687
if copied_text is not None:
16881688
self.agent_loop.telemetry_client.send_user_copied_text(copied_text)
16891689

‎tests/cli/test_copy_shortcuts.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def test_ctrl_y_triggers_copy_selection() -> None:
1717
) as mock_copy:
1818
async with app.run_test() as pilot:
1919
await pilot.press("ctrl+y")
20-
mock_copy.assert_called_once_with(app, show_toast=False)
20+
mock_copy.assert_called_once_with(app, show_toast=True)
2121

2222

2323
@pytest.mark.asyncio
@@ -30,7 +30,7 @@ async def test_ctrl_shift_c_triggers_copy_selection() -> None:
3030
) as mock_copy:
3131
async with app.run_test() as pilot:
3232
await pilot.press("ctrl+shift+c")
33-
mock_copy.assert_called_once_with(app, show_toast=False)
33+
mock_copy.assert_called_once_with(app, show_toast=True)
3434

3535

3636
@pytest.mark.asyncio

0 commit comments

Comments
 (0)