mirror of
https://github.com/storytold/filmcraft.git
synced 2026-12-02 20:19:02 -05:00
Merge pull request #4841 from gmrmad1/fix/markers-add-duration-validation
markers: validate markers.add durationFrames
This commit is contained in:
2 files changed
+31
-1
No files matched your search
@@ -3154,7 +3154,16 @@ fn build() -> Vec<CommandSpec> {
|
||||
let comment = str_p(p, "comment").unwrap_or("").to_string();
|
||||
let (color, custom_color) = marker_color_p(p, "markers.add")?.unwrap_or((Label::Green, None));
|
||||
let author = marker_author_p(p, "markers.add")?.unwrap_or_default();
|
||||
let dur = p.get("durationFrames").and_then(Value::as_i64).map(|f| s.sequence_rate().tick_of(f)).unwrap_or_default();
|
||||
let dur = match p.get("durationFrames").filter(|v| !v.is_null()) {
|
||||
None => Tick::ZERO,
|
||||
Some(value) => {
|
||||
let frames = value
|
||||
.as_i64()
|
||||
.filter(|f| (0..=10_000_000).contains(f))
|
||||
.ok_or_else(|| bad("markers.add", "durationFrames must be a whole number from 0 to 10000000"))?;
|
||||
s.sequence_rate().tick_of(frames)
|
||||
}
|
||||
};
|
||||
let id = s.edit_sequence("Add Marker", |q, ctx, _| {
|
||||
let id = MarkerId(ctx.alloc());
|
||||
q.markers.push(Marker {
|
||||
|
||||
@@ -712,6 +712,27 @@ fn edit_marker_sets_every_field_in_one_undo_step_and_rejects_hostile_values() {
|
||||
assert_eq!(marker(&s).name, "n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_marker_rejects_bad_duration_frames() {
|
||||
let mut s = demo();
|
||||
let before = s.project.to_json();
|
||||
for p in [json!({"durationFrames": -1}), json!({"durationFrames": 5.5}), json!({"durationFrames": 10_000_001}), json!({"durationFrames": "10"})] {
|
||||
let err = s.execute("markers.add", p.clone()).unwrap_err().to_string();
|
||||
assert!(err.contains("durationFrames must be a whole number from 0 to 10000000"), "{p} was refused for the wrong reason: {err}");
|
||||
assert_eq!(s.project.to_json(), before, "{p} must leave the project unchanged");
|
||||
}
|
||||
let id = s.execute("markers.add", json!({"frame": 10, "durationFrames": 10})).unwrap()["marker"].as_u64().unwrap();
|
||||
let m = s.active_sequence().unwrap().markers.iter().find(|m| m.id.0 == id).unwrap().clone();
|
||||
assert_eq!(m.duration, s.sequence_rate().tick_of(10));
|
||||
// absent and null stay "no duration"
|
||||
let id = s.execute("markers.add", json!({"frame": 20})).unwrap()["marker"].as_u64().unwrap();
|
||||
let m = s.active_sequence().unwrap().markers.iter().find(|m| m.id.0 == id).unwrap().clone();
|
||||
assert_eq!(m.duration, Tick::ZERO);
|
||||
let id = s.execute("markers.add", json!({"frame": 30, "durationFrames": null})).unwrap()["marker"].as_u64().unwrap();
|
||||
let m = s.active_sequence().unwrap().markers.iter().find(|m| m.id.0 == id).unwrap().clone();
|
||||
assert_eq!(m.duration, Tick::ZERO);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_marker_holds_source_markers_to_the_same_rules() {
|
||||
// #2470 review: a Source marker's edit went around the `kind` and duration checks
|
||||
|
||||
Reference in new issue
Block a user