[escher/text_field] Fix removing of \n in insertTextAtLocation

Scenario: Copy a text with \n (for instance from a script), then paste
it in a script name -> if \n are replaed with \0 instead of just being
removed, there are problems with the extension
This commit is contained in:
Léa Saviot
2020-01-29 09:10:10 +01:00
parent ad665fba73
commit b29d014695
3 changed files with 19 additions and 4 deletions

View File

@@ -131,6 +131,7 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, char * loca
*overridenByteLocation = overridenByte;
m_currentDraftTextLength += textLength;
// Remove the \n code points
UTF8Decoder decoder(s_draftTextBuffer);
const char * codePointPointer = decoder.stringPosition();
CodePoint codePoint = decoder.nextCodePoint();
@@ -139,11 +140,12 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, char * loca
assert(codePointPointer < s_draftTextBuffer + m_draftTextBufferSize);
if (codePoint == '\n') {
assert(UTF8Decoder::CharSizeOfCodePoint('\n') == 1);
*(const_cast<char *>(codePointPointer)) = 0;
m_currentDraftTextLength = codePointPointer - s_draftTextBuffer;
break;
strlcpy(const_cast<char *>(codePointPointer), codePointPointer + 1, (s_draftTextBuffer + m_draftTextBufferSize) - codePointPointer);
// Put the decoder to the code point replacing \n
decoder.setPosition(codePointPointer);
} else {
codePointPointer = decoder.stringPosition();
}
codePointPointer = decoder.stringPosition();
codePoint = decoder.nextCodePoint();
}