poe

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

чување c1731af897460e365b375e058501b9a2aa9d1038
родитељ 5d3079d065bccccd2f9a06a99384ac2574ab4dbd
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Sat, 25 Sep 2021 14:06:18 +0200

Finish yank/paste when buffer is empty fix

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

Diffstat:
Mdraw.c | 38+++++++++++++++++---------------------
Mpoe.c | 44++++++++++++++++++++++++++------------------
измењених датотека: 2, додавања: 43(+), брисања: 39(-)

diff --git a/draw.c b/draw.c @@ -12,29 +12,27 @@ #include "version.h" static const char* help_title = "Main view help"; -static const char* help[] = { - "", +static const char* help[] = {"", "Esc - Close dialog, clear error", - "Enter - Edit entry", + "Enter - Edit entry", "H or F1 - Show this screen", "/ or F7 - Incremental search (end = Enter)", - "n or F3 - Find next", + "n or F3 - Find next", "N or F4 - Find previous", "u or F8 - Go to next untranslated entry", "f or F9 - Go to next fuzzy entry", "w or C-S - Save file (with backup)", - "g or Home - Go to first entry", + "g or Home - Go to first entry", "C-B or PgUp - Go to previous page", "k or \u2191 - Go to previous entry", - "j or \u2193 - Go to next entry", + "j or \u2193 - Go to next entry", "C-F or PgDn - Go to next page", - "G or End - Go to last entry", + "G or End - Go to last entry", "z or C-Z - Toggle fuzzy flag", - "q or C-Q - Quit", - "See the manual (man poe) for full help." -}; + "q or C-Q - Quit", + "See the manual (man poe) for full help."}; static const char* editbox_title = "Edit translation"; -const char* errors[] = { +const char* errors[] = { [ERR_UNKNOWN_KEY] = "Unknown key (press H for help)", [ERR_EXIT_KEY] = "Press q or C-Q to quit", [ERR_DLG_OPEN] = "Press Esc to close dialog or q/C-Q to quit", @@ -43,13 +41,11 @@ const char* errors[] = { [ERR_CANT_ALLOC] = "Memory allocation failed", [ERR_CANT_SAVE] = "File is not writeable", [ERR_CANT_MOVE] = "Cannot move temporary file", - [ERR_ILLEGAL_ON_FIRST] = "Not allowed on first entry" -}; -const char* flag_strings[] = { - [FL_C_FORMAT] = "c-format", - [FL_NO_C_FORMAT] = "no-c-format", - [FL_FUZZY] = "fuzzy" -}; + [ERR_ILLEGAL_ON_FIRST] = "Not allowed on first entry"}; +const char* flag_strings[] = { + [FL_C_FORMAT] = "c-format", + [FL_NO_C_FORMAT] = "no-c-format", + [FL_FUZZY] = "fuzzy"}; const char* first_entry_msgid = "*** SPECIAL: file info ***"; const char* program_name = "poe"; const char* prompt_dirty = "File changed, save [y/n/ESC]?"; @@ -88,12 +84,13 @@ init_drawstate(struct DrawState* state, char* error, char* filename, state->filename = filename; state->search = NULL; state->input_buffer = NULL; + state->input_changed_fuzzy = UNCHANGED; state->input_column = 0; + state->input_display_column = 0; state->input_first_shown_column = 0; state->input_first_shown_row = 0; + state->input_row = 0; state->input_rows_count = 0; - state->input_display_column = 0; - state->input_changed_fuzzy = UNCHANGED; state->saved_column = -1; state->info_buffer = NULL; state->info_first_shown_column = 0; @@ -896,4 +893,3 @@ draw(const struct DrawState* state) return state; } - diff --git a/poe.c b/poe.c @@ -863,13 +863,13 @@ 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 = 0; - size_t lines_to_init = 0; - size_t lines_to_free = 0; - struct BufferLine* newbuf = NULL; - uint32_t* pmsgstr = NULL; + + 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; + uint32_t* pmsgstr = NULL; struct BufferLine* pbuffer = NULL; if (!current->msgstr || !*(current->msgstr + state->msgstr_index)) @@ -878,7 +878,7 @@ yank_msgstr_to_paste_buffer(struct DrawState* state) free_bufferline(state->paste_buffer + i); free(state->paste_buffer); state->paste_rows_count = 0; - state->paste_buffer = NULL; + state->paste_buffer = NULL; return state; } @@ -900,7 +900,7 @@ yank_msgstr_to_paste_buffer(struct DrawState* state) else newbuf = realloc(state->paste_buffer, msgstr_num_lines * sizeof(struct BufferLine)); - pmsgstr = *(current->msgstr + state->msgstr_index); + pmsgstr = *(current->msgstr + state->msgstr_index); if (!newbuf) return NULL; @@ -946,20 +946,28 @@ paste_paste_buffer_to_input(struct DrawState* state) return NULL; } - size_t lines_to_init = 0; - size_t lines_to_free = 0; + 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)) + if (!state->paste_buffer || !(*state->paste_buffer).text + || !*(*state->paste_buffer).text) { - 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; + /* leave one row */ + for (size_t i = 1; i < state->input_rows_count; i++) + free_bufferline(state->input_buffer + i); + state->input_buffer = realloc(state->input_buffer, + sizeof(struct BufferLine)); + *(state->input_buffer->text) = 0; + state->input_column = 0; + state->input_display_column = 0; + state->input_first_shown_column = 0; + state->input_first_shown_row = 0; + state->input_row = 0; + state->input_rows_count = 1; + state->dirty = 1; return state; }