Merge pull request #26089 from ianb96/word_wrap_cutoff_fix

Fix word wrap cutoff and tab wrapping issue
This commit is contained in:
Rémi Verschelde 2019-02-20 16:28:43 +01:00 committed by GitHub
commit 9714f701c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -861,6 +861,9 @@ void TextEdit::_notification(int p_what) {
const String &str = wrap_rows[line_wrap_index]; const String &str = wrap_rows[line_wrap_index];
int indent_px = line_wrap_index != 0 ? get_indent_level(line) * cache.font->get_char_size(' ').width : 0; int indent_px = line_wrap_index != 0 ? get_indent_level(line) * cache.font->get_char_size(' ').width : 0;
if (indent_px >= wrap_at) {
indent_px = 0;
}
if (line_wrap_index > 0) if (line_wrap_index > 0)
last_wrap_column += wrap_rows[line_wrap_index - 1].length(); last_wrap_column += wrap_rows[line_wrap_index - 1].length();
@ -3788,6 +3791,9 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
int cur_wrap_index = 0; int cur_wrap_index = 0;
int tab_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width; int tab_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width;
if (tab_offset_px >= wrap_at) {
tab_offset_px = 0;
}
while (col < line_text.length()) { while (col < line_text.length()) {
CharType c = line_text[col]; CharType c = line_text[col];
@ -3795,6 +3801,18 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
int indent_ofs = (cur_wrap_index != 0 ? tab_offset_px : 0); int indent_ofs = (cur_wrap_index != 0 ? tab_offset_px : 0);
if (indent_ofs + word_px + w > wrap_at) {
// not enough space to add this char; start next line
wrap_substring += word_str;
lines.push_back(wrap_substring);
cur_wrap_index++;
wrap_substring = "";
px = 0;
word_str = "";
word_str += c;
word_px = w;
} else {
word_str += c; word_str += c;
word_px += w; word_px += w;
if (c == ' ') { if (c == ' ') {
@ -3805,20 +3823,15 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
word_px = 0; word_px = 0;
} }
if ((indent_ofs + px + word_px) > wrap_at) { if (indent_ofs + px + word_px > wrap_at) {
// do not want to add this word // this word will be moved to the next line
if (indent_ofs + word_px > wrap_at) {
// not enough space; add it anyway
wrap_substring += word_str;
word_str = "";
word_px = 0;
}
lines.push_back(wrap_substring); lines.push_back(wrap_substring);
// reset for next wrap // reset for next wrap
cur_wrap_index++; cur_wrap_index++;
wrap_substring = ""; wrap_substring = "";
px = 0; px = 0;
} }
}
col++; col++;
} }
// line ends before hit wrap_at; add this word to the substring // line ends before hit wrap_at; add this word to the substring
@ -4030,6 +4043,9 @@ int TextEdit::get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) cons
int line_wrap_amount = times_line_wraps(p_line); int line_wrap_amount = times_line_wraps(p_line);
int wrap_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width; int wrap_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width;
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
if (p_wrap_index > line_wrap_amount) if (p_wrap_index > line_wrap_amount)
p_wrap_index = line_wrap_amount; p_wrap_index = line_wrap_amount;
if (p_wrap_index > 0) if (p_wrap_index > 0)
@ -4071,6 +4087,9 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
int px = get_column_x_offset(n_char, rows[wrap_index]); int px = get_column_x_offset(n_char, rows[wrap_index]);
int wrap_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width; int wrap_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width;
if (wrap_offset_px >= wrap_at) {
wrap_offset_px = 0;
}
if (wrap_index != 0) if (wrap_index != 0)
px += wrap_offset_px; px += wrap_offset_px;