Skip to content

Conversation

mrfandu1
Copy link

@mrfandu1 mrfandu1 commented Jul 14, 2025


name: Feature Added
about: Added Copy Buttons for per-line Text and Codeblock

Summary of Changes

This PR implements line-by-line copy functionality for AI responses in the AskView component, addressing the need to copy individual lines instead of entire response blocks.

Key Features Added:

  • Dynamic Copy Button: Appears next to text lines on hover for precise line copying
  • Smart Positioning: Automatically adjusts position for list items, nested content, and regular text
  • Persistent Visibility: Button remains visible at last position after mouse leaves text
  • Visual Feedback: Highlights hovered line and shows copy confirmation with icon animation
  • Performance Optimized: Uses Map-based timeout management and element caching

Related Issue

This change addresses the workflow friction described in issue #102 where users needed to copy specific lines from AI responses but were forced to copy entire blocks, making line-by-line iteration for debugging, shell commands, or documentation unnecessarily difficult.

Contributor's Self-Review Checklist

Please check the boxes that apply. This is a reminder of what we look for in a good pull request.

  • [✔] I have read the CONTRIBUTING.md document.
  • [✔] My code follows the project's coding style and architectural patterns as described in DESIGN_PATTERNS.md.
  • [✔] I have added or updated relevant tests for my changes.
  • [✔] I have updated the documentation to reflect my changes (if applicable).
  • [✔] My changes have been tested locally and are working as expected.

Additional Context (Optional)

Technical Implementation Details:

New Features:

  1. Dynamic Copy Button System:

    • Automatically positions copy buttons next to text elements on hover
    • Handles different content types (paragraphs, headings, list items, blockquotes)
    • Smart positioning logic prevents conflicts with bullet points and nested content
  2. Optimized Performance:

    • Map-based timeout management for better memory handling
    • Element caching to reduce DOM queries
    • Passive event listeners for improved scroll performance
  3. Enhanced UX:

    • Button persists at last position (no more chasing disappearing buttons)
    • Visual feedback with text highlighting and icon animations
    • Proper pointer cursor behavior

Code Architecture:

  • Follows existing LitElement patterns
  • Uses CSS custom properties for consistent styling
  • Implements proper cleanup in disconnectedCallback()
  • Maintains backward compatibility with existing copy functionality

Testing Notes:

  • Tested with various content types (code blocks, lists, paragraphs)
  • Verified positioning accuracy across different text structures
  • Confirmed proper cleanup and memory management
  • Validated accessibility with keyboard navigation
pr2.mp4
pr1.mp4

@mrfandu1 mrfandu1 changed the title Add per-line copy button for AI response Added per-line copy button for AI response Jul 14, 2025
@mrfandu1
Copy link
Author

@samtiz @jhyang0 Please review this PR, and lemme know if any other changes required

@tarsyang
Copy link
Contributor

Nice! I'll review it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy AI Response Line by Line Instead of Full Block
3 participants