чување 0b1ac0e2e9087598554aa62698b0169676ae4715
родитељ 80bad7a92ca1e30a6d3094370b91ca60df6cc06c
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 18 Apr 2022 20:29:08 +0200
Fix: Fix joining lines, avoid inserting additional spaces
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 2, додавања: 15(+), брисања: 5(-)
diff --git a/TODO b/TODO
@@ -1,7 +1,7 @@
TODO
====
- [ ] Avoid inserting additional spaces when joining lines
+ [x] Avoid inserting additional spaces when joining lines
[ ] Replace (patch)
diff --git a/sled.c b/sled.c
@@ -452,6 +452,7 @@ join_lines(struct DrawState* state)
int selection = 0;
int saved_row = state->coord.row;
struct BufferLine* current = NULL;
+ struct BufferLine* next = NULL;
if (SEL_NOT_EMPTY(state))
{
@@ -474,22 +475,31 @@ join_lines(struct DrawState* state)
{
ssr = state->coord.row;
ssc = state->coord.col;
- ser = state->coord.row + 1;
+ ser = state->coord.row;
}
+ if (ssr == state->rows_count - 1)
+ return 0;
+
for (int row = ssr; row <= ser; row++)
{
current = state->buffer + ssr;
+ next = state->buffer + ssr + 1;
if (current->length + 2 < MAXBUFLINE)
{
state->coord.row = ssr;
- if (current->length > 0)
+ if (current->length > 0
+ && !u32_is_word_boundary(
+ current->text[current->length - 1], 1)
+ && !u32_is_word_boundary(next->text[0], 1))
{
current->text[current->length] = ' ';
current->text[current->length + 1] = 0;
current->length++;
+ state->coord.col = current->length - 1;
}
- state->coord.col = current->length;
+ else
+ state->coord.col = current->length;
state->display_column = display_length(state,
current->text, state->coord.col);
simple_join_lines(state);
@@ -1753,7 +1763,7 @@ simple_join_lines(struct DrawState* state)
{
size_t first_line = state->coord.row;
- if (state->rows_count == 1)
+ if (first_line == state->rows_count - 1)
return;
u32_strcat(state->buffer[first_line].text,