Skip to content

Commit 86a08df

Browse files
davide-donaEtienneLescot
authored andcommitted
Update blur handling
1 parent 33cf5c3 commit 86a08df

3 files changed

Lines changed: 47 additions & 13 deletions

File tree

src/components/video-editor/VideoEditor.tsx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,18 +1865,25 @@ export default function VideoEditor() {
18651865
}
18661866

18671867
// Copy/paste region attributes. Skipped while typing in a field so native
1868-
// text copy/paste keeps working.
1868+
// text copy/paste keeps working. Also only intercepted when there's an
1869+
// actual region selected (copy) or something on the clipboard (paste);
1870+
// otherwise the browser handles native copy/paste of any page selection.
18691871
const editingText = isTextEditingTarget(e.target);
18701872
if (!editingText) {
18711873
if (matchesShortcut(e, shortcuts.copySelected, isMac)) {
1872-
e.preventDefault();
1873-
handleCopySelected();
1874-
return;
1875-
}
1876-
if (matchesShortcut(e, shortcuts.paste, isMac)) {
1877-
e.preventDefault();
1878-
handlePaste();
1879-
return;
1874+
const hasRegionSelected =
1875+
selectedZoomId || selectedSpeedId || selectedAnnotationId || selectedBlurId;
1876+
if (hasRegionSelected) {
1877+
e.preventDefault();
1878+
handleCopySelected();
1879+
return;
1880+
}
1881+
} else if (matchesShortcut(e, shortcuts.paste, isMac)) {
1882+
if (getCopiedRegion()) {
1883+
e.preventDefault();
1884+
handlePaste();
1885+
return;
1886+
}
18801887
}
18811888
}
18821889

@@ -1936,7 +1943,18 @@ export default function VideoEditor() {
19361943

19371944
window.addEventListener("keydown", handleKeyDown, { capture: true });
19381945
return () => window.removeEventListener("keydown", handleKeyDown, { capture: true });
1939-
}, [undo, redo, shortcuts, isMac, handleCopySelected, handlePaste]);
1946+
}, [
1947+
undo,
1948+
redo,
1949+
shortcuts,
1950+
isMac,
1951+
handleCopySelected,
1952+
handlePaste,
1953+
selectedZoomId,
1954+
selectedSpeedId,
1955+
selectedAnnotationId,
1956+
selectedBlurId,
1957+
]);
19401958

19411959
useEffect(() => {
19421960
if (selectedZoomId && !zoomRegions.some((region) => region.id === selectedZoomId)) {

src/components/video-editor/regionClipboard.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
AnnotationSize,
55
AnnotationTextStyle,
66
AnnotationType,
7+
BlurData,
78
FigureData,
89
PlaybackSpeed,
910
Rotation3DPreset,
@@ -35,6 +36,7 @@ export type CopiedAnnotation = {
3536
style: AnnotationTextStyle;
3637
size: AnnotationSize;
3738
figureData?: FigureData;
39+
blurData?: BlurData;
3840
// Content & placement — used only when pasting as a brand-new region.
3941
type: AnnotationType;
4042
content: string;
@@ -72,12 +74,22 @@ export function extractSpeedAttributes(region: SpeedRegion): CopiedSpeed {
7274
return { kind: "speed", speed: region.speed };
7375
}
7476

77+
/** Deep-clones blur data, including its nested freehand points array. */
78+
function cloneBlurData(blurData?: BlurData): BlurData | undefined {
79+
if (!blurData) return undefined;
80+
return {
81+
...blurData,
82+
freehandPoints: blurData.freehandPoints ? [...blurData.freehandPoints] : undefined,
83+
};
84+
}
85+
7586
export function extractAnnotationAttributes(region: AnnotationRegion): CopiedAnnotation {
7687
return {
7788
kind: "annotation",
7889
style: { ...region.style },
7990
size: { ...region.size },
8091
figureData: region.figureData ? { ...region.figureData } : undefined,
92+
blurData: cloneBlurData(region.blurData),
8193
type: region.type,
8294
content: region.content,
8395
textContent: region.textContent,
@@ -119,6 +131,9 @@ export function replaceAnnotationAttributes(
119131
// (e.g. pasting a figure's attributes onto a text annotation keeps the text figure-less).
120132
figureData:
121133
region.type === "figure" && attrs.figureData ? { ...attrs.figureData } : region.figureData,
134+
// Likewise, only carry blur settings onto a blur target.
135+
blurData:
136+
region.type === "blur" && attrs.blurData ? cloneBlurData(attrs.blurData) : region.blurData,
122137
};
123138
}
124139

@@ -138,5 +153,6 @@ export function buildPastedAnnotation(
138153
size: { ...attrs.size },
139154
style: { ...attrs.style },
140155
figureData: attrs.figureData ? { ...attrs.figureData } : undefined,
156+
blurData: cloneBlurData(attrs.blurData),
141157
};
142158
}

src/components/video-editor/regionPlacement.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* Placement is valid as long as `startPos` does not fall inside an
99
* existing region and there is some room before the next one. Landing
10-
* exactly on the start of an existing region is fine (adjacency is
11-
* allowed); landing strictly between a region's start and end, or
12-
* having zero space left before the next region, is not.
10+
* exactly on the end of an existing region is fine (adjacency is
11+
* allowed); landing on a region's start or strictly between its start
12+
* and end, or having zero space left before the next region, is not.
1313
*/
1414
export function findFreeGapAt(
1515
regions: ReadonlyArray<{ startMs: number; endMs: number }>,

0 commit comments

Comments
 (0)