Enforce minimum pane size (180px) on split and gutter drag

Spamming the ⇥/⇣ split buttons (or their Ctrl+Shift+E/O shortcuts)
used to subdivide panes indefinitely, leaving toolbar-only slivers
that were unusable.

- tree.ts: MIN_PANE_PX = 180 constant.
- App.tsx: the `split` orchestration callback now computes the active
  pane's pixel dimensions from its layout slot + the container rect,
  and refuses to split if either child would fall below MIN_PANE_PX.
  Surfaces the refusal via a `notify(...)` toast so the user knows
  why nothing happened.
- Gutter.tsx: pointermove clamps the new ratio so the smaller child
  stays at least MIN_PANE_PX wide/tall. Falls back to the old 0.05
  floor only if the parent is so small that two min-sized panes
  can't both fit (degraded but functional).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
megaproxy 2026-05-22 22:01:41 +01:00
parent a5209e08ae
commit daf0d4e88a
3 changed files with 50 additions and 11 deletions

View file

@ -1,5 +1,5 @@
import { useCallback, useRef, useState, type PointerEvent } from "react";
import type { GutterInfo } from "./tree";
import { type GutterInfo, MIN_PANE_PX } from "./tree";
/**
* A draggable gutter at a split boundary.
@ -59,7 +59,15 @@ export default function Gutter({
info.orientation === "h"
? (xFrac - pb.left) / pb.width
: (yFrac - pb.top) / pb.height;
const ratio = Math.max(0.05, Math.min(0.95, rawRatio));
// Clamp so neither child shrinks below MIN_PANE_PX. If the parent
// box is so small that two min-sized panes don't fit, fall back to
// 0.05 / 0.95 (ugly but functional).
const parentPx =
info.orientation === "h" ? rect.width * pb.width : rect.height * pb.height;
const minByPx = parentPx > 0 ? MIN_PANE_PX / parentPx : 0.05;
const minRatio = Math.min(0.45, Math.max(0.05, minByPx));
const maxRatio = 1 - minRatio;
const ratio = Math.max(minRatio, Math.min(maxRatio, rawRatio));
pendingRatioRef.current = ratio;
if (rafRef.current == null) {
rafRef.current = requestAnimationFrame(flushPending);

View file

@ -253,6 +253,12 @@ export function setAllBroadcast(root: TreeNode, on: boolean): TreeNode {
return { ...root, a, b };
}
/** Minimum width/height (px) we allow a pane to shrink to. Just enough for
* the toolbar + a few cols/rows of usable terminal. Used by the split
* handler (to refuse subdividing a pane that's already too small) and by
* the gutter drag (to clamp ratios so neither child drops below this). */
export const MIN_PANE_PX = 180;
// --- flat layout (for absolute-positioned rendering) ------------------------
/** Normalised bounding box: top/left/width/height as fractions [0, 1]. */