poe

Уређивач .po фајлова
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 615d82980166baad5f2c505a22f8576ac1ba93a1
родитељ 06492bb408a28870e27e2a8eb54994752c390594
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Tue,  7 Mar 2023 12:26:15 +0100

Bugfix: C-C copied msgstr instead of input buffer (conceptual error)

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MTODO | 2+-
Mconfig.def.h | 4++--
Mconfig.h | 6+++---
Mpoe.c | 67+++++++++++++++++++++++++++++--------------------------------------
измењених датотека: 4, додавања: 35(+), брисања: 44(-)

diff --git a/TODO b/TODO @@ -1,7 +1,7 @@ TODO ==== - [ ] Bug: C-C/C-V don't work until the msgstr is saved (they should) + [x] Bug: C-C/C-V don't work until the msgstr is saved (they should) [ ] Bug: C-T behavior? Cross-check with sled's routines diff --git a/config.def.h b/config.def.h @@ -123,7 +123,7 @@ int show_help(struct DrawState* state); int show_search(struct DrawState* state); int toggle_fuzzy(struct DrawState* state); int toggle_info_focused(struct DrawState* state); -int yank_msgstr_to_paste_buffer(struct DrawState* state); +int yank_input_to_paste_buffer(struct DrawState* state); int write_file(struct DrawState* state); /* clang-format off */ @@ -152,7 +152,7 @@ static const struct Key edit_keys[] = { { .ev = { .key = TB_KEY_CTRL_A }, .callback = move_start }, { .ev = { .key = TB_KEY_CTRL_C }, - .callback = yank_msgstr_to_paste_buffer }, + .callback = yank_input_to_paste_buffer }, { .ev = { .key = TB_KEY_CTRL_E }, .callback = move_end }, { .ev = { .key = TB_KEY_CTRL_K }, diff --git a/config.h b/config.h @@ -7,7 +7,7 @@ static const char* backup_suffix = "~"; #endif /* PO_C_GLOBALS */ -#define SAVE_WRAP_WIDTH 70 +#define SAVE_WRAP_WIDTH 75 #define WRAP_FIRST_MSGSTR 0 #define WARN_COUNT_DOTS 0 @@ -123,7 +123,7 @@ int show_help(struct DrawState* state); int show_search(struct DrawState* state); int toggle_fuzzy(struct DrawState* state); int toggle_info_focused(struct DrawState* state); -int yank_msgstr_to_paste_buffer(struct DrawState* state); +int yank_input_to_paste_buffer(struct DrawState* state); int write_file(struct DrawState* state); /* clang-format off */ @@ -152,7 +152,7 @@ static const struct Key edit_keys[] = { { .ev = { .key = TB_KEY_CTRL_A }, .callback = move_start }, { .ev = { .key = TB_KEY_CTRL_C }, - .callback = yank_msgstr_to_paste_buffer }, + .callback = yank_input_to_paste_buffer }, { .ev = { .key = TB_KEY_CTRL_E }, .callback = move_end }, { .ev = { .key = TB_KEY_CTRL_K }, diff --git a/poe.c b/poe.c @@ -1938,7 +1938,7 @@ toggle_info_focused(struct DrawState* state) } int -yank_msgstr_to_paste_buffer(struct DrawState* state) +yank_input_to_paste_buffer(struct DrawState* state) { if (state->edit_info_focused) return 0; @@ -1949,15 +1949,14 @@ yank_msgstr_to_paste_buffer(struct DrawState* state) return 0; } - struct PoEntry* current = &state->entries[state->msgid_number - 1]; - size_t msgstr_num_lines = 0; - size_t lines_to_init = 0; - size_t lines_to_free = 0; - struct BufferLine* newbuf = NULL; - const uint32_t* pmsgstr = NULL; - struct BufferLine* pbuffer = NULL; + size_t lines_to_init = 0; + size_t lines_to_free = 0; + struct BufferLine* ppaste = NULL; + struct BufferLine* newbuf = NULL; + struct BufferLine* pinput = NULL; - if (!current->msgstr || !*(current->msgstr + state->msgstr_index)) + if (!state->input_buffer || !(*state->input_buffer).text + || !*(*state->input_buffer).text) { for (size_t i = 0; i < state->paste_rows_count; i++) free_bufferline(state->paste_buffer + i); @@ -1967,56 +1966,48 @@ yank_msgstr_to_paste_buffer(struct DrawState* state) return 0; } - msgstr_num_lines - = u32_lines_in_string(*(current->msgstr + state->msgstr_index), - 0, 0); - lines_to_init = state->paste_rows_count < msgstr_num_lines - ? msgstr_num_lines - state->paste_rows_count + lines_to_init = state->paste_rows_count < state->input_rows_count + ? state->input_rows_count - state->paste_rows_count : 0; - lines_to_free = state->paste_rows_count > msgstr_num_lines - ? state->paste_rows_count - msgstr_num_lines + lines_to_free = state->paste_rows_count > state->input_rows_count + ? state->paste_rows_count - state->input_rows_count : 0; for (size_t i = 0; i < lines_to_free; i++) free_bufferline( state->paste_buffer + state->paste_rows_count - i - 1); if (!state->paste_buffer) - newbuf = calloc(msgstr_num_lines, sizeof(struct BufferLine)); + newbuf = calloc(state->input_rows_count, + sizeof(struct BufferLine)); else newbuf = realloc(state->paste_buffer, - msgstr_num_lines * sizeof(struct BufferLine)); - pmsgstr = *(current->msgstr + state->msgstr_index); + state->input_rows_count * sizeof(struct BufferLine)); + pinput = state->input_buffer; if (!newbuf) return 0; for (size_t i = 0; i < lines_to_init; i++) { - pbuffer = newbuf + msgstr_num_lines - 1 - i; - init_bufferline(pbuffer); + ppaste = newbuf + state->input_rows_count - 1 - i; + init_bufferline(ppaste); uint32_t* newtext = calloc(MAXBUFLINE, sizeof(uint32_t)); if (!newtext) return 0; - pbuffer->text = newtext; + ppaste->text = newtext; } - pbuffer = newbuf; - while (*pmsgstr) - { - size_t len = 0; - size_t newlen = 0; - const uint32_t* old_pmsgstr = pmsgstr; - - len = u32_next_line(*(current->msgstr + state->msgstr_index), - &pmsgstr, 0, 0); - u32_strncpy(pbuffer->text, old_pmsgstr, - MIN(len + 1, MAXBUFLINE)); - newlen = u32_decode_tabs(pbuffer->text, MAXBUFLINE); - pbuffer->length = newlen; - pbuffer++; - } + if (pinput) + for (size_t i = 0; i < state->input_rows_count; i++) + { + ppaste = newbuf + i; + u32_strncpy(ppaste->text, pinput->text, + MIN(pinput->length + 1, MAXBUFLINE)); + ppaste->length = pinput->length; + pinput++; + } - state->paste_rows_count = msgstr_num_lines; + state->paste_rows_count = state->input_rows_count; state->paste_buffer = newbuf; return 0;