Skip to content

Commit 2c7eb8a

Browse files
committed
Block: Set next and parent ID properly
1 parent 119aa26 commit 2c7eb8a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/scratch/block.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ std::shared_ptr<Block> Block::next() const
6666
/*! Returns the ID of the next block. */
6767
std::string Block::nextId() const
6868
{
69-
if (impl->next)
70-
return impl->next->id();
71-
else
72-
return impl->nextId;
69+
return impl->nextId;
7370
}
7471

7572
/*! Sets the next block. */
7673
void Block::setNext(std::shared_ptr<Block> block)
7774
{
7875
impl->next = block;
76+
77+
if (block)
78+
impl->nextId = block->id();
79+
else
80+
impl->nextId = "";
7981
}
8082

8183
/*! Sets the next block by ID. */
@@ -94,16 +96,18 @@ std::shared_ptr<Block> Block::parent() const
9496
/*! Returns the ID of the parent block. */
9597
std::string Block::parentId() const
9698
{
97-
if (impl->parent)
98-
return impl->parent->id();
99-
else
100-
return impl->parentId;
99+
return impl->parentId;
101100
}
102101

103102
/*! Sets the parent block. */
104103
void Block::setParent(std::shared_ptr<Block> block)
105104
{
106105
impl->parent = block;
106+
107+
if (block)
108+
impl->parentId = block->id();
109+
else
110+
impl->parentId = "";
107111
}
108112

109113
/*! Sets the parent block by ID. */

0 commit comments

Comments
 (0)