Skip to content

Commit 85f96a7

Browse files
committed
fix #571: Get processed bubble text before passing to interfaces
1 parent 694f1bf commit 85f96a7

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/scratch/sprite.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,17 @@ void Sprite::setBubbleType(BubbleType type)
557557
void Sprite::setBubbleText(const std::string &text)
558558
{
559559
Target::setBubbleText(impl->visible ? text : "");
560+
const std::string &finalText = bubbleText();
560561

561-
if (impl->visible && !text.empty()) {
562+
if (impl->visible && !finalText.empty()) {
562563
IEngine *eng = engine();
563564

564565
if (eng)
565566
eng->requestRedraw();
566567
}
567568

568569
if (impl->iface)
569-
impl->iface->onBubbleTextChanged(impl->visible ? text : "");
570+
impl->iface->onBubbleTextChanged(impl->visible ? finalText : "");
570571
}
571572

572573
Target *Sprite::dataSource() const

src/scratch/stage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,17 @@ void Stage::setBubbleType(BubbleType type)
233233
void Stage::setBubbleText(const std::string &text)
234234
{
235235
Target::setBubbleText(text);
236+
const std::string &finalText = bubbleText();
236237

237-
if (!text.empty()) {
238+
if (!finalText.empty()) {
238239
IEngine *eng = engine();
239240

240241
if (eng)
241242
eng->requestRedraw();
242243
}
243244

244245
if (impl->iface)
245-
impl->iface->onBubbleTextChanged(text);
246+
impl->iface->onBubbleTextChanged(finalText);
246247
}
247248

248249
bool Stage::touchingClones(const std::vector<Sprite *> &clones) const

test/target_interfaces/ispritehandler_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,25 @@ TEST_F(ISpriteHandlerTest, BubbleText)
200200
EXPECT_CALL(m_handler, onBubbleTextChanged("test"));
201201
EXPECT_CALL(m_engine, requestRedraw());
202202
m_sprite.setBubbleText("test");
203+
204+
// The text should be processed in Target::setBubbleText() (#571)
205+
std::string longstr =
206+
"EY8OUNzAqwgh7NRGk5TzCP3dkAhJy9TX"
207+
"Y9mqKElPjdQpKddYqjyCwUk2hx6YgVZV"
208+
"6BOdmZGxDMs8Hjv8W9G6j4gTxAWdOkzs"
209+
"8Ih80xzEDbvLilWsDwoB6FxH2kVVI4xs"
210+
"IXOETNQ6QMsCKLWc5XjHk2BS9nYvDGpJ"
211+
"uEmp9zIzFGT1kRSrOlU3ZwnN1YtvqFx"
212+
"3hkWVNtJ71dQ0PJHhOVQPUy19V01SPu3"
213+
"KIIS2wdSUVAc4RYMzepSveghzWbdcizy"
214+
"Tm1KKAj4svu9YoL8b9vsolG8gKunvKO7"
215+
"MurRKSeUbECELnJEKV6683xCq7RvmjAu"
216+
"2djZ54apiQc1lTixWns5GoG0SVNuFzHl"
217+
"q97qUiqiMecjVFM51YVif7c1Stip52Hl";
218+
219+
EXPECT_CALL(m_handler, onBubbleTextChanged(longstr.substr(0, 330)));
220+
EXPECT_CALL(m_engine, requestRedraw());
221+
m_sprite.setBubbleText(longstr);
203222
}
204223

205224
TEST_F(ISpriteHandlerTest, BoundingRect)

test/target_interfaces/istagehandler_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,25 @@ TEST_F(IStageHandlerTest, BubbleText)
8383
EXPECT_CALL(m_handler, onBubbleTextChanged("test"));
8484
EXPECT_CALL(m_engine, requestRedraw());
8585
m_stage.setBubbleText("test");
86+
87+
// The text should be processed in Target::setBubbleText() (#571)
88+
std::string longstr =
89+
"EY8OUNzAqwgh7NRGk5TzCP3dkAhJy9TX"
90+
"Y9mqKElPjdQpKddYqjyCwUk2hx6YgVZV"
91+
"6BOdmZGxDMs8Hjv8W9G6j4gTxAWdOkzs"
92+
"8Ih80xzEDbvLilWsDwoB6FxH2kVVI4xs"
93+
"IXOETNQ6QMsCKLWc5XjHk2BS9nYvDGpJ"
94+
"uEmp9zIzFGT1kRSrOlU3ZwnN1YtvqFx"
95+
"3hkWVNtJ71dQ0PJHhOVQPUy19V01SPu3"
96+
"KIIS2wdSUVAc4RYMzepSveghzWbdcizy"
97+
"Tm1KKAj4svu9YoL8b9vsolG8gKunvKO7"
98+
"MurRKSeUbECELnJEKV6683xCq7RvmjAu"
99+
"2djZ54apiQc1lTixWns5GoG0SVNuFzHl"
100+
"q97qUiqiMecjVFM51YVif7c1Stip52Hl";
101+
102+
EXPECT_CALL(m_handler, onBubbleTextChanged(longstr.substr(0, 330)));
103+
EXPECT_CALL(m_engine, requestRedraw());
104+
m_stage.setBubbleText(longstr);
86105
}
87106

88107
TEST_F(IStageHandlerTest, BoundingRect)

0 commit comments

Comments
 (0)