Skip to content

[Bug]: Code block copy button adds trailing newline(s), so a pasted one-line command becomes multi-line #37268

Closed

Description

@mzijlstra-hia

Area

apps/web: chat markdown code blocks

Steps to reproduce

  1. Get an assistant reply with a one-line fenced shell block, e.g. sudo pacman -S patchelf.
  2. Click the code block's copy button.
  3. Inspect the clipboard: wl-paste | od -c.

Expected behavior

The clipboard holds the command without a trailing newline (sudo pacman -S patchelf), so pasting a single-line command gives a single-line command.

Actual behavior

The clipboard holds sudo pacman -S patchelf\n\n. Shells with a multi-line editor (ble.sh, also fish and zsh with bracketed paste) then treat the pasted command as multi-line: Enter inserts a newline instead of running it, and you have to use the "run" key (C-j in ble.sh) instead.

MarkdownCodeBlock.tsx copies the fence text exactly as given, and that text always ends in \n:

const handleCopy = () => copyToClipboard(code);

(The run-in-terminal check a few lines above even relies on code.endsWith("\n").)

Suggested fix: copy code.replace(/\n+$/, ""), keeping the raw code for the run-in-terminal path.

Impact

Every copied one-line command needs an extra keystroke, or the trailing newline deleted by hand, in shells that support multi-line editing.

Version or commit

v0.1.9 (AppImage). Still present on main as of a621be8.

Environment

Arch Linux, Hyprland (Wayland), foot + bash with ble.sh.

Workaround

A ble.sh Enter binding that strips trailing newlines before accepting the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions