[poincare] Fix layout insertion

This commit is contained in:
Léa Saviot
2018-07-06 11:35:52 +02:00
parent fa8da9b238
commit 785df118dc
2 changed files with 6 additions and 7 deletions

View File

@@ -243,14 +243,15 @@ void LayoutField::insertLayoutAtCursor(LayoutRef layoutR, LayoutRef pointedLayou
LayoutRef lastMergedLayoutChild = layoutWillBeMerged ? layoutR.childAtIndex(layoutR.numberOfChildren()-1) : LayoutRef(nullptr);
m_contentView.cursor()->addLayoutAndMoveCursor(layoutR);
if (!forceCursorRightOfLayout) {
if (pointedLayoutR.isDefined() && (!layoutWillBeMerged || pointedLayoutR != layoutR)) {
if (pointedLayoutR.isDefined() && pointedLayoutR.parent().isDefined() && (!layoutWillBeMerged || pointedLayoutR != layoutR)) {
// Make sure the layout was inserted (its parent is not nullptr)
m_contentView.cursor()->setLayoutReference(pointedLayoutR);
m_contentView.cursor()->setPosition(LayoutCursor::Position::Right);
} else if (!layoutWillBeMerged ) { //&& !layoutR.isAllocationFailure()) {
} else if (!layoutWillBeMerged && layoutR.parent().isDefined()) { //&& !layoutR.isAllocationFailure()) {
m_contentView.cursor()->setLayoutReference(layoutR.layoutToPointWhenInserting());
m_contentView.cursor()->setPosition(LayoutCursor::Position::Right);
}
} else if (!layoutWillBeMerged) {
} else if (!layoutWillBeMerged && layoutR.parent().isDefined()) {
m_contentView.cursor()->setLayoutReference(layoutR);
m_contentView.cursor()->setPosition(LayoutCursor::Position::Right);
}

View File

@@ -107,11 +107,9 @@ void LayoutCursor::insertText(const char * text) {
else {
newChild = CharLayoutRef(text[i]);
}
m_layoutRef.addSibling(this, newChild);
m_layoutRef = newChild;
m_position = Position::Right;
m_layoutRef.addSiblingAndMoveCursor(this, newChild);
}
if (pointedChild.isDefined()) {
if (pointedChild.isDefined() && pointedChild.parent().isDefined()) {
m_layoutRef = pointedChild;
}
}