Skip to content

feat(preview): add inline code copy action - #1359

Merged
perber merged 5 commits into
perber:mainfrom
happykawayigt:feat/inline-code-copy
Aug 9, 2026
Merged

feat(preview): add inline code copy action#1359
perber merged 5 commits into
perber:mainfrom
happykawayigt:feat/inline-code-copy

Conversation

@happykawayigt

@happykawayigt happykawayigt commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a compact copy action to inline code that appears on hover or keyboard focus
  • reuse shared clipboard and feedback behavior for inline and fenced code
  • prevent the copy action from activating surrounding links or click handlers
  • cover successful copies, failures, temporary feedback, and event isolation

Validation

  • targeted preview tests: 8 passed
  • npm run build
  • npm run lint
  • git diff --check
  • full npm test -- --run: 284 passed, 1 failed in HotKeyHandler.test.tsx; the same full-suite-only failure reproduces on a clean latest main (280 passed, 1 failed), while that test passes in isolation

Fixes #1358

AI assistance: Codex was used to help investigate, implement, and test this change.

@perber

perber commented Jul 31, 2026

Copy link
Copy Markdown
Owner

@happykawayigt Thanks, have you checked the UI. A short manual test?

@perber

perber commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Could you rebase.

@happykawayigt
happykawayigt force-pushed the feat/inline-code-copy branch 2 times, most recently from 37eb95c to 3c5e37d Compare July 31, 2026 17:26
@perber

perber commented Jul 31, 2026

Copy link
Copy Markdown
Owner

I checked, the design it looks different to the codeblock, the tooltip, ...
Could you fix it?

@happykawayigt
happykawayigt force-pushed the feat/inline-code-copy branch 2 times, most recently from 4355bba to 2a49d11 Compare July 31, 2026 23:36
@happykawayigt

Copy link
Copy Markdown
Contributor Author

Fixed in 2a49d11. I aligned the inline control with the fenced-code control by reusing TooltipWrapper and the same border, background, foreground, and hover styling while keeping the compact inline size.

Manual UI check: I rendered inline and fenced code together through the real MarkdownPreview, verified the inline control appears on hover, the tooltip says “Copy code”, and clicking changes the accessible label to “Code copied”. The targeted preview tests (8), lint, and build all pass.

@happykawayigt
happykawayigt marked this pull request as ready for review August 1, 2026 16:24
@happykawayigt
happykawayigt requested a review from perber as a code owner August 1, 2026 16:24
@perber

perber commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Hi @happykawayigt,

Thanks again! It looks already pretty good, but I think it is better, when no padding is on the right side.
The inline code is position: relative and the click button is absolute positioned as in the code block.

image

As the copy button is only visible on hover I think it is ok to overlap the content with the button.

@perber perber left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

see above comment

@happykawayigt
happykawayigt force-pushed the feat/inline-code-copy branch from 2a49d11 to 773769b Compare August 3, 2026 12:01
Use --radius-sm instead of an off-scale 0.125rem (no existing token is
that small) and add the opacity transition the app's other hover-reveal
control (headline anchors) already uses, so the button doesn't pop in/out.
@perber

perber commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Ran the copy button through a design-consistency check against the app's existing patterns (fenced-code copy button, headline-anchor hover-reveal) and pushed a small follow-up commit (ceaa93d1):

  • border-radius: 0.125remvar(--radius-sm) — 0.125rem isn't on the app's radius scale (--radius-sm: 0.25rem / --radius-md: 0.375rem / --radius-lg: 0.5rem); next to the fenced-code button's clearly rounded corners the inline one read as noticeably sharper.
  • Added transition: opacity 200ms — the only other hover-reveal control in the app (headline anchors) fades in with transition-opacity duration-200; the inline copy button was popping in/out instantly.

Left the icon-overlapping-text-on-hover behavior as-is (not adding extra margin/padding for it). Everything else — clipboard/toast reuse, color tokens, icons — already matched house conventions well.

(Also ran into a pre-existing, unrelated bug while testing — inline code spans rendering with literal backticks — confirmed it reproduces on main too, so it's not from this PR. Logged separately, not something to fix here.)

@perber
perber self-requested a review August 9, 2026 16:06
@perber
perber merged commit 8e56dce into perber:main Aug 9, 2026
9 checks passed
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.

Feature Request: Add a copy button to inline code

2 participants