diff --git a/src/main.py b/src/main.py index 6fdfca3..07e5ba0 100644 --- a/src/main.py +++ b/src/main.py @@ -109,7 +109,6 @@ async def main(): # Copy button with ui.row().classes('w-full justify-end q-gutter-sm'): copy_button = ui.button('Copy to Clipboard', icon='content_copy').props('outline') - copy_button.disable() # Action buttons with ui.card().classes('w-full'): @@ -136,8 +135,24 @@ async def main(): def update_char_count(): char_count_label.text = f'{len(input_text.value)} characters' - def mock_copy(): - ui.notify('Text copied to clipboard (mockup)', type='positive') + async def copy_to_clipboard(): + if output_text.value: + await ui.run_javascript(f''' + navigator.clipboard.writeText({repr(output_text.value)}).then(() => {{ + // Success handled by notify below + }}).catch(() => {{ + // Fallback for older browsers + const textArea = document.createElement('textarea'); + textArea.value = {repr(output_text.value)}; + document.body.appendChild(textArea); + textArea.select(); + document.execCommand('copy'); + document.body.removeChild(textArea); + }}); + ''') + ui.notify('Text copied to clipboard!', type='positive') + else: + ui.notify('No text to copy', type='warning') def clear_all(): input_text.value = '' @@ -150,7 +165,7 @@ async def main(): # Connect event handlers input_text.on('input', update_char_count) - copy_button.on_click(mock_copy) + copy_button.on_click(copy_to_clipboard) clear_button.on_click(clear_all) # Footer