Skip to content

Conversation

@JakeSCahill
Copy link
Contributor

@JakeSCahill JakeSCahill commented Nov 18, 2025

This pull request adds a new "Ask AI" feature to code blocks in documentation, allowing users to quickly query Kapa AI for code explanations. It also refines the UI/UX for the existing "Copy" functionality and improves the styling and positioning of toolbox elements for better accessibility and visual feedback.

New Feature: Ask AI Integration

  • Added an "Ask AI" button to code blocks (when Kapa is available), which opens Kapa AI with a prompt to explain the selected code snippet. This includes a sparkles SVG icon and event handler for user interaction. [1] [2]

UI/UX Improvements for Toolbox Buttons

  • Changed .copy-button and new .ask-ai-button to use inline-flex for better alignment and interaction, and added hover effects for both SVG and image icons for improved feedback. [1] [2]
  • Enhanced the appearance and positioning of the copy toast notification, including absolute positioning, pointer events handling, and a visually improved arrow indicator.

Code Refactoring

  • Cleaned up and streamlined code block normalization and button creation logic in src/js/06-copy-to-clipboard.js for maintainability. [1] [2]
2025-11-18_11-43-49.mp4

@netlify
Copy link

netlify bot commented Nov 18, 2025

Deploy Preview for docs-ui ready!

Name Link
🔨 Latest commit dcb305d
🔍 Latest deploy log https://app.netlify.com/projects/docs-ui/deploys/691d761289209a00082df714
😎 Deploy Preview https://deploy-preview-347--docs-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 27 (🔴 down 3 from production)
Accessibility: 93 (no change from production)
Best Practices: 100 (no change from production)
SEO: 89 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request adds an "Ask AI" feature to documentation code blocks and restructures the copy button UI styling. The JavaScript implementation introduces a handleAskAI() function that extracts code from blocks, formats a prompt, and opens Kapa AI when available. The CSS changes restructure the copy button from vertical to inline-flex layout, reposition the copy-toast with absolute positioning, add hover effects to copy icons, and introduce new styles for an Ask AI button with icon and hover interactions. The feature only appears when Kapa AI is available and is skipped for suppressed code blocks.

Sequence Diagram

sequenceDiagram
    actor User
    participant Page
    participant JavaScript
    participant KapaAI

    User->>Page: Page loads with code block
    JavaScript->>JavaScript: Check if Kapa AI available
    alt Kapa AI Available
        JavaScript->>Page: Create Ask AI button + icon
        JavaScript->>Page: Append to code toolbox
        Note over Page: Ask AI button visible
    else Kapa AI Not Available
        Note over JavaScript: Skip button creation
    end

    User->>Page: Click Ask AI button
    JavaScript->>JavaScript: Extract code from block
    JavaScript->>JavaScript: Format prompt<br/>(remove $, handle continuations)
    JavaScript->>KapaAI: Open with mode: ai + query
    Note over KapaAI: Kapa AI processes query
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • CSS restructuring: The copy-button layout change from vertical flex to inline-flex and copy-toast repositioning to absolute positioning require careful verification of visual alignment and pointer targeting
  • handleAskAI() implementation: The code extraction logic (removing "$ " prefix and line continuations) and Kapa AI integration need review for edge cases and correctness
  • Conditional feature availability: Verify that the Ask AI button is only created when Kapa is available and respects the no-copy suppression flag
  • Event listener wiring: Ensure proper closure context and no memory leaks with the button click handler

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main feature added: an 'Ask AI' option for code blocks, which is the primary change in this pull request.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the Ask AI feature, UI/UX improvements, and code refactoring with specific details and references.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
src/js/06-copy-to-clipboard.js (3)

26-83: Shared tool state looks good; consider future-proofing around no-copy usage

The refactor to share code, lang, copy, toast, askAI, and toolbox and to normalize code blocks is consistent with the existing copy/run behavior and keeps the logic coherent.

One consideration: no-copy now implicitly also disables Ask AI (via the same ancestor class check). If you expect cases where AI should be available even when copying is not (or vice versa), it may be worth splitting this into more explicit flags (for example, no-copy vs no-ai) to avoid overloading one class with multiple meanings.


