Skip to content

Commit 030cc99

Browse files
committed
Merge pull request #102854 from bruvzg/brk_trim3
[TextServer] Fix space trimming on line break.
2 parents f419873 + c03aa4b commit 030cc99

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

servers/text_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped
847847
if (last_end <= l_gl[start_pos].start) {
848848
lines.push_back(l_gl[start_pos].start);
849849
lines.push_back(l_gl[end_pos].end);
850-
cur_safe_brk = end_pos;
850+
cur_safe_brk = last_safe_break;
851851
last_end = l_gl[end_pos].end;
852852
}
853853
trim_next = true;
@@ -1021,7 +1021,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do
10211021
if (p_width > indent) {
10221022
l_width = p_width - indent;
10231023
}
1024-
cur_safe_brk = end_pos;
1024+
cur_safe_brk = last_safe_break;
10251025
last_end = l_gl[end_pos].end;
10261026
}
10271027
trim_next = true;

tests/servers/test_text_server.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,19 @@ TEST_SUITE("[TextServer]") {
596596
CHECK_FALSE_MESSAGE(brks[5] != 14, "Invalid line break position.");
597597
}
598598

599+
brks = ts->shaped_text_get_line_breaks(ctx, 35.0, 0, TextServer::BREAK_WORD_BOUND | TextServer::BREAK_MANDATORY | TextServer::BREAK_TRIM_EDGE_SPACES);
600+
CHECK_FALSE_MESSAGE(brks.size() != 6, "Invalid line breaks number.");
601+
if (brks.size() == 6) {
602+
CHECK_FALSE_MESSAGE(brks[0] != 0, "Invalid line break position.");
603+
CHECK_FALSE_MESSAGE(brks[1] != 4, "Invalid line break position.");
604+
605+
CHECK_FALSE_MESSAGE(brks[2] != 5, "Invalid line break position.");
606+
CHECK_FALSE_MESSAGE(brks[3] != 9, "Invalid line break position.");
607+
608+
CHECK_FALSE_MESSAGE(brks[4] != 10, "Invalid line break position.");
609+
CHECK_FALSE_MESSAGE(brks[5] != 14, "Invalid line break position.");
610+
}
611+
599612
ts->free_rid(ctx);
600613

601614
for (int j = 0; j < font.size(); j++) {

0 commit comments

Comments
 (0)