Skip to content

Commit 4ce481f

Browse files
committed
fix #571: Get processed bubble text before passing to interfaces
1 parent a35433f commit 4ce481f

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
@@ -548,16 +548,17 @@ void Sprite::setBubbleType(BubbleType type)
548548
void Sprite::setBubbleText(const std::string &text)
549549
{
550550
Target::setBubbleText(impl->visible ? text : "");
551+
const std::string &finalText = bubbleText();
551552

552-
if (impl->visible && !text.empty()) {
553+
if (impl->visible && !finalText.empty()) {
553554
IEngine *eng = engine();
554555

555556
if (eng)
556557
eng->requestRedraw();
557558
}
558559

559560
if (impl->iface)
560-
impl->iface->onBubbleTextChanged(impl->visible ? text : "");
561+
impl->iface->onBubbleTextChanged(impl->visible ? finalText : "");
561562
}
562563

563564
Target *Sprite::dataSource() const

src/scratch/stage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,17 @@ void Stage::setBubbleType(BubbleType type)
224224
void Stage::setBubbleText(const std::string &text)
225225
{
226226
Target::setBubbleText(text);
227+
const std::string &finalText = bubbleText();
227228

228-
if (!text.empty()) {
229+
if (!finalText.empty()) {
229230
IEngine *eng = engine();
230231

231232
if (eng)
232233
eng->requestRedraw();
233234
}
234235

235236
if (impl->iface)
236-
impl->iface->onBubbleTextChanged(text);
237+
impl->iface->onBubbleTextChanged(finalText);
237238
}
238239

239240
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)