Skip to content

Commit

Permalink
Fix crash that would occur when performing certain actions after remo…
Browse files Browse the repository at this point in the history
…ving all tabs (#4271)

* Ensure we can deselect notebooks

* Add changelog entry

* Use dynamic_cast instead of raw cast
  • Loading branch information
pajlada authored Dec 29, 2022
1 parent 11fdd7e commit 90046f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Minor: Tables in settings window will now scroll to newly added rows. (#4216)
- Minor: Added link to streamlink docs for easier user setup. (#4217)
- Minor: Added setting to turn off rendering of reply context. (#4224)
- Bugfix: Fixed crash that would occur when performing certain actions after removing all tabs. (#4271)
- Bugfix: Fixed highlight sounds not reloading on change properly. (#4194)
- Bugfix: Fixed CTRL + C not working in reply thread popups. (#4209)
- Bugfix: Fixed message input showing as red after removing a message that was more than 500 characters. (#4204)
Expand Down
66 changes: 37 additions & 29 deletions src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,49 +156,50 @@ int Notebook::indexOf(QWidget *page) const

void Notebook::select(QWidget *page, bool focusPage)
{
if (!page)
{
return;
}

if (page == this->selectedPage_)
{
// Nothing has changed
return;
}

auto *item = this->findItem(page);
if (!item)
if (page)
{
return;
}
// A new page has been selected, mark it as selected & focus one of its splits
auto *item = this->findItem(page);
if (!item)
{
return;
}

page->show();
page->show();

item->tab->setSelected(true);
item->tab->raise();
item->tab->setSelected(true);
item->tab->raise();

if (focusPage)
{
if (item->selectedWidget == nullptr)
if (focusPage)
{
item->page->setFocus();
}
else
{
if (containsChild(page, item->selectedWidget))
if (item->selectedWidget == nullptr)
{
item->selectedWidget->setFocus(Qt::MouseFocusReason);
item->page->setFocus();
}
else
{
qCDebug(chatterinoWidget) << "Notebook: selected child of "
"page doesn't exist anymore";
if (containsChild(page, item->selectedWidget))
{
item->selectedWidget->setFocus(Qt::MouseFocusReason);
}
else
{
qCDebug(chatterinoWidget) << "Notebook: selected child of "
"page doesn't exist anymore";
}
}
}
}

if (this->selectedPage_ != nullptr)
if (this->selectedPage_)
{
// Hide the previously selected page
this->selectedPage_->hide();

auto *item = this->findItem(selectedPage_);
Expand Down Expand Up @@ -1169,22 +1170,29 @@ SplitContainer *SplitNotebook::getOrAddSelectedPage()
{
auto *selectedPage = this->getSelectedPage();

return selectedPage != nullptr ? (SplitContainer *)selectedPage
: this->addPage();
if (selectedPage)
{
return dynamic_cast<SplitContainer *>(selectedPage);
}

return this->addPage();
}

void SplitNotebook::select(QWidget *page, bool focusPage)
{
if (auto selectedPage = this->getSelectedPage())
// If there's a previously selected page, go through its splits and
// update their "last read message" indicator
if (auto *selectedPage = this->getSelectedPage())
{
if (auto splitContainer = dynamic_cast<SplitContainer *>(selectedPage))
if (auto *splitContainer = dynamic_cast<SplitContainer *>(selectedPage))
{
for (auto split : splitContainer->getSplits())
for (auto *split : splitContainer->getSplits())
{
split->updateLastReadMessage();
}
}
}

this->Notebook::select(page, focusPage);
}

Expand Down

0 comments on commit 90046f3

Please sign in to comment.