summaryrefslogtreecommitdiff
path: root/src/modlistviewactions.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-11 19:15:39 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-11 19:15:39 +0100
commit08520822eb91c065a0893da0e2e9d11574450208 (patch)
treed137ce8d040e8b149876b4e986dd817e3d25e56a /src/modlistviewactions.cpp
parente53905329a7a204ad0ad41600a9fb3040b942991 (diff)
Fix drop in separator and create mod in separator in descending priority.
Diffstat (limited to 'src/modlistviewactions.cpp')
-rw-r--r--src/modlistviewactions.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/modlistviewactions.cpp b/src/modlistviewactions.cpp
index cc50f009..09142026 100644
--- a/src/modlistviewactions.cpp
+++ b/src/modlistviewactions.cpp
@@ -103,22 +103,33 @@ void ModListViewActions::createEmptyMod(const QModelIndex& index) const
auto info = ModInfo::getByIndex(mIndex);
newPriority = m_core.currentProfile()->getModPriority(mIndex);
if (info->isSeparator()) {
+
+ auto isSeparator = [](const auto& p) {
+ return ModInfo::getByIndex(p.second)->isSeparator();
+ };
+
auto& ibp = m_core.currentProfile()->getAllIndexesByPriority();
- // start right after the current priority and look for the next
+ // start right after/before the current priority and look for the next
// separator
- auto it = ibp.find(newPriority + 1);
- for (; it != ibp.end(); ++it) {
- auto info = ModInfo::getByIndex(it->second);
- if (info->isSeparator()) {
+ if (m_view->sortOrder() == Qt::AscendingOrder) {
+ auto it = std::find_if(ibp.find(newPriority + 1), ibp.end(), isSeparator);
+ if (it != ibp.end()) {
newPriority = it->first;
- break;
+ }
+ else {
+ newPriority = -1;
}
}
-
- // no separator found, create at the end
- if (it == ibp.end()) {
- newPriority = -1;
+ else {
+ auto it = std::find_if(std::reverse_iterator{ ibp.find(newPriority - 1) }, ibp.rend(), isSeparator);
+ if (it != ibp.rend()) {
+ newPriority = it->first + 1;
+ }
+ else {
+ // create "before" priority 0, i.e. at the end in descending priority.
+ newPriority = 0;
+ }
}
}
}