Skip to content

[Bug]: Triple-clicking the last line of a code block copies Markdown fences #8042

Description

@jinrehacek

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/desktop

Steps to reproduce

  1. Open a conversation containing a fenced code block with two or more lines:
    cd ~/dotfiles
    sudo dnf remove niri xwayland-satellite alacritty
  2. Triple-click the final line to select it.
  3. Press Ctrl+C.
  4. Paste into a terminal or plain-text editor.

The same problem occurs when triple-clicking the only line in a single-line code block (as it's also the last line).
For comparison, triple-clicking a non-final line copies plain text correctly.

Expected behavior

Only the selected command is copied:

sudo dnf remove niri xwayland-satellite alacritty

Actual behavior

The selected command is wrapped in a Markdown fence and language identifier, thus clipboard stores this:

```bash
sudo dnf remove niri xwayland-satellite alacritty
```

Impact

Minor bug or occasional failure

Version or commit

0.0.34-nightly.20260823.1170

Environment

Fedora, Sway WM, Desktop app via AppImage (it happens in web too tho)

Logs or stack traces

Screenshots, recordings, or supporting files

No response

Workaround

Drag-select the command without including the final line boundary, or use the code block's Copy button.

Related issue

This appears to be a remaining edge case of #4741, which was closed by #5069. The fix works for ordinary partial selections, but triple-clicking the final line still reproduces the original fenced-copy behavior on a nightly containing that fix.

Investigation

chatMarkdownClipboardPayload copies plain text when the selection's common ancestor is inside <pre>.

Triple-clicking the final line appears to include the code block's trailing boundary. A minimized DOM Range with that shape has the outer Markdown container as its common ancestor. cloneContents() then produces a partial wrapper containing <pre>, which the Markdown serializer converts back into a fenced block.

This also explains the observed difference:

  • Triple-clicking a middle line keeps the range inside <pre> and copies plain text.
  • Triple-clicking the final or only line crosses the trailing boundary and copies fenced Markdown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken or behaving incorrectly.needs-triageIssue needs maintainer review and initial categorization.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions