mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[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:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user