Skip to content

Comments

fix(web): harden clipboard copy and terminal paste flows#187

Merged
tiann merged 4 commits intotiann:mainfrom
gaius-codius:split/pr185-clipboard-terminal
Feb 19, 2026
Merged

fix(web): harden clipboard copy and terminal paste flows#187
tiann merged 4 commits intotiann:mainfrom
gaius-codius:split/pr185-clipboard-terminal

Conversation

@gaius-codius
Copy link
Contributor

@gaius-codius gaius-codius commented Feb 18, 2026

Summary

This PR improves copy/paste behavior across desktop + mobile contexts and clarifies copy intent in file view.

Why

  • clipboard APIs fail in common environments (permissions, insecure context, mobile webview constraints)
  • terminal paste needed a clear fallback path when direct clipboard reads are unavailable
  • file view needed clearer distinction between "copy path" and "copy file content"

Scope

Clipboard reliability

  • upgrade safeCopyToClipboard:
    • try modern navigator.clipboard.writeText
    • fallback to legacy document.execCommand('copy') strategy
    • preserve selection/focus where possible
    • throw explicit failure only after both paths fail

Terminal paste UX

  • add explicit Paste action in terminal quick input area
  • when clipboard read works, inject text directly
  • if clipboard read fails, open manual paste dialog
  • guard against empty clipboard values (no fallback dialog spam)
  • keep terminal focus and modifier reset behavior consistent

File view copy clarity

  • keep path copy action in file header row
  • move file-content copy action into file content block
  • only enable file-content copy for safe cases:
    • successful file read
    • non-binary content
    • non-empty content
    • size <= 1,000,000 bytes

i18n

  • add terminal paste labels/strings in en and zh-CN

Files touched

  • web/src/lib/clipboard.ts
  • web/src/routes/sessions/terminal.tsx
  • web/src/routes/sessions/file.tsx
  • web/src/lib/locales/en.ts
  • web/src/lib/locales/zh-CN.ts

Validation

  • bun run typecheck
  • bun run test:web

Test coverage added in this PR

  • Added web/src/lib/clipboard.test.ts
  • Added web/src/routes/sessions/terminal.test.tsx
  • Covers:
    • clipboard writeText success path
    • execCommand fallback when writeText fails
    • explicit error when both copy strategies fail
    • terminal paste behavior for empty clipboard value
    • terminal fallback modal when clipboard read throws

Validation run (successful)

  • bun run typecheck:web
  • bun run test:web

Both commands executed after test additions and passed.

@gaius-codius gaius-codius changed the title fix(web): clipboard + terminal paste fixes (split from #185) fix(web): harden clipboard copy and terminal paste flows Feb 18, 2026
@gaius-codius
Copy link
Contributor Author

Hi Team, I understand you prefer to open an issue first before adding features but these are changes I’ve worked on for my own setup and thought I would share.
This is a fantastic project and has helped me and my workflow immensely.
I have tried to keep the PRs narrow, open to any and all suggestions and comments.

@gaius-codius gaius-codius marked this pull request as ready for review February 18, 2026 23:22
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Findings

  • None.

Summary

  • No issues found in diff. Residual risk: file-content copy gating tests not found in repo.

Testing

  • Not run (automation)

HAPI Bot

@tiann tiann merged commit 77cfa71 into tiann:main Feb 19, 2026
2 checks passed
Unintendedz pushed a commit to Unintendedz/hapii that referenced this pull request Feb 19, 2026
Lihengwannafly pushed a commit to Lihengwannafly/hapi that referenced this pull request Feb 19, 2026
jasonczc pushed a commit to jasonczc/haqi that referenced this pull request Feb 19, 2026
@gaius-codius gaius-codius deleted the split/pr185-clipboard-terminal branch February 19, 2026 09:35
doraemonkeys pushed a commit to doraemonkeys/hapi that referenced this pull request Feb 20, 2026
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.

2 participants