Skip to content

feat(file-preview): drag-range selection + right-click handoff to terminals & agent#17

Merged
iptoux merged 9 commits into
mainfrom
feat/code-preview-drag-handoff
May 22, 2026
Merged

feat(file-preview): drag-range selection + right-click handoff to terminals & agent#17
iptoux merged 9 commits into
mainfrom
feat/code-preview-drag-handoff

Conversation

@iptoux
Copy link
Copy Markdown
Contributor

@iptoux iptoux commented May 22, 2026

Summary

Extends the CodeView file preview with drag-based line range selection and a right-click context menu that ships the highlighted snippet to any terminal in any workspace, attaches it to any workspace's BLXCode Agent context, or copies it to the clipboard. Cross-workspace handoffs prefix the snippet header with the source workspace label so the receiving agent can disambiguate.

Highlights

  • Drag selection in code_view.rs: mousedown → mousemove extends selected: Option<(usize, usize)>; a window-level mouseup listener (installed once, cleaned up via on_cleanup) ends drags even when the cursor leaves the gutter. Single-click toggle preserved. .code-view got user-select: none.
  • Right-click context menu (new module file_preview/code_context_menu.rs) with four sections, all grouped per workspace:
    • Snippet → Insert into terminal — fenced markdown block written verbatim via pty_write (base64).
    • Full context block → Insert into terminal — same snippet wrapped in the standard ⟪ BLXCode attached context ⟫ envelope.
    • Snippet → Attach to agentupsert_workspace_agent_context with new AgentContextKind::FileSnippet carrying inline content.
    • Clipboard — copy snippet / line range / raw text via navigator.clipboard.writeText with toast feedback.
  • Cross-workspace support: new helper list_terminal_targets_all_workspaces enumerates every workspace's live terminals (shell workspaces filtered via existing is_shell_workspace), with the preview's own workspace pinned to the top and tagged with a localized current badge.
  • Snippet builders: build_file_snippet_block in util.rs (clamped + UTF-8 safe, 6 unit tests) and render_file_snippet_envelope in agent_context_handoff.rs (2 unit tests covering same-workspace and cross-workspace headers).
  • Wire protocol: AgentContextItem gained an optional content: Option<String> field on both src/agent_wire.rs and src-tauri/src/agent/protocol.rs; backend render_context_prompt partitions FileSnippet items into a dedicated `Attached file snippets` prompt section; render_agent_context_block mirrors this with an `## Attached file snippets` section.
  • i18n: 22 new keys (CodeViewMenu*, CodeViewToast*) with real translations in all 13 locales (en, de, fr, es, it, pt_br, pl, hu, ru, ja, ko, zh_cn, zh_tw) using `{workspace}`, `{terminal}`, `{slot}`, `{agent}`, `{error}` placeholders.
  • CSS: .code-context-menu themed via existing tokens (sections, workspace groups, slot sublists, accent-pill badge, themed hover via --overlay-2).
  • Docs: docs/user/file-preview.md and CHANGELOG.md updated; plan tracked in .agents/plans/file-browser-rich-preview.md + .cursor/plans/code-preview-drag-select-handoff_f50216bd.plan.md.

Test plan

  • `cargo check -p blxcode-ui --target wasm32-unknown-unknown` clean
  • `cargo check -p blxcode` clean
  • `cargo test --workspace` — 53 tests pass, including 8 new ones:
    • 6 × build_file_snippet_block_* (single/range/cross-workspace/no-lang/UTF-8/clamping)
    • 2 × render_file_snippet_envelope_* (in-workspace + cross-workspace source marker)
    • 3 × file_snippet_* constructors + render section
  • Manual verification with `cargo tauri dev`:
    • Drag a multi-line range; verify continuous highlight across drag direction (both up & down)
    • Right-click inside vs outside current selection (re-selects single line when outside)
    • Insert snippet → same-workspace terminal and cross-workspace terminal; verify `source workspace:` header appears only on the cross case
    • Insert full envelope → cross-workspace terminal; verify Session block lists target workspace, snippet block lists source workspace
    • Attach to agent → preview workspace and a different workspace; verify Agent panel context list shows `Snippet · path:start-end`
    • Copy snippet/range/raw; verify toast appears in every locale
    • Right-click in `.txt` / `.log` (Text variant) — menu works without syntax highlighting
    • Switch active locale to each of the 13 languages — every section header, group label, slot label, and toast renders in that language
    • `Escape` and outside-click both close the menu

