Commit ccc7884b authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix various spacer crashes

parent b74e28aa
Pipeline #59258 skipped
......@@ -325,6 +325,7 @@ bool TimelineFunctions::requestClipCutAll(std::shared_ptr<TimelineItemModel> tim
int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<TimelineItemModel> &timeline, int trackId, int position)
{
std::unordered_set<int> clips = timeline->getItemsInRange(trackId, position, -1);
timeline->requestClearSelection();
if (!clips.empty()) {
// Remove grouped items that are before the click position
// First get top groups ids
......@@ -332,16 +333,24 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
spacerUngroupedItems.clear();
std::transform(clips.begin(), clips.end(), std::inserter(roots, roots.begin()), [&](int id) { return timeline->m_groups->getRootId(id); });
std::unordered_set<int> groupsToRemove;
int firstCid = -1;
int firstPosition = -1;
for (int r : roots) {
if (timeline->isGroup(r)) {
std::unordered_set<int> leaves = timeline->m_groups->getLeaves(r);
std::unordered_set<int> leavesToRemove;
std::unordered_set<int> leavesToKeep;
for (int l : leaves) {
if (timeline->getItemPosition(l) + timeline->getItemPlaytime(l) < position) {
int pos = timeline->getItemPosition(l);
if (pos + timeline->getItemPlaytime(l) < position) {
leavesToRemove.insert(l);
} else {
leavesToKeep.insert(l);
// Find first item
if (firstPosition == -1 || pos < firstPosition) {
firstCid = l;
firstPosition = pos;
}
}
}
if (leavesToKeep.size() == 1) {
......@@ -370,7 +379,7 @@ int TimelineFunctions::requestSpacerStartOperation(const std::shared_ptr<Timelin
timeline->m_groups->ungroupItem(i.key(), undo, redo);
}
timeline->requestSetSelection(roots);
return (*roots.cbegin());
return (firstCid);
}
return -1;
}
......@@ -1885,21 +1894,7 @@ bool TimelineFunctions::requestDeleteBlankAt(const std::shared_ptr<TimelineItemM
if (cid == -1) {
return false;
}
int start = -1;
if (timeline->isGroup(cid)) {
std::unordered_set<int> sub = timeline->m_groups->getLeaves(cid);
cid = *sub.cbegin();
int start = timeline->getItemPosition(cid);
for (int current_id : sub) {
int st = timeline->getItemPosition(current_id);
if (st < start) {
cid = current_id;
start = st;
}
}
} else {
start = timeline->getItemPosition(cid);
}
int start = timeline->getItemPosition(cid);
// Start undoable command
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
......
......@@ -2109,21 +2109,7 @@ void TimelineController::insertSpace(int trackId, int frame)
pCore->displayMessage(i18n("No clips found to insert space"), ErrorMessage, 500);
return;
}
int start = -1;
if (m_model->isGroup(cid)) {
std::unordered_set<int> sub = m_model->m_groups->getLeaves(cid);
cid = *sub.cbegin();
int start = m_model->getItemPosition(cid);
for (int current_id : sub) {
int st = m_model->getItemPosition(current_id);
if (st < start) {
cid = current_id;
start = st;
}
}
} else {
start = m_model->getItemPosition(cid);
}
int start = m_model->getItemPosition(cid);
requestSpacerEndOperation(cid, start, start + spaceDuration, affectAllTracks ? -1 : trackId);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment