sled

Једноставни уређивач текста
git clone https://git.sr.ht/~strahinja/sled
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 0a3034f88770b1b0bc1d6b708523a0af15148ee8
родитељ ff12a2314d805208cd7f3541d6c2b8bd96f814bf
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Thu, 19 Sep 2024 14:00:40 +0200

Bugfix: wrapping last line in the file, remove whitespace at start

Diffstat:
MTODO | 5-----
MTODO.done | 5+++++
Msled.c | 29+++++++++++++++++------------
измењених датотека: 3, додавања: 22(+), брисања: 17(-)

diff --git a/TODO b/TODO @@ -1,11 +1,6 @@ TODO ==== -[ ] Investigate wrapping further - [ ] Avoid blanks at the beginning of lines - [ ] Last paragraph in README - [ ] Second paragraph in wrap.test - [~] Code optimization (struct coord...) diff --git a/TODO.done b/TODO.done @@ -1,6 +1,11 @@ Done or canceled todos ====================== +[x] Investigate wrapping further + [x] Avoid blanks at the beginning of lines + [x] Last paragraph in README + [x] Second paragraph in wrap.test + [x] Convert #define's in config.def.h to struct Color [x] Add struct Color to master branch diff --git a/sled.c b/sled.c @@ -2656,7 +2656,7 @@ wrap_next_line: state->coord.row = cur_row; dlen = display_length(current->text, current->length); - while (cur_row + 1 < state->rows_count && dlen < wrap_width + while ((dlen < wrap_width) && (cur_row + 1 < state->rows_count) && u32_has_nonblanks(next->text)) { /* Insert space to avoid joining ending and beginning words */ @@ -2669,7 +2669,7 @@ wrap_next_line: current->length + 2, current->length + 2, wrap_alloc_error, uint32_t); current->length++; - current->text[current->length - 1] = L' '; + current->text[current->length - 1] = (uint32_t)' '; current->text[current->length] = 0; } @@ -2708,15 +2708,17 @@ wrap_next_line: current = &state->buffer[cur_row]; next = &state->buffer[cur_row + 1]; - /* - Remove the space between the two words at split + /* - Remove spaces between the two words at split * - current is the new current (the rest of the line * after split) */ - if (u32_is_word_boundary(current->text[0], 1)) + while (u32_is_word_boundary(current->text[0], 1)) { - *current->text = 0; for (col = 0; col < current->length; col++) current->text[col] = current->text[col + 1]; + assert(current->length > 0); current->length--; + if (current->length == 0) + break; } if (sel) @@ -2727,7 +2729,7 @@ wrap_next_line: } end_row++; if (cur_row + 1 == state->rows_count) - break; + goto wrap_next_line; /* If the rest of the line is still in block and is * < wrap_width, join it with next (the new next) */ @@ -2745,8 +2747,9 @@ wrap_next_line: current->length + 2, wrap_alloc_error, uint32_t); current->length++; - current->text[current->length - 1] = L' '; - current->text[current->length] = 0; + current->text[current->length - 1] + = (uint32_t)' '; + current->text[current->length] = 0; } simple_join_lines(state); @@ -2762,7 +2765,7 @@ wrap_next_line: dlen = display_length(current->text, current->length); if (dlen < wrap_width) - continue; + goto wrap_next_line; /* One more split needed for the rest of the line (new * current) */ @@ -2782,13 +2785,15 @@ wrap_next_line: simple_insert_line(state); end_row++; - /* Remove the space between the two words at split */ - if (u32_is_word_boundary(next->text[0], 1)) + /* Remove spaces between the two words at split */ + while (u32_is_word_boundary(next->text[0], 1)) { - *next->text = 0; for (col = 0; col < next->length; col++) next->text[col] = next->text[col + 1]; + assert(next->length > 0); next->length--; + if (next->length == 0) + break; } }