Made with Cursor

iptoux added 6 commits May 22, 2026 21:19
…er handling

Refactored the Git graph implementation to replace the swim-lane layout with a native `git log --graph` representation. Updated the data structures to use `GitGraphEntry` for better clarity and streamlined the fetching of commit data. Improved gutter handling for better alignment and visual consistency in the sidebar. This change enhances the overall user experience by providing a more accurate representation of commit relationships.
Added support for previewing various file types including images, videos, Markdown, and Mermaid diagrams. Introduced a new `FilePreviewHeader` component to display file metadata such as name, path, size, and modification time. Enhanced the Markdown renderer to support inline Mermaid blocks and improved the overall user experience with loading states and error handling. Updated internationalization keys for new features across multiple languages.
… error handling and internationalization

Completed the implementation of the file preview feature, supporting images, videos, Markdown, and Mermaid diagrams. Introduced a structured error handling system using `FilePreviewError` to provide user-friendly messages for various failure scenarios. Updated internationalization keys across multiple languages to reflect new error messages and improved user experience. Marked the file browser rich preview as active in the plans documentation.
…ers and documentation

Expanded the file preview feature to support rich previews for images, videos, Markdown, and Mermaid diagrams. Introduced a new topbar displaying file metadata and improved error handling for unsupported file types. Updated documentation to include a dedicated section for file previews and added screenshots for better user guidance. Included internationalization updates for new keys across all supported languages.
…ew with line numbers and syntax highlighting

Added a new `CodeView` component to the file preview feature, enabling a two-column layout for source code files with line numbers and syntax highlighting using highlight.js. This update allows users to select specific lines for reference, improving the usability of code previews. The implementation includes support for various programming languages and integrates with existing file preview functionalities. Updated styles and documentation to reflect these changes, along with new unit tests for the CodeView component.
…ght-click context menu

Introduced drag-range selection in the `CodeView`, allowing users to select multiple lines by clicking and dragging. A new right-click context menu provides options to insert snippets into terminals, attach to agents, and copy content to the clipboard. This update improves usability by enabling quick access to actions based on selected code lines. Additionally, 22 new internationalization keys were added to support these features across 13 locales, along with corresponding updates to styles and documentation.
@iptoux iptoux added enhancement New feature or request review Ticket/Steps need to be review/tested wip Work in progress labels May 22, 2026
@iptoux iptoux self-assigned this May 22, 2026
iptoux and others added 3 commits May 22, 2026 22:50
…and FileSnippet handoff

Brings the developer architecture doc up to date with the new
CodeView selection model (Option<(usize, usize)> + window-level
mouseup), the code_context_menu module, build_file_snippet_block,
render_file_snippet_envelope, list_terminal_targets_all_workspaces,
the AgentContextItem.content field + FileSnippet kind, and the
backend prompt-renderer section for inline file snippets.

Co-authored-by: Cursor <cursoragent@cursor.com>
…ed performance

Modified the terminal grid behavior to remain mounted throughout the workspace's lifecycle, only hidden when a different center tab is active. This change prevents the termination of running agents and maintains the integrity of the PTY registry, enhancing user experience by ensuring terminals remain accessible across tab switches.
…components

Updated file preview components (CodeView, ImageView, MarkdownView, MermaidView, VideoView) to use `with_untracked` for workspace retrieval, ensuring that the file previews only refetch on explicit reload ticks. This change prevents unnecessary re-fetching and remounting during tab switches, enhancing performance and user experience across the file preview feature.
@iptoux iptoux merged commit d67ea63 into main May 22, 2026
1 check passed
@iptoux iptoux deleted the feat/code-preview-drag-handoff branch May 22, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request review Ticket/Steps need to be review/tested wip Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant