Skip to content

Commit

Permalink
Fix more tab management issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyschoen committed Jan 7, 2025
1 parent 070210a commit bec6112
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Source/Pd/Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ void Instance::initialisePd(String& pdlua_version)
}

MessageManager::callAsync([pd, subpatch] {

if(pd->patches.contains(subpatch, [](auto const& ptr1, auto const& ptr2){ return *ptr1 == *ptr2; })) {
return;
}

for (auto* editor : pd->getEditors()) {
if (!editor->isActiveWindow())
continue;
Expand Down
2 changes: 1 addition & 1 deletion Source/Pd/Patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Patch final : public ReferenceCountedObject {
// The compare equal operator.
bool operator==(Patch const& other) const
{
return getUncheckedPointer() == other.getUncheckedPointer();
return getRawPointer() == other.getRawPointer();
}

// Gets the bounds of the patch.
Expand Down
7 changes: 1 addition & 6 deletions Source/TabComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,9 @@ Canvas* TabComponent::openPatch(pd::Patch::Ptr existingPatch, bool const warnIfA
}
}

auto unique = pd->patches.add_unique(existingPatch, [](pd::Patch::Ptr const& ptr1, pd::Patch::Ptr const& ptr2){
pd->patches.add_unique(existingPatch, [](auto const& ptr1, auto const& ptr2){
return *ptr1 == *ptr2;
});
if(!unique) {
triggerAsyncUpdate();
return nullptr;
}

existingPatch->splitViewIndex = activeSplitIndex;
existingPatch->windowIndex = editor->editorIndex;
Expand Down Expand Up @@ -413,7 +409,6 @@ void TabComponent::handleAsyncUpdate()
}
}
}

if (!exists) {
canvases.remove(i);
}
Expand Down
9 changes: 8 additions & 1 deletion Source/Utility/Containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,13 @@ class SmallArrayImpl : public SmallArrayTemplateBase<T> {
{
return std::find(this->begin(), this->end(), to_find) != this->end();
}

template <typename Predicate>
[[nodiscard]] bool contains(T const& to_find, Predicate pred) {
return std::find_if(this->begin(), this->end(), [&to_find, pred](T const& element) {
return pred(element, to_find);
}) != this->end();
}

template<typename U>
[[nodiscard]] int index_of(U const& to_find) const
Expand Down Expand Up @@ -1888,7 +1895,7 @@ class HeapArray {
{
return std::find(data_.begin(), data_.end(), to_find) != end();
}

template<typename U>
[[nodiscard]] int index_of(U const& to_find) const
{
Expand Down

0 comments on commit bec6112

Please sign in to comment.