Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
perf(web): cut timeline geometry time after transcript edits
Akshar Patela51dcc78f318
diff --git a/apps/web/__tests__/unit/video-edits.test.ts b/apps/web/__tests__/unit/video-edits.test.tsindex ff3fb5cbf..cda1e4522 100644--- a/apps/web/__tests__/unit/video-edits.test.ts+++ b/apps/web/__tests__/unit/video-edits.test.ts@@ -224,6 +224,79 @@ describe("timeline editing", () => {expect(mapTimelineDisplayTimeToSourceTime(deleted, 3)).toBe(3);});+ it("preserves display offsets and split indices across trimmed deletions", () => {+ const state = {+ ...createTimelineState(20),+ trimStart: 2,+ trimEnd: 18,+ splitPoints: [17, 14, 12, 10, 9, 8, 7, 6, 4, 3],+ deletedRanges: [+ { start: 17, end: 19 },+ { start: 10, end: 12 },+ { start: 6, end: 8 },+ { start: 1, end: 3 },+ ],+ selectedSegmentId: "8:9",+ };++ expect(+ getTimelineDisplaySegments(state).map(+ ({ start, end, displayStart, displayEnd, selected }) => ({+ start,+ end,+ displayStart,+ displayEnd,+ selected,+ }),+ ),+ ).toEqual([+ { start: 3, end: 4, displayStart: 1, displayEnd: 2, selected: false },+ { start: 4, end: 6, displayStart: 2, displayEnd: 4, selected: false },+ { start: 8, end: 9, displayStart: 4, displayEnd: 5, selected: true },+ { start: 9, end: 10, displayStart: 5, displayEnd: 6, selected: false },+ { start: 12, end: 14, displayStart: 6, displayEnd: 8, selected: false },+ { start: 14, end: 17, displayStart: 8, displayEnd: 11, selected: false },+ ]);+ expect(+ getTimelineDisplaySplitPoints(state).map(+ ({ time, sourceTimes, splitIndices }) => ({+ time,+ sourceTimes,+ splitIndices,+ }),+ ),+ ).toEqual([+ { time: 2, sourceTimes: [4], splitIndices: [1] },+ { time: 4, sourceTimes: [6, 8], splitIndices: [2, 3] },+ { time: 5, sourceTimes: [9], splitIndices: [4] },+ { time: 6, sourceTimes: [10, 12], splitIndices: [5, 6] },+ { time: 8, sourceTimes: [14], splitIndices: [7] },+ ]);+ });++ it("retains nearby split indices when a subminimum segment is omitted", () => {+ const state = {+ ...createTimelineState(10),+ splitPoints: [1, 1.001, 2, 3, 7, 8],+ deletedRanges: [{ start: 3, end: 7 }],+ };++ expect(+ getTimelineDisplaySplitPoints(state).map(+ ({ time, sourceTimes, splitIndices }) => ({+ time,+ sourceTimes,+ splitIndices,+ }),+ ),+ ).toEqual([+ { time: 1, sourceTimes: [1], splitIndices: [0, 1] },+ { time: 2, sourceTimes: [2], splitIndices: [2] },+ { time: 3, sourceTimes: [3, 7], splitIndices: [3, 4] },+ { time: 4, sourceTimes: [8], splitIndices: [5] },+ ]);+ });+it("removes a collapsed display split by restoring the deleted segment", () => {const splitState = splitTimelineAt(splitTimelineAt(createTimelineState(10), 3),diff --git a/apps/web/lib/video-edits.ts b/apps/web/lib/video-edits.tsindex 94ce746ee..83ad86853 100644--- a/apps/web/lib/video-edits.ts+++ b/apps/web/lib/video-edits.ts@@ -520,8 +520,17 @@ export function getTimelineDisplaySegments(const normalized = normalizeTimelineState(state);const keepRanges = getTimelineKeepRanges(normalized);const segments: VideoTimelineDisplaySegment[] = [];+ let deletedRangeIndex = 0;+ let deletedBefore = 0;for (const range of keepRanges) {+ let deletedRange = normalized.deletedRanges[deletedRangeIndex];+ while (deletedRange && deletedRange.end <= range.start + EPSILON) {+ deletedBefore += deletedRange.end - deletedRange.start;+ deletedRangeIndex++;+ deletedRange = normalized.deletedRanges[deletedRangeIndex];+ }+const boundaries = [range.start,...normalized.splitPoints.filter(@@ -536,11 +545,8 @@ export function getTimelineDisplaySegments(if (end - start < MIN_RANGE_DURATION) continue;const id = getSegmentId(start, end);- const displayStart = mapTimelineSourceTimeToDisplayTime(- normalized,- start,- );- const displayEnd = mapTimelineSourceTimeToDisplayTime(normalized, end);+ const displayStart = roundEditTime(Math.max(0, start - deletedBefore));+ const displayEnd = roundEditTime(Math.max(0, end - deletedBefore));if (displayEnd - displayStart < MIN_RANGE_DURATION) continue;segments.push({@@ -565,6 +571,7 @@ export function getTimelineDisplaySplitPoints(const segments = getTimelineDisplaySegments(normalized);const sortedSplitPoints = [...normalized.splitPoints].sort((a, b) => a - b);const markers: VideoTimelineDisplaySplitPoint[] = [];+ let splitIndex = 0;for (let index = 0; index < segments.length - 1; index++) {const current = segments[index];@@ -576,11 +583,17 @@ export function getTimelineDisplaySplitPoints(sourceTimes.push(next.start);}- const splitIndices = sortedSplitPoints.flatMap((point, splitIndex) =>- sourceTimes.some((sourceTime) => Math.abs(point - sourceTime) <= EPSILON)- ? [splitIndex]- : [],- );+ const splitIndices: number[] = [];+ for (const sourceTime of sourceTimes) {+ let point = sortedSplitPoints[splitIndex];+ while (point !== undefined && point - sourceTime <= EPSILON) {+ if (Math.abs(point - sourceTime) <= EPSILON) {+ splitIndices.push(splitIndex);+ }+ splitIndex++;+ point = sortedSplitPoints[splitIndex];+ }+ }const time = current.displayEnd;markers.push({id: `${roundEditTime(time)}:${sourceTimes.map(roundEditTime).join(":")}`,