Skip to content

Copy text from the Files viewer and diffs - #18

Open
VedangP57 wants to merge 2 commits into
mainfrom
feat/copy-in-viewers
Open

VedangP57 wants to merge 2 commits into
mainfrom
feat/copy-in-viewers

Conversation

@VedangP57

Copy link
Copy Markdown
Owner

What

  • Drag over lines in the Files viewer or a History/Changes diff to select them; releasing the mouse copies them to the clipboard (OSC 52, the same route y/Y already use for SHAs) and shows "Copied N lines".
  • The copied text is the file's own lines: no line numbers, no +/- markers, no hunk headers, no padding. Wrapped lines copy as one line and sideways-scrolled lines copy whole. In split view only the half the drag started on is copied.
  • In the Changes diff, only a drag that starts on the text selects; a drag on the line-number gutter still stages lines. Double-click still opens the editor.
  • y copies the selection (Files viewer with no selection: the whole file; diffs with no selection: the v range, else the line under the cursor). Y copies the file's path. In the Files tree y/Y copy the entry's relative/absolute path. History's commit and file lists keep y/Y for the SHA.
  • A masked secret file is never copied: drag selects nothing and y says to reveal it first (v). Y (the path) still works.
  • Copies are capped at 1 MiB and the toast says when one was cut. Esc clears the selection.

Tests

cargo test --workspace (937 passed) and clippy are clean. New unit tests for the text extraction, render/mouse tests for drag, copy, Esc, gutter staging, split halves, wrapping, sideways scroll, double-click and masked secrets, and a keymap test. In a pty, real mouse drags sent to the release binary produced OSC 52 payloads whose decoded text was exactly the selected lines.

Not verified

Kitty itself (that the payload reaches the macOS clipboard, and how the highlight looks), and behaviour inside herdr or tmux (tmux needs set-clipboard on).

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.

1 participant