[escher] Fixed bugs in previous commit (XNT)

This commit is contained in:
Laury
2022-07-07 12:37:55 +02:00
parent 51a5f699c3
commit 1fbd5281a9
4 changed files with 19 additions and 16 deletions

View File

@@ -3,6 +3,7 @@
#include <apps/i18n.h>
#include "helpers.h"
#include <ion/unicode/utf8_helper.h>
#include <apps/apps_container.h>
namespace Code {
@@ -129,10 +130,19 @@ VariableBoxController * App::variableBoxForInputEventHandler(InputEventHandler *
}
bool App::textInputDidReceiveEvent(InputEventHandler * textInput, Ion::Events::Event event) {
bool shouldRemoveLastCharacter = false;
char buffer[CodePoint::MaxCodePointCharLength + 1];
if (Helpers::PythonTextForEvent(event, buffer, &shouldRemoveLastCharacter)) {
textInput->handleEventWithText(buffer, false, false, shouldRemoveLastCharacter);
if (event == Ion::Events::XNT) {
int bufferSize = CodePoint::MaxCodePointCharLength + 1;
char buffer[bufferSize];
bool shouldRemoveLastCharacter = false;
CodePoint codePoint = AppsContainer::sharedAppsContainer()->XNT('x', &shouldRemoveLastCharacter);
UTF8Decoder::CodePointToChars(codePoint, buffer, bufferSize);
buffer[UTF8Decoder::CharSizeOfCodePoint(codePoint)] = 0;
textInput->handleEventWithText(const_cast<char *>(buffer), false, false, shouldRemoveLastCharacter);
return true;
}
const char * pythonText = Helpers::PythonTextForEvent(event);
if (pythonText != nullptr) {
textInput->handleEventWithText(pythonText);
return true;
}
return false;

View File

@@ -1,24 +1,17 @@
#include "helpers.h"
#include <escher/clipboard.h>
#include <apps/apps_container.h>
namespace Code {
namespace Helpers {
bool PythonTextForEvent(Ion::Events::Event event, char * buffer, bool * shouldRemoveLastCharacter) {
const char * PythonTextForEvent(Ion::Events::Event event) {
for (size_t i=0; i<NumberOfPythonTextPairs; i++) {
UTF8Helper::TextPair pair = PythonTextPairs[i];
if (event.text() == pair.firstString()) {
strcpy(buffer, pair.secondString());
return true;
return pair.secondString();
}
if (event == Ion::Events::XNT) {
CodePoint XNT = AppsContainer::sharedAppsContainer()->XNT('x', shouldRemoveLastCharacter);
buffer[UTF8Decoder::CodePointToChars(XNT, buffer, CodePoint::MaxCodePointCharLength + 1)] = 0;
return true;
}
return false;
}
return nullptr;
}
}
}

View File

@@ -6,7 +6,7 @@
namespace Code {
namespace Helpers {
bool PythonTextForEvent(Ion::Events::Event event, char * buffer, bool * shouldRemoveLastCharacter);
const char * PythonTextForEvent(Ion::Events::Event event);
}
}