brokk icon indicating copy to clipboard operation
brokk copied to clipboard

Enable Copy / Paste of any ContextFragment as a native fragment (no text-downgrading)

Open lutzleonhardt opened this issue 7 months ago • 0 comments

Feature Request: Enable Copy / Paste of any ContextFragment as a native fragment (no text-downgrading)


Problem

When I copy a fragment from an earlier context and paste it into the top-context, it is always downgraded to a Paste/TextFragment.
This strips the original fragment type and all rich metadata (file refs, search refs, etc.).

Fragment type Expected after paste Actual after paste
FileFragment FileFragment (keeps refs) OK today (via Edit File)
SearchFragment SearchFragment (keeps refs) Becomes TextFragment
CodeFragment CodeFragment (keeps refs) Becomes TextFragment
DiffFragment DiffFragment (keeps refs) Becomes TextFragment
Any custom Fragment Same type Becomes TextFragment

The only workaround is to re-capture the fragment, which breaks flow and loses history.


User Impact

  • Lost metadata: File or symbol refs disappear, making follow-up actions harder.

  • Extra clicks: Users must rerun searches or recapture code that already exists.

  • Context drift: Original fragment semantics are lost, hurting review and traceability.


Proposed Solution

  1. Native Copy:

    • Add “Copy as Fragment” to every fragment’s context menu.

    • The clipboard entry carries the Fragment object (e.g. via a custom MIME/DataFlavor).

  2. Smart Paste:

    • When pasting, detect the MIME/DataFlavor.

    • If it’s a Fragment type we support, insert it as-is (keeping refs, diff metadata, etc.).

    • Fallback to plain-text paste if the receiving context does not understand the flavor.

  3. Optional dual-action buttons (nice-to-have):

    • “Add fragment” – paste full fragment with refs.

    • “Add refs only” – paste a lightweight reference node without the heavy payload.

  4. Shared Transferable Interface:

    public interface FragmentTransferable extends Transferable {
        DataFlavor FRAGMENT_FLAVOR = new DataFlavor(Fragment.class, "application/x-brokk-fragment");
        @Override DataFlavor[] getTransferDataFlavors();
        @Override Object getTransferData(DataFlavor flavor);
    }
    

    All fragment types implement this once; no duplication.


Acceptance Criteria

  • Copying any fragment places a FragmentTransferable on the clipboard with FRAGMENT_FLAVOR.

  • Pasting into the top-context recognizes the flavor and inserts an identical fragment instance (type, refs, metadata preserved).

  • Plain-text paste still works in editors or apps that don’t understand our MIME type.

  • FileFragment workflow (“Edit File”) remains unchanged and still works as today.


Reference discussion: internal Slack thread 28 May 2025 11:19 (Jonathan E. ↔ Lutz L.).

lutzleonhardt avatar May 28 '25 21:05 lutzleonhardt