* fix(app): clamp split pane resize Prevent right-edge drags from overflowing the Electron viewport. * fix(app): isolate resize pointer state Keep concurrent resize drags from clobbering each other.
37 lines
916 B
TypeScript
37 lines
916 B
TypeScript
import { MIN_SPLIT_SIZE } from "@/stores/workspace-layout-constants";
|
|
|
|
interface ComputeResizeHandleSizesInput {
|
|
sizes: number[];
|
|
index: number;
|
|
deltaRatio: number;
|
|
minSize?: number;
|
|
}
|
|
|
|
export function computeResizeHandleSizes({
|
|
sizes,
|
|
index,
|
|
deltaRatio,
|
|
minSize = MIN_SPLIT_SIZE,
|
|
}: ComputeResizeHandleSizesInput): number[] {
|
|
const nextSizes = sizes.slice();
|
|
const leftSize = sizes[index];
|
|
const rightSize = sizes[index + 1];
|
|
if (leftSize === undefined || rightSize === undefined) {
|
|
return nextSizes;
|
|
}
|
|
|
|
const pairSize = leftSize + rightSize;
|
|
if (pairSize <= 0) {
|
|
return nextSizes;
|
|
}
|
|
|
|
const adjacentMinSize = Math.min(minSize, pairSize / 2);
|
|
const nextLeftSize = Math.min(
|
|
pairSize - adjacentMinSize,
|
|
Math.max(adjacentMinSize, leftSize + deltaRatio),
|
|
);
|
|
nextSizes[index] = nextLeftSize;
|
|
nextSizes[index + 1] = pairSize - nextLeftSize;
|
|
return nextSizes;
|
|
}
|