84-110: Ask AI button wiring is correct; watch for Kapa load timing

The Ask AI button wiring (creation, SVG icon, event handler) looks correct and mirrors the copy button structure, including reuse of the no-copy suppression logic.

One nuance: the button is only created if window.Kapa is truthy at script execution time. If Kapa is injected asynchronously after this script runs, users won’t see the button even though AI eventually becomes available. If that’s a realistic scenario, consider:

  • Always rendering the button and doing the window.Kapa check only on click, or
  • Re-running the toolbox initialization (or toggling visibility) once Kapa finishes loading.

175-195: handleAskAI reuses console normalization; consider preserving visual snippet and enriching prompt

The handler correctly mirrors writeToClipboard behavior: trimming trailing spaces, normalizing console snippets via extractCommands, and then opening Kapa with a Markdown-formatted prompt. This alignment reduces surprises between “copy” and “ask AI”.

Two potential improvements:

  1. Preserve the exact visual snippet for AI
    For console blocks, extractCommands flattens multi-line $ prompts into a single &&-chained command string. That’s great for copying into a shell, but users might expect the AI prompt to match what they see on the page (including $ prompts and line breaks). You could:

    • Use the raw text for Ask AI, or
    • Include both, for example:
    var aiPromptText =
      'Explain this console snippet (shown as run commands below):\n\n' +
      'Original snippet:\n\n```\n' + code.innerText.replace(TRAILING_SPACE_RX, '') + '\n```\n\n' +
      'Commands:\n\n```\n' + extractCommands(text) + '\n```'
  2. Add minimal API robustness
    Before calling kapa.open, consider guarding against unexpected API shape to avoid runtime errors if the integration changes:

    if (kapa && typeof kapa.open === 'function') {
      kapa.open({ mode: 'ai', query: aiPromptText, submit: true })
    } else {
      console.warn('Kapa AI is not available or misconfigured.')
    }

These are non-blocking but would make the integration more resilient and the AI explanation closer to what users see.

src/css/doc.css (2)

1490-1513: Inline-flex copy button + hover transitions look consistent with toolbox layout

Switching .copy-button to inline-flex with position: relative and adding smooth hover transitions for SVG/img icons fits well with the existing .source-toolbox flex layout and supports the new toast positioning.

One thing to keep in mind: both .copy-button and .ask-ai-button set outline: none;, which removes the default keyboard focus indicator. This was already the case for copy, but it now extends to the new AI control as well. If keyboard accessibility is a concern, consider reintroducing a visible focus style (e.g., a focus ring or underline) instead of globally suppressing outline.


1563-1590: Ask AI button/icon styling aligns with copy button; spacing may need fine-tuning

The .ask-ai-button and .ask-ai-icon styles mirror the copy button’s structure and sizing, and the hover color transition on the sparkles path nicely matches the copy icon behavior. This should integrate cleanly into .source-toolbox alongside the language label and run/copy buttons.

If, during visual QA, the icons or separators feel cramped (e.g., “Copy | Ask AI” touching too closely), consider a small horizontal gap or padding between adjacent buttons, but that’s purely cosmetic and can be tuned later.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f4e6812 and b022dff.

📒 Files selected for processing (2)
  • src/css/doc.css (2 hunks)
  • src/js/06-copy-to-clipboard.js (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/css/doc.css (1)

1519-1556: Copy icon hover and toast positioning are well-structured; verify overflow contexts

The new hover styles for SVG and image copy icons, plus the reworked .copy-toast positioning (absolute below the button, centered with a small margin and arrow), make the interaction clearer and avoid pointer interference via pointer-events: none.

Given .source-toolbox is absolutely positioned within .listingblock > .content, the toast should appear just below the icon without disturbing layout. The only thing worth double-checking in the browser is that no ancestor (e.g., the code container) has overflow: hidden that could clip the toast/arrow—especially in narrow viewports or responsive layouts.

Copy link

@micheleRP micheleRP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice!

@JakeSCahill JakeSCahill merged commit 71765d9 into main Nov 19, 2025
6 checks passed
@JakeSCahill JakeSCahill deleted the ask-ai-code branch November 19, 2025 07:49
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.

3 participants