Summary
Add rectangular output selection to Potato with an Alt+left-drag gesture. The standalone patch also includes the Select-to-Copy scheduling correction from #537 so rectangular and ordinary selection do not perform clipboard I/O on every mouse-motion event.
Clean standalone patch: https://github.com/adkins17/potato/commit/410a000f22159111f984e947cbdb77badc64ace8.patch
Patch branch: https://github.com/adkins17/potato/tree/feature/alt-drag-rectangular-selection
Upstream baseline: 46d18387bd6b156b85176fa588a60991cbba6235 (potatomushclient/potato master)
Related correction: #537
Gesture
- Place the pointer in a world output pane.
- Hold Alt.
- Press and hold the left mouse button at one corner of the desired block.
- Drag horizontally and vertically to the opposite corner.
- Release the mouse button to finish the selection.
- Use Potato's normal Copy command or keyboard shortcut to copy the block.
The gesture operates only in PotatoOutput text widgets. Input panes keep their existing bindings, and an ordinary left-button drag continues to make a normal linear selection.
Clipboard result
Each visible display row contributes only the characters inside the selected horizontal bounds. The slices are joined with newline characters in the clipboard. This makes it possible to copy a column, table field, ASCII-art region, or aligned status block without copying the unrelated text between the first and last selected character.
- Text before and after the rectangle is excluded.
- Short lines are clipped at their actual end.
- A short line with no text inside the horizontal bounds contributes an empty row, preserving the visible shape.
- With Select to Copy enabled, the completed rectangle is copied exactly once on mouse release.
- With Select to Copy disabled, the rectangle remains highlighted until Copy, Escape, or a new ordinary selection.
Selection behavior
- Dragging bottom-to-top or right-to-left produces the same rectangle as the opposite direction.
- Wrapped screen rows are handled as separate displayed rows rather than whole logical lines.
- Tk's native pixel hit-testing and font measurements handle proportional fonts, tabs, and ANSI font tags.
- Dragging above or below the output pane autoscrolls in that direction.
- Escape clears the rectangular highlight.
- Starting a normal selection clears rectangular state and restores stock selection behavior.
- Text marks allow a completed rectangle to survive incoming output and scrollback trimming above it.
- Reloading the module does not duplicate widget bindtags or destroy a completed selection.
Performance and correction
The patch includes the diagnosis and correction from #537. Stock Potato currently clears and repopulates the system clipboard for every <<Selection>> event while Select to Copy is enabled. The correction coalesces ordinary selection changes for 125 ms and flushes after mouse release.
Rectangular selection adds two further safeguards:
- mouse-motion redraws are coalesced to approximately one update per 16 ms; and
- each redraw is bounded to at most 2,000 displayed rows.
Queued Tk selection events are deduplicated after release so the same rectangle is not copied twice.
Platform note
Some Linux window managers reserve Alt+drag for moving windows and may intercept the gesture before Tk receives it. On those desktops the window-manager binding must be remapped. A future preferences control could make the modifier configurable; this patch deliberately keeps the initial gesture narrow and does not alter existing Potato settings or world files.
Implementation scope
The feature is a stock library module, potato-box-selection.tcl. Potato attaches its bindtag explicitly when creating a world output widget. It does not install a global mouse-motion hook, does not poll the widget tree, and does not affect Telnet, rendering, socket handling, or server protocols.
Verification
The patch includes two Tcl/Tk 8.6 regression suites. They provide 24 assertions covering:
- the Select-to-Copy scheduling correction;
- output-only attachment;
- forward and reverse rectangular drags;
- exact clipboard slices and row boundaries;
- short and wrapped rows;
- ordinary linear selection compatibility;
- Select-to-Copy release behavior and duplicate suppression;
- incoming output and scrollback trimming;
- autoscroll and timer cleanup;
- Escape clearing; and
- reload safety.
The generated mail patch was applied with git am to a fresh detached worktree at the exact upstream baseline. Both suites passed there with Tcl/Tk 8.6.18.
Summary
Add rectangular output selection to Potato with an Alt+left-drag gesture. The standalone patch also includes the Select-to-Copy scheduling correction from #537 so rectangular and ordinary selection do not perform clipboard I/O on every mouse-motion event.
Clean standalone patch: https://github.com/adkins17/potato/commit/410a000f22159111f984e947cbdb77badc64ace8.patch
Patch branch: https://github.com/adkins17/potato/tree/feature/alt-drag-rectangular-selection
Upstream baseline:
46d18387bd6b156b85176fa588a60991cbba6235(potatomushclient/potatomaster)Related correction: #537
Gesture
The gesture operates only in
PotatoOutputtext widgets. Input panes keep their existing bindings, and an ordinary left-button drag continues to make a normal linear selection.Clipboard result
Each visible display row contributes only the characters inside the selected horizontal bounds. The slices are joined with newline characters in the clipboard. This makes it possible to copy a column, table field, ASCII-art region, or aligned status block without copying the unrelated text between the first and last selected character.
Selection behavior
Performance and correction
The patch includes the diagnosis and correction from #537. Stock Potato currently clears and repopulates the system clipboard for every
<<Selection>>event while Select to Copy is enabled. The correction coalesces ordinary selection changes for 125 ms and flushes after mouse release.Rectangular selection adds two further safeguards:
Queued Tk selection events are deduplicated after release so the same rectangle is not copied twice.
Platform note
Some Linux window managers reserve Alt+drag for moving windows and may intercept the gesture before Tk receives it. On those desktops the window-manager binding must be remapped. A future preferences control could make the modifier configurable; this patch deliberately keeps the initial gesture narrow and does not alter existing Potato settings or world files.
Implementation scope
The feature is a stock library module,
potato-box-selection.tcl. Potato attaches its bindtag explicitly when creating a world output widget. It does not install a global mouse-motion hook, does not poll the widget tree, and does not affect Telnet, rendering, socket handling, or server protocols.Verification
The patch includes two Tcl/Tk 8.6 regression suites. They provide 24 assertions covering:
The generated mail patch was applied with
git amto a fresh detached worktree at the exact upstream baseline. Both suites passed there with Tcl/Tk 8.6.18.