[apps/solver] Fix addition of "=0" to equations

ShiftRight no longer puts the cursor at the end of the text/layout.
This commit is contained in:
Léa Saviot
2020-01-31 13:55:05 +01:00
parent c5315189ac
commit 963edd5c35
3 changed files with 10 additions and 4 deletions

View File

@@ -125,10 +125,11 @@ bool layoutRepresentsAnEquality(Poincare::Layout l) {
bool ListController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
if (textField->isEditing() && textField->shouldFinishEditing(event)) {
if (!textRepresentsAnEquality(textField->text())) {
textField->handleEvent(Ion::Events::ShiftRight);
const char * text = textField->text();
if (!textRepresentsAnEquality(text)) {
textField->setCursorLocation(text + strlen(text));
textField->handleEventWithText("=0");
if (!textRepresentsAnEquality(textField->text())) {
if (!textRepresentsAnEquality(text)) {
Container::activeApp()->displayWarning(I18n::Message::RequireEquation);
return true;
}
@@ -143,7 +144,7 @@ bool ListController::textFieldDidReceiveEvent(TextField * textField, Ion::Events
bool ListController::layoutFieldDidReceiveEvent(LayoutField * layoutField, Ion::Events::Event event) {
if (layoutField->isEditing() && layoutField->shouldFinishEditing(event)) {
if (!layoutRepresentsAnEquality(layoutField->layout())) {
layoutField->handleEvent(Ion::Events::ShiftRight);
layoutField->putCursorRightOfLayout();
layoutField->handleEventWithText("=0");
if (!layoutRepresentsAnEquality(layoutField->layout())) {
Container::activeApp()->displayWarning(I18n::Message::RequireEquation);

View File

@@ -30,6 +30,7 @@ public:
bool hasText() const { return layout().hasText(); }
Poincare::Layout layout() const { return m_contentView.expressionView()->layout(); }
CodePoint XNTCodePoint(CodePoint defaultXNTCodePoint) override;
void putCursorRightOfLayout();
// ScrollableView
void setBackgroundColor(KDColor c) override {

View File

@@ -295,6 +295,10 @@ CodePoint LayoutField::XNTCodePoint(CodePoint defaultXNTCodePoint) {
return defaultXNTCodePoint;
}
void LayoutField::putCursorRightOfLayout() {
m_contentView.setCursor(LayoutCursor(m_contentView.expressionView()->layout(), LayoutCursor::Position::Right));
}
void LayoutField::reload(KDSize previousSize) {
layout().invalidAllSizesPositionsAndBaselines();
KDSize newSize = minimalSizeForOptimalDisplay();