- ContentList c = _parent->selected ();
- for (ContentList::iterator i = c.begin(); i != c.end(); ++i) {
- (*i)->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
+ DCPTime const ph = _viewer->position ();
+
+ _viewer->set_coalesce_player_changes (true);
+
+ shared_ptr<Content> ref;
+ optional<FrameRateChange> ref_frc;
+ optional<DCPTime> ref_ph;
+ BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
+ if (i->position() <= ph && ph < i->end()) {
+ /* The playhead is in i. Use it as a reference to work out
+ where to put the playhead post-trim; we're trying to keep the playhead
+ at the same frame of content that we're looking at pre-trim.
+ */
+ ref = i;
+ ref_frc = _parent->film()->active_frame_rate_change (i->position ());
+ ref_ph = ph - i->position() + DCPTime (i->trim_start(), ref_frc.get());
+ }
+
+ i->set_trim_start (_trim_start->get (_parent->film()->video_frame_rate ()));
+ }
+
+ if (ref) {
+ _viewer->set_position (max (DCPTime(), ref_ph.get() + ref->position() - DCPTime (ref->trim_start(), ref_frc.get())));