mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[expression_editor] Insert text char by char, using CharLayout.
Change-Id: Id5b146bf875c1cf1d9ac949258d43a5ed415a334
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "controller.h"
|
||||
#include <poincare/src/layout/char_layout.h> //TODO move from there.
|
||||
|
||||
namespace ExpressionEditor {
|
||||
|
||||
@@ -34,7 +35,8 @@ bool Controller::handleEvent(Ion::Events::Event event) {
|
||||
{
|
||||
returnValue = true;
|
||||
}
|
||||
else if (event.hasText() && m_expressionLayout->insertLayoutForTextAtCursor(event.text(), &m_cursor)) {
|
||||
else if (event.hasText()) {
|
||||
insertTextAtCursor(event.text());
|
||||
returnValue = true;
|
||||
m_expressionLayout->invalidAllSizesAndPositions();
|
||||
m_view.layoutSubviews();
|
||||
@@ -43,4 +45,20 @@ bool Controller::handleEvent(Ion::Events::Event event) {
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void Controller::insertTextAtCursor(const char * text) {
|
||||
int textLength = strlen(text);
|
||||
if (textLength <= 0) {
|
||||
return;
|
||||
}
|
||||
Poincare::CharLayout * newChild = nullptr;
|
||||
for (int i = 0; i < textLength; i++) {
|
||||
newChild = new Poincare::CharLayout(text[i]);
|
||||
m_cursor.pointedExpressionLayout()->addBrother(&m_cursor, newChild);
|
||||
}
|
||||
assert(newChild != nullptr);
|
||||
m_cursor.setPointedExpressionLayout(newChild);
|
||||
m_cursor.setPosition(Poincare::ExpressionLayoutCursor::Position::Right);
|
||||
m_cursor.setPositionInside(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user