Browse Source

Fix some cases of not checking for history push

master
cancel 5 years ago
parent
commit
a8395d6017
  1. 13
      tui_main.c

13
tui_main.c

@ -334,9 +334,9 @@ void undo_history_deinit(Undo_history *hist) {
} }
} }
void undo_history_push(Undo_history *hist, Field *field, Usz tick_num) { bool undo_history_push(Undo_history *hist, Field *field, Usz tick_num) {
if (hist->limit == 0) if (hist->limit == 0)
return; return false;
Undo_node *new_node; Undo_node *new_node;
if (hist->count == hist->limit) { if (hist->count == hist->limit) {
new_node = hist->first; new_node = hist->first;
@ -349,6 +349,8 @@ void undo_history_push(Undo_history *hist, Field *field, Usz tick_num) {
} }
} else { } else {
new_node = malloc(sizeof(Undo_node)); new_node = malloc(sizeof(Undo_node));
if (!new_node)
return false;
++hist->count; ++hist->count;
field_init(&new_node->field); field_init(&new_node->field);
} }
@ -364,6 +366,7 @@ void undo_history_push(Undo_history *hist, Field *field, Usz tick_num) {
} }
new_node->next = NULL; new_node->next = NULL;
hist->last = new_node; hist->last = new_node;
return true;
} }
void undo_history_pop(Undo_history *hist, Field *out_field, Usz *out_tick_num) { void undo_history_pop(Undo_history *hist, Field *out_field, Usz *out_tick_num) {
@ -3301,7 +3304,8 @@ int main(int argc, char **argv) {
oso *temp_name = get_nonempty_singular_form_text(qf); oso *temp_name = get_nonempty_singular_form_text(qf);
if (!temp_name) if (!temp_name)
break; break;
undo_history_push(&t.ged.undo_hist, &t.ged.field, t.ged.tick_num); bool added_hist = undo_history_push(&t.ged.undo_hist,
&t.ged.field, t.ged.tick_num);
Field_load_error fle = Field_load_error fle =
field_load_file(osoc(temp_name), &t.ged.field); field_load_file(osoc(temp_name), &t.ged.field);
if (fle == Field_load_error_ok) { if (fle == Field_load_error_ok) {
@ -3317,6 +3321,7 @@ int main(int argc, char **argv) {
t.ged.is_draw_dirty = true; t.ged.is_draw_dirty = true;
pop_qnav_if_main_menu(); pop_qnav_if_main_menu();
} else { } else {
if (added_hist)
undo_history_pop(&t.ged.undo_hist, &t.ged.field, undo_history_pop(&t.ged.undo_hist, &t.ged.field,
&t.ged.tick_num); &t.ged.tick_num);
qmsg_printf_push("Error Loading File", "%s:\n%s", qmsg_printf_push("Error Loading File", "%s:\n%s",
@ -3533,12 +3538,14 @@ int main(int argc, char **argv) {
break; break;
case CTRL_PLUS('v'): case CTRL_PLUS('v'):
if (t.use_gui_cboard) { if (t.use_gui_cboard) {
bool added_hist =
undo_history_push(&t.ged.undo_hist, &t.ged.field, t.ged.tick_num); undo_history_push(&t.ged.undo_hist, &t.ged.field, t.ged.tick_num);
Usz pasted_h, pasted_w; Usz pasted_h, pasted_w;
Cboard_error cberr = cboard_paste( Cboard_error cberr = cboard_paste(
t.ged.field.buffer, t.ged.field.height, t.ged.field.width, t.ged.field.buffer, t.ged.field.height, t.ged.field.width,
t.ged.ged_cursor.y, t.ged.ged_cursor.x, &pasted_h, &pasted_w); t.ged.ged_cursor.y, t.ged.ged_cursor.x, &pasted_h, &pasted_w);
if (cberr) { if (cberr) {
if (added_hist)
undo_history_pop(&t.ged.undo_hist, &t.ged.field, &t.ged.tick_num); undo_history_pop(&t.ged.undo_hist, &t.ged.field, &t.ged.tick_num);
switch (cberr) { switch (cberr) {
case Cboard_error_none: case Cboard_error_none:

Loading…
Cancel
Save