Skip to content

Commit

Permalink
fix: Avoid unnecessary NotebookTab updates (#5068)
Browse files Browse the repository at this point in the history
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
  • Loading branch information
Nerixyz and pajlada authored Jan 6, 2024
1 parent 99b537f commit 1192393
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
- Dev: Refactor Args to be less of a singleton. (#5041)
- Dev: Channels without any animated elements on screen will skip updates from the GIF timer. (#5042, #5043, #5045)
- Dev: Autogenerate docs/plugin-meta.lua. (#5055)
- Dev: Fix `NotebookTab` emitting updates for every message. (#5068)

## 2.4.6

Expand Down
18 changes: 13 additions & 5 deletions src/widgets/helper/NotebookTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,25 @@ bool NotebookTab::isLive() const

void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
{
if (this->isSelected() || (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage))
if (this->isSelected())
{
return;
}
if (this->highlightState_ != HighlightState::Highlighted)

if (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage)
{
this->highlightState_ = newHighlightStyle;
return;
}

this->update();
if (this->highlightState_ == newHighlightStyle ||
this->highlightState_ == HighlightState::Highlighted)
{
return;
}

this->highlightState_ = newHighlightStyle;
this->update();
}

HighlightState NotebookTab::highlightState() const
Expand Down
3 changes: 1 addition & 2 deletions tests/src/NotebookTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ TEST_F(NotebookTabFixture, UpgradeHighlightState)
/// The highlight state must stay as NewMessage when called twice
TEST_F(NotebookTabFixture, SameHighlightStateNewMessage)
{
// XXX: This only updates the state once, so it should only update once
EXPECT_CALL(this->tab, update).Times(Exactly(2));
EXPECT_CALL(this->tab, update).Times(Exactly(1));
EXPECT_EQ(this->tab.highlightState(), HighlightState::None);
this->tab.setHighlightState(HighlightState::NewMessage);
EXPECT_EQ(this->tab.highlightState(), HighlightState::NewMessage);
Expand Down

0 comments on commit 1192393

Please sign in to comment.