[escher] Fix text inputs so they use UTF8

This commit is contained in:
Léa Saviot
2019-01-18 16:41:39 +01:00
committed by Émilie Feral
parent 07a910b455
commit 5c39cab73e
24 changed files with 510 additions and 360 deletions

View File

@@ -126,7 +126,7 @@ void MenuController::renameSelectedScript() {
app()->setFirstResponder(myCell);
myCell->setHighlighted(false);
myCell->textField()->setEditing(true, false);
myCell->textField()->setCursorLocation(strlen(myCell->textField()->text()));
myCell->textField()->setCursorTextLocation(myCell->textField()->text() + strlen(myCell->textField()->text()));
}
void MenuController::deleteScript(Script script) {
@@ -283,7 +283,9 @@ bool MenuController::textFieldShouldFinishEditing(TextField * textField, Ion::Ev
}
bool MenuController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
if (event == Ion::Events::Right && textField->isEditing() && textField->cursorLocation() == textField->draftTextLength()) {
if (event == Ion::Events::Right
&& textField->isEditing()
&& textField->cursorTextLocation() == textField->text() + textField->draftTextLength()) {
return true;
}
if (event == Ion::Events::Clear && textField->isEditing()) {
@@ -292,7 +294,7 @@ bool MenuController::textFieldDidReceiveEvent(TextField * textField, Ion::Events
assert(k_bufferSize >= 1 + strlen(ScriptStore::k_scriptExtension) + 1);
strlcpy(&buffer[1], ScriptStore::k_scriptExtension, strlen(ScriptStore::k_scriptExtension) + 1);
textField->setText(buffer);
textField->setCursorLocation(0);
textField->setCursorTextLocation(textField->text());
return true;
}
return false;
@@ -316,7 +318,7 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
* default name and let the user modify it. */
if (!foundDefaultName) {
textField->setText(numberedDefaultName);
textField->setCursorLocation(defaultNameLength);
textField->setCursorTextLocation(textField->draftTextBuffer() + defaultNameLength);
}
newName = const_cast<const char *>(numberedDefaultName);
}
@@ -348,8 +350,9 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
bool MenuController::textFieldDidHandleEvent(TextField * textField, bool returnValue, bool textSizeDidChange) {
int scriptExtensionLength = 1 + strlen(ScriptStore::k_scriptExtension);
if (textField->isEditing() && textField->cursorLocation() > textField->draftTextLength() - scriptExtensionLength) {
textField->setCursorLocation(textField->draftTextLength() - scriptExtensionLength);
const char * maxPointerLocation = textField->text() + textField->draftTextLength() - scriptExtensionLength;
if (textField->isEditing() && textField->cursorTextLocation() > maxPointerLocation) {
textField->setCursorTextLocation(maxPointerLocation);
}
return returnValue;
}