Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/timeline/interaction/interaction-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,16 @@ export class InteractionController implements TimelineInteractionRegistration {
const ghostHeights = this.getHeights();
const targetHeight = (ghostHeights[state.dragTarget.trackIndex] ?? getTrackHeight(targetTrack.primaryAssetType)) - 8;

ghost.style.left = `${timeToViewX(clipTime, feedbackConfig.pixelsPerSecond)}px`; // eslint-disable-line no-param-reassign -- DOM manipulation
// The feedback layer doesn't scroll with the tracks
const ghostX = timeToViewX(clipTime, feedbackConfig.pixelsPerSecond) - feedbackConfig.scrollLeft;
ghost.style.left = `${ghostX}px`; // eslint-disable-line no-param-reassign -- DOM manipulation
ghost.style.top = `${targetTrackY + feedbackConfig.tracksOffset}px`; // eslint-disable-line no-param-reassign -- DOM manipulation
ghost.style.height = `${targetHeight}px`; // eslint-disable-line no-param-reassign -- DOM manipulation

this.feedbackElements.dragTimeTooltip = showDragTimeTooltip(
this.feedbackElements,
clipTime,
timeToViewX(clipTime, feedbackConfig.pixelsPerSecond),
ghostX,
targetTrackY + feedbackConfig.tracksOffset
);
hideDropZone(this.feedbackElements.dropZone);
Expand Down
18 changes: 14 additions & 4 deletions src/components/timeline/interaction/interaction-feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ export function showLumaConnectionLine(
trackYPosition: number,
trackHeight: number,
tracksOffset: number,
pixelsPerSecond: number
pixelsPerSecond: number,
scrollLeft: number
): HTMLElement {
const line = getOrCreateElement(elements.container, elements.lumaConnectionLine, "ss-luma-connection-line");
const clipX = timeToViewX(sec(targetClip.config.start), pixelsPerSecond);
const clipX = timeToViewX(sec(targetClip.config.start), pixelsPerSecond) - scrollLeft;
line.style.left = `${clipX}px`;
line.style.top = `${trackYPosition + tracksOffset}px`;
line.style.height = `${trackHeight}px`;
Expand Down Expand Up @@ -168,7 +169,15 @@ export function updateLumaTargetHighlight(
}

// Show connection line from ghost to target
const connectionLine = showLumaConnectionLine(elements, targetClip, trackYPosition, trackHeight, tracksOffset, pixelsPerSecond);
const connectionLine = showLumaConnectionLine(
elements,
targetClip,
trackYPosition,
trackHeight,
tracksOffset,
pixelsPerSecond,
tracksContainer.scrollLeft
);

return { targetClipElement: clipElement, connectionLine };
}
Expand Down Expand Up @@ -212,7 +221,8 @@ export function getTracksOffsetInFeedbackLayer(feedbackLayer: HTMLElement, track

const parentRect = feedbackParent.getBoundingClientRect();
const tracksRect = tracksContainer.getBoundingClientRect();
return tracksRect.top - parentRect.top;
// Feedback is placed by track y in the tracks' content, which scrolls; the feedback layer doesn't
return tracksRect.top - parentRect.top - tracksContainer.scrollTop;
}

// ─── Aggregate Render Functions ────────────────────────────────────────────
Expand Down
89 changes: 89 additions & 0 deletions tests/interaction-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,95 @@ describe("InteractionController", () => {
});
});

