diff options
author | Campbell Barton <campbell@blender.org> | 2022-05-17 10:50:45 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-05-17 10:50:45 +0300 |
commit | fcc3a68cac6cae906e526e72d0691827b098be6a (patch) | |
tree | 7af0cf8f3d7f09350e928a6531838a0f7fb649cd /source | |
parent | f11401d32a30ddbfa775177b67ad78100dc6c5ea (diff) | |
parent | f4ff36431ccfac2f0a99fc23c18fe0d9de38b36d (diff) |
Merge branch 'blender-v3.2-release'
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index ec6387c9cf6..9acf387b930 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -1425,11 +1425,15 @@ void txt_from_buf_for_undo(Text *text, const char *buf, size_t buf_len) char *txt_to_buf(Text *text, size_t *r_buf_strlen) { + const bool has_data = !BLI_listbase_is_empty(&text->lines); /* Identical to #txt_to_buf_for_undo except that the string is nil terminated. */ size_t buf_len = 0; LISTBASE_FOREACH (const TextLine *, l, &text->lines) { buf_len += l->len + 1; } + if (has_data) { + buf_len -= 1; + } char *buf = MEM_mallocN(buf_len + 1, __func__); char *buf_step = buf; LISTBASE_FOREACH (const TextLine *, l, &text->lines) { @@ -1437,6 +1441,11 @@ char *txt_to_buf(Text *text, size_t *r_buf_strlen) buf_step += l->len; *buf_step++ = '\n'; } + /* Remove the trailing new-line so a round-trip doesn't add a newline: + * Python for e.g. `text.from_string(text.as_string())`. */ + if (has_data) { + buf_step--; + } *buf_step = '\0'; *r_buf_strlen = buf_len; return buf; |