mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/poincare] Fix cursor position when inserting log(a,b) in 2DEdition
This commit is contained in:
@@ -122,9 +122,10 @@ bool textRepresentsAnEquality(const char * text) {
|
||||
}
|
||||
|
||||
bool layoutRepresentsAnEquality(Poincare::Layout l) {
|
||||
return l.recursivelyMatches(
|
||||
Poincare::Layout match = l.recursivelyMatches(
|
||||
[](Poincare::Layout layout) {
|
||||
return layout.isChar() && static_cast<Poincare::CharLayout &>(layout).character() == '"'; });
|
||||
return !match.isUninitialized();
|
||||
}
|
||||
|
||||
bool ListController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
|
||||
|
||||
@@ -129,19 +129,15 @@ bool LayoutField::handleEventWithText(const char * text, bool indentation, bool
|
||||
}
|
||||
// Find the pointed layout.
|
||||
Layout pointedLayout;
|
||||
if (strcmp(text, I18n::translate(I18n::Message::RandomCommandWithArg)) == 0) {
|
||||
/* Special case: if the text is "random()", the cursor should not be set
|
||||
* inside the parentheses. */
|
||||
pointedLayout = resultLayout;
|
||||
} else if (resultLayout.isHorizontal()) {
|
||||
/* If the layout is horizontal, pick the first open parenthesis. For now,
|
||||
* all horizontal layouts in MathToolbox have parentheses. */
|
||||
for (int i = 0; i < resultLayout.numberOfChildren(); i++) {
|
||||
Layout l = resultLayout.childAtIndex(i);
|
||||
if (l.isLeftParenthesis()) {
|
||||
pointedLayout = l;
|
||||
break;
|
||||
}
|
||||
if (!forceCursorRightOfText) {
|
||||
if (strcmp(text, I18n::translate(I18n::Message::RandomCommandWithArg)) == 0) {
|
||||
/* Special case: if the text is "random()", the cursor should not be set
|
||||
* inside the parentheses. */
|
||||
pointedLayout = resultLayout;
|
||||
} else if (resultLayout.isHorizontal()) {
|
||||
pointedLayout = resultLayout.recursivelyMatches(
|
||||
[](Poincare::Layout layout) {
|
||||
return layout.isLeftParenthesis() || layout.isEmpty();});
|
||||
}
|
||||
}
|
||||
/* Insert the layout. If pointedLayout is uninitialized, the cursor will
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
|
||||
// Layout properties
|
||||
typedef bool (*LayoutTest)(const Layout l);
|
||||
bool recursivelyMatches(LayoutTest test) const;
|
||||
Layout recursivelyMatches(LayoutTest test) const;
|
||||
bool mustHaveLeftSibling() const { return const_cast<Layout *>(this)->node()->mustHaveLeftSibling(); }
|
||||
bool isEmpty() const { return const_cast<Layout *>(this)->node()->isEmpty(); }
|
||||
bool isHorizontal() const { return const_cast<Layout *>(this)->node()->isHorizontal(); }
|
||||
|
||||
@@ -36,16 +36,17 @@ int Layout::serializeParsedExpression(char * buffer, int bufferSize) const {
|
||||
return e.serialize(buffer, bufferSize, Poincare::Preferences::sharedPreferences()->displayMode());
|
||||
}
|
||||
|
||||
bool Layout::recursivelyMatches(LayoutTest test) const {
|
||||
Layout Layout::recursivelyMatches(LayoutTest test) const {
|
||||
if (test(*this)) {
|
||||
return true;
|
||||
return *this;
|
||||
}
|
||||
for (int i = 0; i < numberOfChildren(); i++) {
|
||||
if (childAtIndex(i).recursivelyMatches(test)) {
|
||||
return true;
|
||||
Layout childResult = childAtIndex(i).recursivelyMatches(test);
|
||||
if (!childResult.isUninitialized()) {
|
||||
return childResult;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return Layout();
|
||||
}
|
||||
|
||||
// Cursor
|
||||
|
||||
Reference in New Issue
Block a user