чување e278a2d890be264d44f235befefdc5970239da1b
родитељ 5cf1c3e993b795e94f2831818cf3843b574f37c5
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Fri, 9 Jul 2021 21:23:10 +0200
Fix: restore fuzzy state and fuzzy count when canceling edit
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
| M | draw.c | | | 59 | ++++++++++++++++++++++++++++++----------------------------- |
| M | draw.h | | | 7 | +++++++ |
| M | poe.c | | | 29 | +++++++++++++++++++++++++++++ |
измењених датотека: 3, додавања: 66(+), брисања: 29(-)
diff --git a/draw.c b/draw.c
@@ -82,38 +82,39 @@ void
init_drawstate(struct DrawState* state, char* error, char* filename,
char* prompt)
{
- state->error = error;
- state->filename = filename;
- state->search = NULL;
- state->input_buffer = NULL;
- state->input_column = 0;
- state->input_first_shown_column = 0;
- state->input_first_shown_row = 0;
- state->input_rows_count = 0;
- state->input_display_column = 0;
- state->saved_column = -1;
- state->info_buffer = NULL;
- state->info_first_shown_column = 0;
- state->info_first_shown_row = 0;
- state->info_rows_count = 0;
+ state->error = error;
+ state->filename = filename;
+ state->search = NULL;
+ state->input_buffer = NULL;
+ state->input_column = 0;
+ state->input_first_shown_column = 0;
+ state->input_first_shown_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;
+ state->info_first_shown_row = 0;
+ state->info_rows_count = 0;
state->search_column = 0;
state->search_first_shown_column = 0;
state->search_display_column = 0;
- state->prompt = prompt;
- state->prompt_callback = NULL;
- state->running = 1;
- state->dirty = 0;
- state->dirty_before_edit = 0;
- state->fuzzy_before_edit = 0;
- state->in_prompt = 0;
- state->show_help = 0;
- state->show_edit = 0;
- state->edit_info_focused = 0;
- state->msgid_number = state->msgid_count > 0 ? 1 : 0;
- state->fuzzy_count = 0;
- state->untranslated_count = 0;
- state->msgstr_index = 0;
- state->first_shown_msgid = state->msgid_number;
+ state->prompt = prompt;
+ state->prompt_callback = NULL;
+ state->running = 1;
+ state->dirty = 0;
+ state->dirty_before_edit = 0;
+ state->fuzzy_before_edit = 0;
+ state->in_prompt = 0;
+ state->show_help = 0;
+ state->show_edit = 0;
+ state->edit_info_focused = 0;
+ state->msgid_number = state->msgid_count > 0 ? 1 : 0;
+ state->fuzzy_count = 0;
+ state->untranslated_count = 0;
+ state->msgstr_index = 0;
+ state->first_shown_msgid = state->msgid_number;
}
void
diff --git a/draw.h b/draw.h
@@ -25,6 +25,12 @@ typedef enum {
RIGHT
} Alignment;
+typedef enum {
+ UNCHANGED,
+ SET,
+ CLEARED
+} FlagChange;
+
struct BufferLine {
uint32_t* text;
size_t length;
@@ -44,6 +50,7 @@ struct DrawState {
int input_first_shown_row;
int input_rows_count;
int input_display_column;
+ FlagChange input_changed_fuzzy;
int saved_column;
struct BufferLine* info_buffer; /* information pane above
* edit box */
diff --git a/poe.c b/poe.c
@@ -431,6 +431,7 @@ save_msgstr(struct DrawState* state)
u32_encode_tabs(to_save, MAXBUFLINE);
u32_set_msgstr(&state->entries[state->msgid_number-1], to_save,
state->msgstr_index, 0, state);
+ state->input_changed_fuzzy = UNCHANGED;
//state->dirty = 1;
}
@@ -449,6 +450,18 @@ cancel_msgstr(struct DrawState* state)
state->info_buffer = NULL;
state->dirty = state->dirty_before_edit;
state->fuzzy_count = state->fuzzy_before_edit;
+ switch (state->input_changed_fuzzy)
+ {
+ case SET:
+ state->entries[state->msgid_number-1].flags &=
+ ~FL_FUZZY;
+ break;
+ case CLEARED:
+ state->entries[state->msgid_number-1].flags |= FL_FUZZY;
+ break;
+ default:;
+ }
+ state->input_changed_fuzzy = UNCHANGED;
}
void
@@ -740,6 +753,7 @@ next_untranslated(struct DrawState* state)
save_msgstr(state);
state->dirty_before_edit = state->dirty;
state->fuzzy_before_edit = state->fuzzy_count;
+ state->input_changed_fuzzy = UNCHANGED;
}
state->msgid_number = e + 1;
@@ -792,6 +806,7 @@ next_fuzzy(struct DrawState* state)
save_msgstr(state);
state->dirty_before_edit = state->dirty;
state->fuzzy_before_edit = state->fuzzy_count;
+ state->input_changed_fuzzy = UNCHANGED;
}
state->msgid_number = e + 1;
@@ -1100,9 +1115,21 @@ toggle_fuzzy(struct DrawState* state)
{
state->entries[state->msgid_number-1].flags ^= FL_FUZZY;
if (state->entries[state->msgid_number-1].flags & FL_FUZZY)
+ {
state->fuzzy_count++;
+ if (state->input_changed_fuzzy == CLEARED)
+ state->input_changed_fuzzy = UNCHANGED;
+ else
+ state->input_changed_fuzzy = SET;
+ }
else
+ {
state->fuzzy_count--;
+ if (state->input_changed_fuzzy == SET)
+ state->input_changed_fuzzy = UNCHANGED;
+ else
+ state->input_changed_fuzzy = CLEARED;
+ }
state->dirty = 1;
}
}
@@ -1413,6 +1440,7 @@ handle_editbox_key_event(struct tb_event* ev, struct DrawState* state)
save_msgstr(state);
state->dirty_before_edit = state->dirty;
state->fuzzy_before_edit = state->fuzzy_count;
+ state->input_changed_fuzzy = UNCHANGED;
move_list_down(state);
state->msgstr_index = 0;
load_msgstr(state);
@@ -1561,6 +1589,7 @@ handle_key_event(struct tb_event* ev, struct DrawState* state)
{
state->dirty_before_edit = state->dirty;
state->fuzzy_before_edit = state->fuzzy_count;
+ state->input_changed_fuzzy = UNCHANGED;
state->show_edit = 1;
state->input_row = 0;
state->input_first_shown_row = 0;