Skip to content

feat(terminal): copy the selection to the clipboard - #5642

Closed
diallosouleymane wants to merge 3 commits into
Dokploy:canaryfrom
diallosouleymane:fix/terminal-copy-on-select
Closed

diallosouleymane wants to merge 3 commits into
Dokploy:canaryfrom
diallosouleymane:fix/terminal-copy-on-select

Conversation

@diallosouleymane

@diallosouleymane diallosouleymane commented Oct 10, 2026 •

Copy link
Copy Markdown

What is this PR about?

Selecting output in the Docker terminal left no way to copy it, so the only way to get a line out of the browser was retyping it or taking a screenshot. Ctrl+C has to keep sending SIGINT, Ctrl+Shift+C is reserved by browsers for DevTools and never reaches the page, and the ClipboardAddon already loaded only implements OSC 52, a copy requested by the remote program. The selection is now copied when the drag ends, the way a Unix terminal has done since X11's primary selection, and a toast confirms it. The selection itself is left in place, because a copy that erases what you highlighted gives no way to tell it apart from a copy that did nothing. The web server terminal gets the same treatment, it shared the gap.

Three details worth a reviewer's attention. The release is caught on the document rather than on the terminal element, because reaching the end of a line means dragging past its edge and that release lands elsewhere. Reading the selection waits a tick, because xterm settles it in its own mouseup handler, registered on the document when the drag starts and therefore after this one. And navigator.clipboard only exists on a secure context, while many instances are reached over plain HTTP on an IP before a domain is set up, so execCommand remains as a fallback and restores the focus it takes from the terminal.

Checklist

Before submitting this PR, please make sure that:

  • You created a dedicated branch based on the canary branch.
  • You have read the suggestions in the CONTRIBUTING.md file https://github.com/Dokploy/dokploy/blob/canary/CONTRIBUTING.md#pull-request
  • You have tested this PR in your local instance. If you have not tested it yet, please do so before submitting. This helps avoid wasting maintainers' time reviewing code that has not been verified by you.

Tested on a local instance running this branch, against a real container opened from /dashboard/docker: selecting output copies it, the toast appears, the selection stays, and pasting elsewhere returns the selected text. An earlier version of this patch listened on the terminal element and copied only intermittently, which is what led to the two details above.

Issues related (if applicable)

closes #5640

Screenshots (if applicable)

image

Selecting output in the Docker terminal left no way to copy it. Ctrl+C has
to keep sending SIGINT, Ctrl+Shift+C is reserved by browsers for DevTools and
never reaches the page, and the ClipboardAddon already loaded only implements
OSC 52, a copy requested by the remote program.

The selection is now copied when the drag ends, the way a Unix terminal has
done since X11's primary selection, and a toast confirms it. The selection
itself is left in place: a copy that erases what you highlighted gives no way
to tell it apart from a copy that did nothing.

The release is caught on the document rather than on the terminal, because
reaching the end of a line means dragging past its edge, and reading the
selection waits a tick, because xterm settles it in its own mouseup handler
registered after this one.

navigator.clipboard only exists on a secure context, and many instances are
reached over plain HTTP on an IP before a domain is set up, so execCommand
remains as a fallback. It restores the focus it takes from the terminal.

The web server terminal gets the same treatment, it shared the gap.
Comment thread apps/dokploy/lib/terminal-clipboard.ts Outdated
Both terminals open inside a modal dialog. Its focus trap pulls the focus
back in as soon as something outside takes it, and selecting a textarea
focuses it, so a textarea appended to the body lost its selection before
execCommand could read it. On a plain HTTP instance, where the clipboard API
does not exist, selecting output therefore copied nothing.

@narcisonunez narcisonunez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove all the unnecessary comments. No need for them

@diallosouleymane

Copy link
Copy Markdown
Author

@narcisonunez Done in 190e769, all the comments added by this PR are gone.

@narcisonunez

Copy link
Copy Markdown
Collaborator

Will check again soon, thanks

@imrja8

imrja8 commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for working on this. Closing it, as I couldn't reproduce #5640.

Why I don't think this PR should be merged:

  • It copies every selection on mouse release, on every OS, including macOS, where Cmd+C already works.
  • Not every selection is meant to be copied, people highlight text to read it, point at something, or select it by accident.
  • Each of those will automatically overwrites the user's clipboard.
  • VS Code and Windows Terminal keep copy-on-select off by default for this reason.

If discoverability is the real problem, a "Copy selection" button or an opt-in setting would be a better fix.

@imrja8 imrja8 closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker terminal: a selection cannot be copied to the clipboard on Linux/Windows

3 participants