fix: Avoid unnecessary NotebookTab updates (#5068)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix 2024-01-06 12:04:04 +01:00 committed by GitHub
parent 99b537ffd9
commit 1192393039
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions

View file

@ -108,6 +108,7 @@
- Dev: Refactor Args to be less of a singleton. (#5041) - 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: 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: Autogenerate docs/plugin-meta.lua. (#5055)
- Dev: Fix `NotebookTab` emitting updates for every message. (#5068)
## 2.4.6 ## 2.4.6

View file

@ -346,17 +346,25 @@ bool NotebookTab::isLive() const
void NotebookTab::setHighlightState(HighlightState newHighlightStyle) void NotebookTab::setHighlightState(HighlightState newHighlightStyle)
{ {
if (this->isSelected() || (!this->highlightEnabled_ && if (this->isSelected())
newHighlightStyle == HighlightState::NewMessage))
{ {
return; return;
} }
if (this->highlightState_ != HighlightState::Highlighted)
{
this->highlightState_ = newHighlightStyle;
this->update(); if (!this->highlightEnabled_ &&
newHighlightStyle == HighlightState::NewMessage)
{
return;
} }
if (this->highlightState_ == newHighlightStyle ||
this->highlightState_ == HighlightState::Highlighted)
{
return;
}
this->highlightState_ = newHighlightStyle;
this->update();
} }
HighlightState NotebookTab::highlightState() const HighlightState NotebookTab::highlightState() const

View file

@ -91,8 +91,7 @@ TEST_F(NotebookTabFixture, UpgradeHighlightState)
/// The highlight state must stay as NewMessage when called twice /// The highlight state must stay as NewMessage when called twice
TEST_F(NotebookTabFixture, SameHighlightStateNewMessage) TEST_F(NotebookTabFixture, SameHighlightStateNewMessage)
{ {
// XXX: This only updates the state once, so it should only update once EXPECT_CALL(this->tab, update).Times(Exactly(1));
EXPECT_CALL(this->tab, update).Times(Exactly(2));
EXPECT_EQ(this->tab.highlightState(), HighlightState::None); EXPECT_EQ(this->tab.highlightState(), HighlightState::None);
this->tab.setHighlightState(HighlightState::NewMessage); this->tab.setHighlightState(HighlightState::NewMessage);
EXPECT_EQ(this->tab.highlightState(), HighlightState::NewMessage); EXPECT_EQ(this->tab.highlightState(), HighlightState::NewMessage);