чување 68cc281d8aba9226507aeb9bd5b21550af4be4a3
родитељ f930bafe2fc2cb96068a1c62ad9a19a5a04a61fc
Аутор: Страхиња Радић <sr@strahinja.org>
Датум: Tue, 31 Mar 2026 13:57:28 +0000
sled.c(erase_prev_word): Smaller refactors for clarity
Diffstat:
| M | sled.c | | | 44 | +++++++++++++++++++++++--------------------- |
измењених датотека: 1, додавања: 23(+), брисања: 21(-)
diff --git a/sled.c b/sled.c
@@ -443,33 +443,37 @@ erase_line_error:
static int
erase_prev_word(struct DrawState* state)
{
- struct BufferLine* current = NULL;
- int i;
- int d;
+ uint32_t* pline;
+ ssize_t len;
+ int i, j, d;
- assert(state != NULL);
- i = state->coord.col;
- current = state->buffer + state->coord.row;
- assert((current != NULL) && (current->text != NULL));
+ assert((state != NULL) && (state->buffer != NULL)
+ && (state->buffer[state->coord.row].text != NULL));
+ i = state->coord.col;
+ len = state->buffer[state->coord.row].length;
+ pline = state->buffer[state->coord.row].text;
- if (i > 0 && u32_is_word_boundary(current->text[i - 1], 0))
+ if (i > 0 && u32_is_word_boundary(pline[i - 1], 0))
i--;
- while (i > 0 && u32_is_word_boundary(current->text[i], 0))
+ while (i > 0 && u32_is_word_boundary(pline[i], 0))
i--;
- while (i > 0 && !u32_is_word_boundary(current->text[i], 0)
- && !u32_is_word_boundary(current->text[i - 1], 0))
+ while (i > 0 && !u32_is_word_boundary(pline[i], 0)
+ && !u32_is_word_boundary(pline[i - 1], 0))
i--;
d = state->coord.col - i;
- for (ssize_t j = i; j + d < current->length; j++)
- current->text[j] = current->text[j + d];
+ for (j = i; j + d < len; j++)
+ pline[j] = pline[j + d];
- current->length -= d;
- current->text[current->length] = 0;
- state->coord.col = i;
- state->display_column = display_length(current->text, state->coord.col);
- state->dirty = 1;
+ len -= d;
+ state->buffer[state->coord.row].length = len;
+ pline[len] = 0;
+ state->coord.col = i;
+ state->display_column = display_length(pline, state->coord.col);
+ if (state->display_column < state->first_shown.col)
+ state->first_shown.col = state->display_column;
+ state->dirty = 1;
return 0;
}
@@ -1083,9 +1087,7 @@ insert_char(struct DrawState* state, uint32_t ch)
{
struct BufferLine* buffer_line = NULL;
uint32_t* ptext = NULL;
- ssize_t i;
- ssize_t len;
- ssize_t size;
+ ssize_t i, len, size;
assert((state != NULL) && (state->buffer != NULL));
ENSURE_SIZE(state->buffer[state->coord.row].text, ptext,