чување 5d3079d065bccccd2f9a06a99384ac2574ab4dbd
родитељ 56a8f94dc5f56ee500a08d326bc625072142ee47
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Thu, 23 Sep 2021 23:30:52 +0200
WIP Fix: yank/paste when input buffer is empty
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | poe.c | | | 63 | ++++++++++++++++++++++++++++++++++++++++++++++++++------------- |
измењених датотека: 1, додавања: 50(+), брисања: 13(-)
diff --git a/poe.c b/poe.c
@@ -863,28 +863,48 @@ yank_msgstr_to_paste_buffer(struct DrawState* state)
strcpy(state->error, errors[ERR_ILLEGAL_ON_FIRST]);
return NULL;
}
-
+
struct PoEntry* current = &state->entries[state->msgid_number - 1];
- size_t msgstr_num_lines
+ size_t msgstr_num_lines = 0;
+ size_t lines_to_init = 0;
+ size_t lines_to_free = 0;
+ struct BufferLine* newbuf = NULL;
+ uint32_t* pmsgstr = NULL;
+ struct BufferLine* pbuffer = NULL;
+
+ if (!current->msgstr || !*(current->msgstr + state->msgstr_index))
+ {
+ for (size_t i = 0; i < state->paste_rows_count; i++)
+ free_bufferline(state->paste_buffer + i);
+ free(state->paste_buffer);
+ state->paste_rows_count = 0;
+ state->paste_buffer = NULL;
+ return state;
+ }
+
+ msgstr_num_lines
= u32_lines_in_string(*(current->msgstr + state->msgstr_index),
NULL);
- size_t lines_to_init = state->paste_rows_count < msgstr_num_lines
+ lines_to_init = state->paste_rows_count < msgstr_num_lines
? msgstr_num_lines - state->paste_rows_count
: 0;
- size_t lines_to_free = state->paste_rows_count > msgstr_num_lines
+ lines_to_free = state->paste_rows_count > msgstr_num_lines
? state->paste_rows_count - msgstr_num_lines
: 0;
+
for (size_t i = 0; i < lines_to_free; i++)
free_bufferline(
state->paste_buffer + state->paste_rows_count - i - 1);
- struct BufferLine* newbuf = realloc(state->paste_buffer,
- msgstr_num_lines * sizeof(struct BufferLine));
- uint32_t* pmsgstr = *(current->msgstr + state->msgstr_index);
+ if (!state->paste_buffer)
+ newbuf = calloc(msgstr_num_lines, sizeof(struct BufferLine));
+ else
+ newbuf = realloc(state->paste_buffer,
+ msgstr_num_lines * sizeof(struct BufferLine));
+ pmsgstr = *(current->msgstr + state->msgstr_index);
if (!newbuf)
return NULL;
- struct BufferLine* pbuffer = NULL;
for (size_t i = 0; i < lines_to_init; i++)
{
pbuffer = newbuf + msgstr_num_lines - 1 - i;
@@ -926,23 +946,40 @@ paste_paste_buffer_to_input(struct DrawState* state)
return NULL;
}
- size_t lines_to_init = state->input_rows_count < state->paste_rows_count
+ size_t lines_to_init = 0;
+ size_t lines_to_free = 0;
+ struct BufferLine* pinput = NULL;
+ struct BufferLine* newbuf = NULL;
+ struct BufferLine* ppaste = NULL;
+
+ // TODO: yank/paste with empty buffer
+ if (!state->paste_buffer || !*(state->paste_buffer + state->msgstr_index))
+ {
+ for (size_t i = 0; i < state->paste_rows_count; i++)
+ free_bufferline(state->paste_buffer + i);
+ free(state->paste_buffer);
+ state->paste_rows_count = 0;
+ state->paste_buffer = NULL;
+ return state;
+ }
+
+ lines_to_init = state->input_rows_count < state->paste_rows_count
? state->paste_rows_count - state->input_rows_count
: 0;
- size_t lines_to_free = state->input_rows_count > state->paste_rows_count
+ lines_to_free = state->input_rows_count > state->paste_rows_count
? state->input_rows_count - state->paste_rows_count
: 0;
+
for (size_t i = 0; i < lines_to_free; i++)
free_bufferline(
state->input_buffer + state->input_rows_count - i - 1);
- struct BufferLine* newbuf = realloc(state->input_buffer,
+ newbuf = realloc(state->input_buffer,
state->paste_rows_count * sizeof(struct BufferLine));
- struct BufferLine* ppaste = state->paste_buffer;
+ ppaste = state->paste_buffer;
if (!newbuf)
return NULL;
- struct BufferLine* pinput = NULL;
for (size_t i = 0; i < lines_to_init; i++)
{
pinput = newbuf + state->paste_rows_count - 1 - i;