[escher] LayoutField: the insertion cursor can't point to an EmptyLayout

as it might be destroyed

This fixes the following crash: input 1, OK, input ans/[], go up to the history --> crash
This commit is contained in:
Émilie Feral
2020-05-22 09:58:42 +02:00
parent a53379781f
commit 79e7626dc3
2 changed files with 13 additions and 5 deletions

View File

@@ -87,11 +87,7 @@ private:
bool selectionIsEmpty() const;
void deleteSelection();
void invalidateInsertionCursor() { m_insertionCursor = Poincare::LayoutCursor(); }
void updateInsertionCursor() {
if (!m_insertionCursor.isDefined()) {
m_insertionCursor = m_cursor;
}
}
void updateInsertionCursor();
private:
int numberOfSubviews() const override { return 2; }

View File

@@ -2,6 +2,7 @@
#include <escher/clipboard.h>
#include <escher/text_field.h>
#include <poincare/expression.h>
#include <poincare/empty_layout.h>
#include <poincare/horizontal_layout.h>
#include <assert.h>
#include <string.h>
@@ -234,6 +235,17 @@ void LayoutField::ContentView::deleteSelection() {
resetSelection();
}
void LayoutField::ContentView::updateInsertionCursor() {
if (!m_insertionCursor.isDefined()) {
Layout l = m_cursor.layout();
if (l.type() == LayoutNode::Type::EmptyLayout && static_cast<EmptyLayout &>(l).color() == EmptyLayoutNode::Color::Grey) {
// Don't set m_insertionCursor pointing to a layout which might disappear
return;
}
m_insertionCursor = m_cursor;
}
}
View * LayoutField::ContentView::subviewAtIndex(int index) {
assert(0 <= index && index < numberOfSubviews());
View * m_views[] = {&m_expressionView, &m_cursorView};