fix(preview): keep source navigation and canvas interactions responsive
This commit is contained in:
1 parent
107e93b959
commit
77dbb1897f
4 files changed
+685
-22
No files matched your search
@@ -16,6 +16,7 @@ import 'package:cutdex/features/properties/mask_properties.dart';
|
||||
import 'package:cutdex/features/properties/property_number_input.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:cutdex_sdk/runtime.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
@@ -208,6 +209,177 @@ void main() {
|
||||
messenger.setMockMethodCallHandler(events, null);
|
||||
});
|
||||
|
||||
testWidgets('alignment refreshes selection when the native scene settles', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/align.mov')),
|
||||
))!;
|
||||
final timeline = fixture.timeline;
|
||||
final sequence = SequenceId('one');
|
||||
final clip = ElementId('clip');
|
||||
await tester.runAsync(() async {
|
||||
timeline.commands.setTransform(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
change: (_) => const ClipTransform(x: .1, scale: .5, scaleY: .5),
|
||||
);
|
||||
await timeline.flush();
|
||||
});
|
||||
final preview = PreviewController(
|
||||
timeline: timeline,
|
||||
activeSequence: () => timeline.activeSequenceId,
|
||||
viewForSequence: timeline.view,
|
||||
runtime: CutdexRuntime(),
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await preview.close();
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
await tester.runAsync(() async {
|
||||
await preview.initialize();
|
||||
await until(() => calls.any((c) => c.method == 'seek'));
|
||||
});
|
||||
expect(tester.takeException(), isNull, reason: 'initialize');
|
||||
preview.selectVisual(clip);
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'project',
|
||||
).overrideWith((ref) async => preview),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penLight,
|
||||
home: const Scaffold(
|
||||
body: EditorPreviewPanel(
|
||||
projectId: 'project',
|
||||
timelineId: 'project',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final selection = find.descendant(
|
||||
of: find.byType(PreviewInteractionOverlay),
|
||||
matching: find.byType(CustomPaint),
|
||||
);
|
||||
final before = tester.widget<CustomPaint>(selection).painter!;
|
||||
final cachedVisual = preview.visualsForSelection({clip}).single;
|
||||
for (var i = 0; i < 100; i++) {
|
||||
expect(preview.visualsForSelection({clip}).single, same(cachedVisual));
|
||||
expect(preview.visuals.single, same(cachedVisual));
|
||||
}
|
||||
final canvasBefore = tester.widget<PreviewCanvas>(
|
||||
find.byType(PreviewCanvas),
|
||||
);
|
||||
final seeks = calls.where((c) => c.method == 'seek').length;
|
||||
final patch = blockedPatch = Completer<void>();
|
||||
await tester.runAsync(() async {
|
||||
await timeline.alignClip(
|
||||
sequence,
|
||||
AlignClip(
|
||||
clipId: 'clip',
|
||||
at: CommandTime(0, 1),
|
||||
alignment: CanvasAlignment.left,
|
||||
),
|
||||
);
|
||||
await until(() => calls.any((c) => c.method == 'applyPatch'));
|
||||
});
|
||||
expect(tester.takeException(), isNull, reason: 'align');
|
||||
await tester.pump();
|
||||
expect(preview.busy, isTrue);
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(before),
|
||||
isFalse,
|
||||
);
|
||||
|
||||
patch.complete();
|
||||
await tester.runAsync(() => until(() => !preview.busy));
|
||||
expect(tester.takeException(), isNull, reason: 'native acknowledgement');
|
||||
await tester.pump();
|
||||
final aligned = tester.widget<CustomPaint>(selection).painter!;
|
||||
expect(aligned.shouldRepaint(before), isTrue);
|
||||
expect(
|
||||
preview.visualsForSelection({clip}).single,
|
||||
isNot(same(cachedVisual)),
|
||||
);
|
||||
expect(preview.visuals.single.geometry.bounds.left, closeTo(0, 1e-6));
|
||||
expect(
|
||||
tester.widget<PreviewCanvas>(find.byType(PreviewCanvas)),
|
||||
same(canvasBefore),
|
||||
);
|
||||
expect(preview.positionTick, 0);
|
||||
expect(preview.selectedVisualIds, {clip});
|
||||
|
||||
blockedPatch = null;
|
||||
await tester.runAsync(() async {
|
||||
timeline.view(sequence).undo();
|
||||
await until(() => !preview.busy);
|
||||
});
|
||||
expect(tester.takeException(), isNull, reason: 'undo');
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(aligned),
|
||||
isTrue,
|
||||
);
|
||||
final undone = tester.widget<CustomPaint>(selection).painter!;
|
||||
expect(preview.selectedVisualIds, isEmpty);
|
||||
await tester.runAsync(() async {
|
||||
timeline.view(sequence).redo();
|
||||
await until(() => !preview.busy);
|
||||
});
|
||||
await tester.pump();
|
||||
expect(preview.visuals.single.geometry.bounds.left, closeTo(0, 1e-6));
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(undone),
|
||||
isFalse,
|
||||
);
|
||||
expect(preview.selectedVisualIds, isEmpty);
|
||||
preview.selectVisual(clip);
|
||||
await tester.pump();
|
||||
for (final transform in [
|
||||
const ClipTransform(x: .2, y: .1),
|
||||
const ClipTransform(x: .2, y: .1, scale: .75, scaleY: .5),
|
||||
const ClipTransform(x: .2, y: .1, scale: .75, scaleY: .5, rotation: 30),
|
||||
]) {
|
||||
final previous = tester.widget<CustomPaint>(selection).painter!;
|
||||
await tester.runAsync(() async {
|
||||
timeline.commands.setTransform(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
change: (_) => transform,
|
||||
);
|
||||
await until(() => !preview.busy);
|
||||
});
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<CustomPaint>(selection).painter!.shouldRepaint(previous),
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
expect(calls.where((c) => c.method == 'seek'), hasLength(seeks));
|
||||
expect(
|
||||
calls.where((c) => c.method == 'beginInteractiveTransform'),
|
||||
isEmpty,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
test('alignment tools share geometry, preserve rotation and undo, and never seek', () async {
|
||||
final fixture = await createPreviewFixture(Uri.file('/align.mov'));
|
||||
final timeline = fixture.timeline;
|
||||
@@ -754,6 +926,136 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
for (final animated in [false, true]) {
|
||||
testWidgets('mask inspector follows playback with animated=$animated', (
|
||||
tester,
|
||||
) async {
|
||||
final fixture = (await tester.runAsync(
|
||||
() => createPreviewFixture(Uri.file('/mask-playback.mov')),
|
||||
))!;
|
||||
final timeline = fixture.timeline;
|
||||
final sequence = SequenceId('one');
|
||||
final clip = ElementId('clip');
|
||||
const maskId = 'playback-mask';
|
||||
await tester.runAsync(() async {
|
||||
timeline.commands.addMask(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
maskId: maskId,
|
||||
shape: ClipMaskShape.rectangle,
|
||||
);
|
||||
timeline.commands.setMask(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
maskId: maskId,
|
||||
value: const ClipMask(x: .25),
|
||||
);
|
||||
if (animated) {
|
||||
timeline.commands.editKeyframeChannel(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: 0,
|
||||
parameterIds: ['mask.$maskId.center.x'],
|
||||
);
|
||||
timeline.commands.setMask(
|
||||
sequence: sequence,
|
||||
clip: clip,
|
||||
tick: TimelineClock.ticksPerSecond,
|
||||
maskId: maskId,
|
||||
value: const ClipMask(x: .75),
|
||||
);
|
||||
}
|
||||
await timeline.flush();
|
||||
});
|
||||
final preview = PreviewController(
|
||||
timeline: timeline,
|
||||
activeSequence: () => timeline.activeSequenceId,
|
||||
viewForSequence: timeline.view,
|
||||
runtime: CutdexRuntime(),
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.runAsync(() async {
|
||||
await preview.close();
|
||||
await fixture.workspace.close();
|
||||
await fixture.directory.delete(recursive: true);
|
||||
}),
|
||||
);
|
||||
await tester.runAsync(() async {
|
||||
await preview.initialize();
|
||||
await until(() => calls.any((c) => c.method == 'seek'));
|
||||
});
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
editorPreviewProvider(
|
||||
'project',
|
||||
'project',
|
||||
).overrideWith((ref) async => preview),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: MaskProperties(
|
||||
projectId: 'project',
|
||||
timelineId: 'project',
|
||||
element: clip,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final xField = find.byWidgetPredicate(
|
||||
(widget) => widget is PropertyNumberInput && widget.label == 'X',
|
||||
);
|
||||
expect(tester.widget<PropertyNumberInput>(xField).value, 25);
|
||||
Future<void> advance(int seconds) async {
|
||||
await tester.runAsync(() async {
|
||||
emit({
|
||||
'state': 'playing',
|
||||
'revision': revision,
|
||||
'position': MediaTime(seconds, 1).toMap(),
|
||||
'rate': 1.0,
|
||||
});
|
||||
await until(
|
||||
() =>
|
||||
preview.playing &&
|
||||
preview.positionTick == seconds * TimelineClock.ticksPerSecond,
|
||||
);
|
||||
});
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
await advance(0);
|
||||
final before = tester.widget<PropertyNumberInput>(xField);
|
||||
var controlNotifications = 0;
|
||||
preview.addListener(() => controlNotifications++);
|
||||
await advance(1);
|
||||
expect(
|
||||
controlNotifications,
|
||||
0,
|
||||
reason: 'Playback ticks only notify position listeners',
|
||||
);
|
||||
expect(preview.maskFor(clip)!.x, animated ? .75 : .25);
|
||||
expect(
|
||||
tester.widget<PropertyNumberInput>(xField).value,
|
||||
animated ? 75 : 25,
|
||||
);
|
||||
if (!animated) {
|
||||
expect(tester.widget<PropertyNumberInput>(xField), same(before));
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('mask inspector adds a shape and grouped keys at compact width', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in new issue
Block a user