describe("drag feedback in a scrolled timeline", () => {
const box = (left: number, top: number, width: number, height: number) =>
({ left, top, width, height, right: left + width, bottom: top + height, x: left, y: top, toJSON: () => ({}) }) as DOMRect;
const px = (el: HTMLElement | null, side: "left" | "top") => parseFloat(el?.style[side] ?? "");
const ghost = () => mockDOM.feedbackLayer.querySelector<HTMLElement>(".ss-drag-ghost");
const clipElement = () => mockDOM.tracksContainer.querySelector<HTMLElement>(".ss-clip")!;

beforeEach(() => {
// A 4 s video at 5 s on track 0 over a 2 s luma on track 1, at 50 px/s: the video starts at view x 266 (16px padding)
mockStateManager.setTestTracks([
createMockTrack(0, [{ start: 5, length: 4 }]),
createMockTrack(1, [{ start: 0, length: 2, assetType: "luma" }])
] as MockTrack[]);
mockStateManager.getViewport.mockReturnValue({ scrollX: 0, scrollY: 0, pixelsPerSecond: 50 });
Object.assign(mockStateManager, { findAttachedLuma: jest.fn(() => null) });
// The feedback layer spans the ruler (32px) and the tracks below it, from the same left edge
const wrapper = document.createElement("div");
wrapper.getBoundingClientRect = () => box(0, 0, 800, 232);
wrapper.appendChild(mockDOM.feedbackLayer);
mockDOM.tracksContainer.getBoundingClientRect = () => box(0, 32, 800, 200);
mockDOM.tracksContainer.setPointerCapture = jest.fn();
controller = new InteractionController(
mockEdit as never,
mockStateManager as never,
mockTrackList as never,
mockDOM.tracksContainer,
mockDOM.feedbackLayer
);
controller.mount();
});

// Grabs the video 50px in from its left edge, wherever the scroll puts it on screen
const grab = (scrollLeft: number, pointerType = "mouse") => {
mockDOM.tracksContainer.scrollLeft = scrollLeft;
const clip = clipElement();
clip.getBoundingClientRect = () => box(266 - scrollLeft, 36, 200, 64);
clip.dispatchEvent(createPointerEvent("pointerdown", { clientX: 316 - scrollLeft, clientY: 60, pointerType }));
return clip;
};
const moveTo = (clientX: number, clientY = 60, options: { altKey?: boolean; pointerType?: string } = {}) =>
document.dispatchEvent(createPointerEvent("pointermove", { clientX, clientY, ...options }));

it("lines the ghost and its time up with the clip when the tracks are scrolled 167px", () => {
const clip = grab(167);
moveTo(153);
expect(px(ghost(), "left") - px(clip, "left")).toBe(0);

moveTo(183);
expect(px(ghost(), "left") - px(clip, "left")).toBe(0);
expect(px(mockDOM.feedbackLayer.querySelector(".ss-drag-time-tooltip"), "left")).toBe(px(ghost(), "left"));
});

it("places the ghost where it always has in an unscrolled timeline", () => {
grab(0);
moveTo(346);

expect(ghost()?.style.left).toBe("296px");
});

it("lines the ghost up with a lifted clip in a scrolled timeline", () => {
jest.useFakeTimers();
const clip = grab(167, "touch");
jest.advanceTimersByTime(450);
moveTo(179, 60, { pointerType: "touch" });
jest.useRealTimers();

expect(px(ghost(), "left") - px(clip, "left")).toBe(0);
});

it("draws the luma connection line at its target clip's left edge in a scrolled timeline", () => {
mockDOM.tracksContainer.scrollLeft = 167;
const luma = mockDOM.addClipElement(1, 0, { left: 16 - 167, top: 108, width: 100, height: 64 });
luma.dispatchEvent(createPointerEvent("pointerdown", { clientX: 16 - 167 + 10, clientY: 140, altKey: true }));
moveTo(150, 60, { altKey: true });

expect(px(mockDOM.feedbackLayer.querySelector(".ss-luma-connection-line"), "left")).toBe(266 - 167);
});

it("places the ghost on its target track when the tracks are scrolled down", () => {
mockDOM.tracksContainer.scrollTop = 40;
grab(0);
// Track 1 spans content y 72 to 144; its middle sits 40px higher on screen, below the 32px ruler
moveTo(350, 108 - 40 + 32);

// Content y 72 + 4px inset, moved up by the scroll and down by the ruler
expect(px(ghost(), "top")).toBe(72 + 4 - 40 + 32);
});
});

// ─── Touch Input Tests ───────────────────────────────────────────────────

describe("touch input", () => {
Expand Down
Loading