# HG changeset patch # User Chris Cannam # Date 1222086034 0 # Node ID fc19435ac0f5d14de7ec02a8cd37d39b5e106a95 # Parent f71752646f972239bebf19886a7980d2c14f9ba1 * Improve snap policy for selecting regions diff -r f71752646f97 -r fc19435ac0f5 layer/RegionLayer.cpp --- a/layer/RegionLayer.cpp Fri Sep 19 14:05:34 2008 +0000 +++ b/layer/RegionLayer.cpp Mon Sep 22 12:20:34 2008 +0000 @@ -342,8 +342,8 @@ bool RegionLayer::snapToFeatureFrame(View *v, int &frame, - size_t &resolution, - SnapType snap) const + size_t &resolution, + SnapType snap) const { if (!m_model) { return Layer::snapToFeatureFrame(v, frame, resolution, snap); @@ -369,11 +369,22 @@ if (snap == SnapRight) { - if (i->frame > frame) { - snapped = i->frame; - found = true; - break; - } + // The best frame to snap to is the end frame of whichever + // feature we would have snapped to the start frame of if + // we had been snapping left. + + if (i->frame <= frame) { + if (i->frame + i->duration > frame) { + snapped = i->frame + i->duration; + found = true; // don't break, as the next may be better + } + } else { + if (!found) { + snapped = i->frame; + found = true; + } + break; + } } else if (snap == SnapLeft) {