Add a before/after split with a draggable handle

The Develop preview can put the untouched source left of a drag line and the
edited frame right of it. Both halves come from one render on one view, so they
line up exactly, and the split shares its handle behaviour with the lens
correction split. The headless render check now asserts that each half shows its
own edit.
This commit is contained in:
2026-12-01 12:13:54 +00:00
parent b39cad02fe
commit 7aef2e37bf
4 changed files with 152 additions and 23 deletions
+90 -14
View File
@@ -276,6 +276,9 @@ export default function Develop({
const [lensCorrection, setLensCorrection] = useState<LensCorrection | null>(null);
const [lensSplit, setLensSplit] = useState(false);
const [lensSplitAt, setLensSplitAt] = useState(0.5);
// The whole edit compared with the untouched source, split by a drag line.
const [splitView, setSplitView] = useState(false);
const [splitAt, setSplitAt] = useState(0.5);
const [lensState, setLensState] = useState<{ loading: boolean; error: string | null }>({
loading: false,
error: null,
@@ -373,11 +376,16 @@ export default function Develop({
onSelect(p.id);
};
const moveLensSplit = (e: React.PointerEvent<HTMLButtonElement>) => {
const rect = e.currentTarget.parentElement?.getBoundingClientRect();
if (!rect || rect.width <= 0) return;
setLensSplitAt(clampNum((e.clientX - rect.left) / rect.width, 0.02, 0.98));
};
// Both splits drag the same way: the handle sits on the line, and its
// percentage follows the pointer across the canvas.
const dragSplit =
(set: (at: number) => void) => (e: React.PointerEvent<HTMLButtonElement>) => {
const rect = e.currentTarget.parentElement?.getBoundingClientRect();
if (!rect || rect.width <= 0) return;
set(clampNum((e.clientX - rect.left) / rect.width, 0.02, 0.98));
};
const moveLensSplit = dragSplit(setLensSplitAt);
const moveSplit = dragSplit(setSplitAt);
const setEdits = useCallback(
(patch: Partial<Edits>, label: string) => {
@@ -546,7 +554,11 @@ export default function Develop({
if (!renderer || !canvas || !bitmap) return;
if (stage.w < 40 || stage.h < 40) return;
const activeEdits = showOriginal ? { ...defaultEdits(), crop: edits.crop } : edits;
// Holding \ shows the untouched source full-frame; the split paints the same
// render over the left of its drag line, and steps aside while \ is held.
const beforeEdits = { ...defaultEdits(), crop: edits.crop };
const splitOn = splitView && !showOriginal;
const activeEdits = showOriginal ? beforeEdits : edits;
const frame = rotatedBounds(bitmap.width, bitmap.height, edits.crop.angle, edits.crop.quarter);
const content: Rect = cropMode
? { x: 0, y: 0, w: 1, h: 1 }
@@ -616,7 +628,7 @@ export default function Develop({
renderer.setImage(bitmap, hdrSource);
// "Show original" must show the untouched source, not the cleaned proxy.
renderer.setDenoised(showOriginal ? null : denoisedBitmap, activeEdits.aiDenoise.amount / 100);
renderer.render(activeEdits, {
const frameOpts = {
width: pxW,
height: pxH,
cropPreview: cropMode,
@@ -631,11 +643,30 @@ export default function Develop({
upscale: dpr * cap * fitScale * zoomFactor > 1.1,
clipPreview,
clipping: clipping ?? undefined,
};
renderer.render(activeEdits, {
...frameOpts,
lens: showOriginal ? null : lensCorrection,
lensSplit: lensSplit && !showOriginal ? lensSplitAt : undefined,
lensSplit: lensSplit && !splitOn ? lensSplitAt : undefined,
maskView,
maskStrength: maskStrength / 100,
});
if (splitOn) {
// Paint the untouched source over the left half. The scissor is in
// device pixels and the same view is reused, so the halves line up.
renderer.setDenoised(null, 0);
renderer.render(beforeEdits, {
...frameOpts,
histogram: false,
lens: null,
maskView: -1,
clipPreview: false,
scissor: { x: 0, w: Math.round(pxW * splitAt) },
});
// Restore what the rest of the frame and the eyedropper read from.
renderer.setDenoised(denoisedBitmap, edits.aiDenoise.amount / 100);
renderer.setLensCorrection(lensCorrection);
}
histRef.current = renderer.histogram;
setHistVersion((v) => v + 1);
} catch (err) {
@@ -656,6 +687,8 @@ export default function Develop({
lensCorrection,
lensSplit,
lensSplitAt,
splitView,
splitAt,
localMode,
localSelected,
maskOverlay,
@@ -1801,6 +1834,7 @@ export default function Develop({
'separator',
{ label: 'Crop & Straighten', shortcut: 'C', onSelect: () => setCropMode((v) => !v) },
{ label: 'Before / After', shortcut: '\\', onSelect: () => setShowOriginal((v) => !v) },
{ label: 'Before / After split', onSelect: () => setSplitView((v) => !v) },
'separator',
{ label: 'Copy settings', shortcut: '⌘C', onSelect: onCopy },
{ label: 'Paste settings', shortcut: '⌘V', onSelect: () => onPaste([photo.id]), disabled: !clipboard },
@@ -1884,6 +1918,14 @@ export default function Develop({
>
Before / After
</button>
<button
className={`btn ghost small ${splitView ? 'on' : ''}`}
onClick={() => setSplitView((v) => !v)}
aria-pressed={splitView}
title="Compare the edit with the original on either side of a draggable line"
>
Split
</button>
<button
className={`btn ghost small ${autoSync ? 'on' : ''}`}
onClick={() => setAutoSync((v) => !v)}
@@ -2097,14 +2139,14 @@ export default function Develop({
toggleZoom(e.clientX, e.clientY);
}}
/>
{lensSplit && lensCorrection && !showOriginal && (
<div className="lens-split">
<div className="lens-split-line" style={{ left: `${lensSplitAt * 100}%` }} />
<span className="lens-split-label before">Before</span>
<span className="lens-split-label after">After</span>
{lensSplit && lensCorrection && !showOriginal && !splitView && (
<div className="compare-split">
<div className="compare-split-line" style={{ left: `${lensSplitAt * 100}%` }} />
<span className="compare-split-label before">Before</span>
<span className="compare-split-label after">After</span>
<button
type="button"
className="lens-split-handle"
className="compare-split-handle"
style={{ left: `${lensSplitAt * 100}%` }}
aria-label="Drag to move the lens correction split"
title="Drag to compare lens correction"
@@ -2131,6 +2173,40 @@ export default function Develop({
</button>
</div>
)}
{splitView && !showOriginal && (
<div className="compare-split">
<div className="compare-split-line" style={{ left: `${splitAt * 100}%` }} />
<span className="compare-split-label before">Before</span>
<span className="compare-split-label after">After</span>
<button
type="button"
className="compare-split-handle"
style={{ left: `${splitAt * 100}%` }}
aria-label="Drag to move the before / after split"
title="Drag to compare the edit with the original"
onPointerDown={(e) => {
e.preventDefault();
e.currentTarget.setPointerCapture(e.pointerId);
moveSplit(e);
}}
onPointerMove={(e) => {
if (e.currentTarget.hasPointerCapture(e.pointerId)) moveSplit(e);
}}
onPointerUp={(e) => {
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
e.currentTarget.releasePointerCapture(e.pointerId);
}
}}
onPointerCancel={(e) => {
if (e.currentTarget.hasPointerCapture(e.pointerId)) {
e.currentTarget.releasePointerCapture(e.pointerId);
}
}}
>
↔
</button>
</div>
)}
{healMode && bitmap && (() => {
const geo = geoRef.current;
const view = geo.view;