fixed nasty corruption bug with the size of the undo stack

master
Allen Webster 2016-05-17 16:21:51 -04:00
parent 562bd0601a
commit c989b9dae9
3 changed files with 17 additions and 40 deletions

View File

@ -752,8 +752,6 @@ COMMAND_DECL(delete_range){
view_cursor_move(view, next_cursor_pos); view_cursor_move(view, next_cursor_pos);
view->file_data.mark = range.start; view->file_data.mark = range.start;
} }
general_memory_check(&models->mem.general);
} }
COMMAND_DECL(undo){ COMMAND_DECL(undo){
@ -762,6 +760,9 @@ COMMAND_DECL(undo){
REQ_FILE_HISTORY(file, view); REQ_FILE_HISTORY(file, view);
view_undo(system, models, view); view_undo(system, models, view);
Assert(file->state.undo.undo.size >= 0);
} }
COMMAND_DECL(redo){ COMMAND_DECL(redo){
@ -770,6 +771,8 @@ COMMAND_DECL(redo){
REQ_FILE_HISTORY(file, view); REQ_FILE_HISTORY(file, view);
view_redo(system, models, view); view_redo(system, models, view);
Assert(file->state.undo.undo.size >= 0);
} }
COMMAND_DECL(history_backward){ COMMAND_DECL(history_backward){

View File

@ -924,7 +924,7 @@ struct Edit_Spec{
internal Edit_Step* internal Edit_Step*
file_post_undo(General_Memory *general, Editing_File *file, file_post_undo(General_Memory *general, Editing_File *file,
Edit_Step step, bool32 do_merge, bool32 can_merge){ Edit_Step step, b32 do_merge, b32 can_merge){
if (step.type == ED_NORMAL){ if (step.type == ED_NORMAL){
file->state.undo.redo.size = 0; file->state.undo.redo.size = 0;
file->state.undo.redo.edit_count = 0; file->state.undo.redo.edit_count = 0;
@ -948,7 +948,7 @@ file_post_undo(General_Memory *general, Editing_File *file,
inv_step.can_merge = (b8)can_merge; inv_step.can_merge = (b8)can_merge;
inv_step.type = ED_UNDO; inv_step.type = ED_UNDO;
bool32 did_merge = 0; b32 did_merge = 0;
if (do_merge && undo->edit_count > 0){ if (do_merge && undo->edit_count > 0){
Edit_Step prev = undo->edits[undo->edit_count-1]; Edit_Step prev = undo->edits[undo->edit_count-1];
if (prev.can_merge && inv_step.edit.len == 0 && prev.edit.len == 0){ if (prev.can_merge && inv_step.edit.len == 0 && prev.edit.len == 0){
@ -967,6 +967,7 @@ file_post_undo(General_Memory *general, Editing_File *file,
else{ else{
if (undo->edit_count == undo->edit_max) if (undo->edit_count == undo->edit_max)
undo_stack_grow_edits(general, undo); undo_stack_grow_edits(general, undo);
result = undo->edits + (undo->edit_count++); result = undo->edits + (undo->edit_count++);
*result = inv_step; *result = inv_step;
} }
@ -992,9 +993,11 @@ inline void
undo_stack_pop(Edit_Stack *stack){ undo_stack_pop(Edit_Stack *stack){
if (stack->edit_count > 0){ if (stack->edit_count > 0){
Edit_Step *edit = stack->edits + (--stack->edit_count); Edit_Step *edit = stack->edits + (--stack->edit_count);
if (edit->child_count == 0){
stack->size -= edit->edit.len; stack->size -= edit->edit.len;
} }
} }
}
internal void internal void
file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){
@ -1811,36 +1814,6 @@ file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File
token->size += local_shift; token->size += local_shift;
shift_amount += local_shift; shift_amount += local_shift;
} }
#if 0
for (; token < end_token && edit < end_edit;){
local_shift = (edit->len - (edit->end - edit->start));
for (; token->start + token->size < edit->start && token < end_token; ++token){
token->start += shift_amount;
}
if (token->start <= edit->start){
original = *token;
if (original.start == edit->start){
shift_amount += local_shift;
token->start += shift_amount;
++edit;
}
for (; edit->start < original.start + original.size && edit < end_edit; ++edit){
local_shift = (edit->len - (edit->end - edit->start));
token->size += local_shift;
shift_amount += local_shift;
}
++token;
}
else{
shift_amount += local_shift;
++edit;
}
}
for (; token < end_token; ++token){
token->start += shift_amount;
}
#endif
} }
} }

View File

@ -1235,6 +1235,7 @@ buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inv
pos = *str_pos; pos = *str_pos;
len = edit.end - edit.start; len = edit.end - edit.start;
assert_4tech(pos >= 0);
assert_4tech(pos + len <= max); assert_4tech(pos + len <= max);
*str_pos = pos + len; *str_pos = pos + len;