fixed bug with whitespace batch editing and token fixup
parent
e07ec779cb
commit
562bd0601a
2
4ed.cpp
2
4ed.cpp
|
@ -752,6 +752,8 @@ 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){
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
/*
|
/*
|
||||||
* Mr. 4th Dimention - Allen Webster
|
* Mr. 4th Dimention - Allen Webster
|
||||||
*
|
*
|
||||||
* 19.08.2015
|
* 19.08.2015
|
||||||
*
|
*
|
||||||
* File editing view for 4coder
|
* File editing view for 4coder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TOP
|
// TOP
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ file_synchronize_times(System_Functions *system, Editing_File *file, char *filen
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
|
file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
|
||||||
Editing_File *file, char *filename){
|
Editing_File *file, char *filename){
|
||||||
i32 result = 0;
|
i32 result = 0;
|
||||||
|
|
||||||
i32 max, size;
|
i32 max, size;
|
||||||
|
@ -331,8 +331,8 @@ file_save(System_Functions *system, Exchange *exchange, Mem_Options *mem,
|
||||||
|
|
||||||
inline b32
|
inline b32
|
||||||
file_save_and_set_names(System_Functions *system, Exchange *exchange,
|
file_save_and_set_names(System_Functions *system, Exchange *exchange,
|
||||||
Mem_Options *mem, Working_Set *working_set, Editing_File *file,
|
Mem_Options *mem, Working_Set *working_set, Editing_File *file,
|
||||||
char *filename){
|
char *filename){
|
||||||
b32 result = 0;
|
b32 result = 0;
|
||||||
result = file_save(system, exchange, mem, file, filename);
|
result = file_save(system, exchange, mem, file, filename);
|
||||||
if (result){
|
if (result){
|
||||||
|
@ -370,12 +370,12 @@ file_grow_starts_widths_as_needed(General_Memory *general, Buffer_Type *buffer,
|
||||||
max = LargeRoundUp(target_lines + max, Kbytes(1));
|
max = LargeRoundUp(target_lines + max, Kbytes(1));
|
||||||
|
|
||||||
f32 *new_widths = (f32*)general_memory_reallocate(
|
f32 *new_widths = (f32*)general_memory_reallocate(
|
||||||
general, buffer->line_widths,
|
general, buffer->line_widths,
|
||||||
sizeof(f32)*count, sizeof(f32)*max, BUBBLE_WIDTHS);
|
sizeof(f32)*count, sizeof(f32)*max, BUBBLE_WIDTHS);
|
||||||
|
|
||||||
i32 *new_lines = (i32*)general_memory_reallocate(
|
i32 *new_lines = (i32*)general_memory_reallocate(
|
||||||
general, buffer->line_starts,
|
general, buffer->line_starts,
|
||||||
sizeof(i32)*count, sizeof(i32)*max, BUBBLE_STARTS);
|
sizeof(i32)*count, sizeof(i32)*max, BUBBLE_STARTS);
|
||||||
|
|
||||||
if (new_lines){
|
if (new_lines){
|
||||||
buffer->line_starts = new_lines;
|
buffer->line_starts = new_lines;
|
||||||
|
@ -398,7 +398,7 @@ file_grow_starts_widths_as_needed(General_Memory *general, Buffer_Type *buffer,
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_measure_starts_widths(System_Functions *system, General_Memory *general,
|
file_measure_starts_widths(System_Functions *system, General_Memory *general,
|
||||||
Buffer_Type *buffer, float *advance_data){
|
Buffer_Type *buffer, float *advance_data){
|
||||||
if (!buffer->line_starts){
|
if (!buffer->line_starts){
|
||||||
i32 max = buffer->line_max = Kbytes(1);
|
i32 max = buffer->line_max = Kbytes(1);
|
||||||
buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32), BUBBLE_STARTS);
|
buffer->line_starts = (i32*)general_memory_allocate(general, max*sizeof(i32), BUBBLE_STARTS);
|
||||||
|
@ -420,7 +420,7 @@ file_measure_starts_widths(System_Functions *system, General_Memory *general,
|
||||||
|
|
||||||
{
|
{
|
||||||
i32 *new_lines = (i32*)general_memory_reallocate(
|
i32 *new_lines = (i32*)general_memory_reallocate(
|
||||||
general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max, BUBBLE_STARTS);
|
general, buffer->line_starts, sizeof(i32)*count, sizeof(i32)*max, BUBBLE_STARTS);
|
||||||
|
|
||||||
// TODO(allen): when unable to grow?
|
// TODO(allen): when unable to grow?
|
||||||
TentativeAssert(new_lines);
|
TentativeAssert(new_lines);
|
||||||
|
@ -431,7 +431,7 @@ file_measure_starts_widths(System_Functions *system, General_Memory *general,
|
||||||
{
|
{
|
||||||
f32 *new_lines = (f32*)
|
f32 *new_lines = (f32*)
|
||||||
general_memory_reallocate(general, buffer->line_widths,
|
general_memory_reallocate(general, buffer->line_widths,
|
||||||
sizeof(f32)*count, sizeof(f32)*max, BUBBLE_WIDTHS);
|
sizeof(f32)*count, sizeof(f32)*max, BUBBLE_WIDTHS);
|
||||||
|
|
||||||
// TODO(allen): when unable to grow?
|
// TODO(allen): when unable to grow?
|
||||||
TentativeAssert(new_lines);
|
TentativeAssert(new_lines);
|
||||||
|
@ -515,7 +515,7 @@ view_measure_wraps(General_Memory *general, View *view){
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_create_from_string(System_Functions *system, Models *models,
|
file_create_from_string(System_Functions *system, Models *models,
|
||||||
Editing_File *file, char *filename, String val, b8 read_only = 0){
|
Editing_File *file, char *filename, String val, b8 read_only = 0){
|
||||||
|
|
||||||
Font_Set *font_set = models->font_set;
|
Font_Set *font_set = models->font_set;
|
||||||
Working_Set *working_set = &models->working_set;
|
Working_Set *working_set = &models->working_set;
|
||||||
|
@ -606,14 +606,14 @@ file_create_from_string(System_Functions *system, Models *models,
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
file_create_empty(System_Functions *system,
|
file_create_empty(System_Functions *system,
|
||||||
Models *models, Editing_File *file, char *filename){
|
Models *models, Editing_File *file, char *filename){
|
||||||
file_create_from_string(system, models, file, filename, string_zero());
|
file_create_from_string(system, models, file, filename, string_zero());
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
file_create_read_only(System_Functions *system,
|
file_create_read_only(System_Functions *system,
|
||||||
Models *models, Editing_File *file, char *filename){
|
Models *models, Editing_File *file, char *filename){
|
||||||
file_create_from_string(system, models, file, filename, string_zero(), 1);
|
file_create_from_string(system, models, file, filename, string_zero(), 1);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -718,7 +718,7 @@ Job_Callback_Sig(job_full_lex){
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_kill_tokens(System_Functions *system,
|
file_kill_tokens(System_Functions *system,
|
||||||
General_Memory *general, Editing_File *file){
|
General_Memory *general, Editing_File *file){
|
||||||
file->settings.tokens_exist = 0;
|
file->settings.tokens_exist = 0;
|
||||||
if (file->state.still_lexing){
|
if (file->state.still_lexing){
|
||||||
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
|
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
|
||||||
|
@ -737,7 +737,7 @@ file_kill_tokens(System_Functions *system,
|
||||||
#if BUFFER_EXPERIMENT_SCALPEL <= 0
|
#if BUFFER_EXPERIMENT_SCALPEL <= 0
|
||||||
internal void
|
internal void
|
||||||
file_first_lex_parallel(System_Functions *system,
|
file_first_lex_parallel(System_Functions *system,
|
||||||
General_Memory *general, Editing_File *file){
|
General_Memory *general, Editing_File *file){
|
||||||
file->settings.tokens_exist = 1;
|
file->settings.tokens_exist = 1;
|
||||||
|
|
||||||
if (file->state.is_loading == 0 && file->state.still_lexing == 0){
|
if (file->state.is_loading == 0 && file->state.still_lexing == 0){
|
||||||
|
@ -758,8 +758,8 @@ file_first_lex_parallel(System_Functions *system,
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_relex_parallel(System_Functions *system,
|
file_relex_parallel(System_Functions *system,
|
||||||
Mem_Options *mem, Editing_File *file,
|
Mem_Options *mem, Editing_File *file,
|
||||||
i32 start_i, i32 end_i, i32 amount){
|
i32 start_i, i32 end_i, i32 amount){
|
||||||
General_Memory *general = &mem->general;
|
General_Memory *general = &mem->general;
|
||||||
Partition *part = &mem->part;
|
Partition *part = &mem->part;
|
||||||
if (file->state.token_stack.tokens == 0){
|
if (file->state.token_stack.tokens == 0){
|
||||||
|
@ -777,7 +777,7 @@ file_relex_parallel(System_Functions *system,
|
||||||
|
|
||||||
Cpp_Relex_State state =
|
Cpp_Relex_State state =
|
||||||
cpp_relex_nonalloc_start(cpp_file, stack,
|
cpp_relex_nonalloc_start(cpp_file, stack,
|
||||||
start_i, end_i, amount, 100);
|
start_i, end_i, amount, 100);
|
||||||
|
|
||||||
Temp_Memory temp = begin_temp_memory(part);
|
Temp_Memory temp = begin_temp_memory(part);
|
||||||
i32 relex_end;
|
i32 relex_end;
|
||||||
|
@ -798,8 +798,8 @@ file_relex_parallel(System_Functions *system,
|
||||||
int new_max = LargeRoundUp(new_count, Kbytes(1));
|
int new_max = LargeRoundUp(new_count, Kbytes(1));
|
||||||
stack->tokens = (Cpp_Token*)
|
stack->tokens = (Cpp_Token*)
|
||||||
general_memory_reallocate(general, stack->tokens,
|
general_memory_reallocate(general, stack->tokens,
|
||||||
stack->count*sizeof(Cpp_Token),
|
stack->count*sizeof(Cpp_Token),
|
||||||
new_max*sizeof(Cpp_Token), BUBBLE_TOKENS);
|
new_max*sizeof(Cpp_Token), BUBBLE_TOKENS);
|
||||||
stack->max_count = new_max;
|
stack->max_count = new_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -807,14 +807,14 @@ file_relex_parallel(System_Functions *system,
|
||||||
if (shift_size > 0){
|
if (shift_size > 0){
|
||||||
Cpp_Token *old_base = stack->tokens + relex_end;
|
Cpp_Token *old_base = stack->tokens + relex_end;
|
||||||
memmove(old_base + shift_amount, old_base,
|
memmove(old_base + shift_amount, old_base,
|
||||||
sizeof(Cpp_Token)*shift_size);
|
sizeof(Cpp_Token)*shift_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
stack->count += shift_amount;
|
stack->count += shift_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(state.stack->tokens + state.start_token_i, relex_space.tokens,
|
memcpy(state.stack->tokens + state.start_token_i, relex_space.tokens,
|
||||||
sizeof(Cpp_Token)*relex_space.count);
|
sizeof(Cpp_Token)*relex_space.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
end_temp_memory(temp);
|
end_temp_memory(temp);
|
||||||
|
@ -894,7 +894,7 @@ child_stack_grow_edits(General_Memory *general, Small_Edit_Stack *stack, i32 amo
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
undo_children_push(General_Memory *general, Small_Edit_Stack *children,
|
undo_children_push(General_Memory *general, Small_Edit_Stack *children,
|
||||||
Buffer_Edit *edits, i32 edit_count, u8 *strings, i32 string_size){
|
Buffer_Edit *edits, i32 edit_count, u8 *strings, i32 string_size){
|
||||||
i32 result = children->edit_count;
|
i32 result = children->edit_count;
|
||||||
if (children->edit_count + edit_count > children->edit_max)
|
if (children->edit_count + edit_count > children->edit_max)
|
||||||
child_stack_grow_edits(general, children, edit_count);
|
child_stack_grow_edits(general, children, edit_count);
|
||||||
|
@ -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, bool32 do_merge, bool32 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;
|
||||||
|
@ -939,7 +939,7 @@ file_post_undo(General_Memory *general, Editing_File *file,
|
||||||
|
|
||||||
Buffer_Edit inv;
|
Buffer_Edit inv;
|
||||||
buffer_invert_edit(&file->state.buffer, step.edit, &inv,
|
buffer_invert_edit(&file->state.buffer, step.edit, &inv,
|
||||||
(char*)undo->strings, &undo->size, undo->max);
|
(char*)undo->strings, &undo->size, undo->max);
|
||||||
|
|
||||||
Edit_Step inv_step = {};
|
Edit_Step inv_step = {};
|
||||||
inv_step.edit = inv;
|
inv_step.edit = inv;
|
||||||
|
@ -1006,7 +1006,7 @@ file_post_redo(General_Memory *general, Editing_File *file, Edit_Step step){
|
||||||
|
|
||||||
Buffer_Edit inv;
|
Buffer_Edit inv;
|
||||||
buffer_invert_edit(&file->state.buffer, step.edit, &inv,
|
buffer_invert_edit(&file->state.buffer, step.edit, &inv,
|
||||||
(char*)redo->strings, &redo->size, redo->max);
|
(char*)redo->strings, &redo->size, redo->max);
|
||||||
|
|
||||||
Edit_Step inv_step = {};
|
Edit_Step inv_step = {};
|
||||||
inv_step.edit = inv;
|
inv_step.edit = inv;
|
||||||
|
@ -1057,7 +1057,7 @@ file_unpost_history_block(Editing_File *file){
|
||||||
|
|
||||||
internal Edit_Step*
|
internal Edit_Step*
|
||||||
file_post_history(General_Memory *general, Editing_File *file,
|
file_post_history(General_Memory *general, Editing_File *file,
|
||||||
Edit_Step step, b32 do_merge, b32 can_merge){
|
Edit_Step step, b32 do_merge, b32 can_merge){
|
||||||
Edit_Stack *history = &file->state.undo.history;
|
Edit_Stack *history = &file->state.undo.history;
|
||||||
Edit_Step *result = 0;
|
Edit_Step *result = 0;
|
||||||
|
|
||||||
|
@ -1075,7 +1075,7 @@ file_post_history(General_Memory *general, Editing_File *file,
|
||||||
|
|
||||||
Buffer_Edit inv;
|
Buffer_Edit inv;
|
||||||
buffer_invert_edit(&file->state.buffer, step.edit, &inv,
|
buffer_invert_edit(&file->state.buffer, step.edit, &inv,
|
||||||
(char*)history->strings, &history->size, history->max);
|
(char*)history->strings, &history->size, history->max);
|
||||||
|
|
||||||
Edit_Step inv_step = {};
|
Edit_Step inv_step = {};
|
||||||
inv_step.edit = inv;
|
inv_step.edit = inv;
|
||||||
|
@ -1135,7 +1135,7 @@ view_compute_cursor_from_pos(View *view, i32 pos){
|
||||||
if (font){
|
if (font){
|
||||||
f32 max_width = view_file_width(view);
|
f32 max_width = view_file_width(view);
|
||||||
result = buffer_cursor_from_pos(&file->state.buffer, pos, view->file_data.line_wrap_y,
|
result = buffer_cursor_from_pos(&file->state.buffer, pos, view->file_data.line_wrap_y,
|
||||||
max_width, (f32)view->font_height, font->advance_data);
|
max_width, (f32)view->font_height, font->advance_data);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1150,7 +1150,7 @@ view_compute_cursor_from_unwrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 ro
|
||||||
if (font){
|
if (font){
|
||||||
f32 max_width = view_file_width(view);
|
f32 max_width = view_file_width(view);
|
||||||
result = buffer_cursor_from_unwrapped_xy(&file->state.buffer, seek_x, seek_y,
|
result = buffer_cursor_from_unwrapped_xy(&file->state.buffer, seek_x, seek_y,
|
||||||
round_down, view->file_data.line_wrap_y, max_width, (f32)view->font_height, font->advance_data);
|
round_down, view->file_data.line_wrap_y, max_width, (f32)view->font_height, font->advance_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -1166,8 +1166,8 @@ view_compute_cursor_from_wrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 roun
|
||||||
if (font){
|
if (font){
|
||||||
f32 max_width = view_file_width(view);
|
f32 max_width = view_file_width(view);
|
||||||
result = buffer_cursor_from_wrapped_xy(&file->state.buffer, seek_x, seek_y,
|
result = buffer_cursor_from_wrapped_xy(&file->state.buffer, seek_x, seek_y,
|
||||||
round_down, view->file_data.line_wrap_y,
|
round_down, view->file_data.line_wrap_y,
|
||||||
max_width, (f32)view->font_height, font->advance_data);
|
max_width, (f32)view->font_height, font->advance_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
|
@ -1183,7 +1183,7 @@ view_compute_cursor_from_line_pos(View *view, i32 line, i32 pos){
|
||||||
if (font){
|
if (font){
|
||||||
f32 max_width = view_file_width(view);
|
f32 max_width = view_file_width(view);
|
||||||
result = buffer_cursor_from_line_character(&file->state.buffer, line, pos,
|
result = buffer_cursor_from_line_character(&file->state.buffer, line, pos,
|
||||||
view->file_data.line_wrap_y, max_width, (f32)view->font_height, font->advance_data);
|
view->file_data.line_wrap_y, max_width, (f32)view->font_height, font->advance_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (result);
|
return (result);
|
||||||
|
@ -1398,7 +1398,7 @@ enum History_Mode{
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step step, u8 *str,
|
file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step step, u8 *str,
|
||||||
History_Mode history_mode){
|
History_Mode history_mode){
|
||||||
if (!file->state.undo.undo.edits) return;
|
if (!file->state.undo.undo.edits) return;
|
||||||
General_Memory *general = &mem->general;
|
General_Memory *general = &mem->general;
|
||||||
|
|
||||||
|
@ -1552,8 +1552,8 @@ file_update_history_before_edit(Mem_Options *mem, Editing_File *file, Edit_Step
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
file_pre_edit_maintenance(System_Functions *system,
|
file_pre_edit_maintenance(System_Functions *system,
|
||||||
General_Memory *general,
|
General_Memory *general,
|
||||||
Editing_File *file){
|
Editing_File *file){
|
||||||
if (file->state.still_lexing){
|
if (file->state.still_lexing){
|
||||||
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
|
system->cancel_job(BACKGROUND_THREADS, file->state.lex_job);
|
||||||
if (file->state.swap_stack.tokens){
|
if (file->state.swap_stack.tokens){
|
||||||
|
@ -1580,9 +1580,9 @@ struct Cursor_Fix_Descriptor{
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_edit_cursor_fix(System_Functions *system,
|
file_edit_cursor_fix(System_Functions *system,
|
||||||
Partition *part, General_Memory *general,
|
Partition *part, General_Memory *general,
|
||||||
Editing_File *file, Editing_Layout *layout,
|
Editing_File *file, Editing_Layout *layout,
|
||||||
Cursor_Fix_Descriptor desc){
|
Cursor_Fix_Descriptor desc){
|
||||||
|
|
||||||
Full_Cursor temp_cursor;
|
Full_Cursor temp_cursor;
|
||||||
Temp_Memory cursor_temp = begin_temp_memory(part);
|
Temp_Memory cursor_temp = begin_temp_memory(part);
|
||||||
|
@ -1610,12 +1610,12 @@ file_edit_cursor_fix(System_Functions *system,
|
||||||
buffer_sort_cursors(cursors, cursor_count);
|
buffer_sort_cursors(cursors, cursor_count);
|
||||||
if (desc.is_batch){
|
if (desc.is_batch){
|
||||||
buffer_batch_edit_update_cursors(cursors, cursor_count,
|
buffer_batch_edit_update_cursors(cursors, cursor_count,
|
||||||
desc.batch, desc.batch_size);
|
desc.batch, desc.batch_size);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
buffer_update_cursors(cursors, cursor_count,
|
buffer_update_cursors(cursors, cursor_count,
|
||||||
desc.start, desc.end,
|
desc.start, desc.end,
|
||||||
desc.shift_amount + (desc.end - desc.start));
|
desc.shift_amount + (desc.end - desc.start));
|
||||||
}
|
}
|
||||||
buffer_unsort_cursors(cursors, cursor_count);
|
buffer_unsort_cursors(cursors, cursor_count);
|
||||||
|
|
||||||
|
@ -1653,8 +1653,8 @@ file_edit_cursor_fix(System_Functions *system,
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_do_single_edit(System_Functions *system,
|
file_do_single_edit(System_Functions *system,
|
||||||
Models *models, Editing_File *file,
|
Models *models, Editing_File *file,
|
||||||
Edit_Spec spec, History_Mode history_mode, b32 use_high_permission = 0){
|
Edit_Spec spec, History_Mode history_mode, b32 use_high_permission = 0){
|
||||||
if (!use_high_permission && file->settings.read_only) return;
|
if (!use_high_permission && file->settings.read_only) return;
|
||||||
|
|
||||||
Mem_Options *mem = &models->mem;
|
Mem_Options *mem = &models->mem;
|
||||||
|
@ -1680,7 +1680,7 @@ file_do_single_edit(System_Functions *system,
|
||||||
i32 request_amount = 0;
|
i32 request_amount = 0;
|
||||||
Assert(end <= buffer_size(&file->state.buffer));
|
Assert(end <= buffer_size(&file->state.buffer));
|
||||||
while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount,
|
while (buffer_replace_range(&file->state.buffer, start, end, str, str_len, &shift_amount,
|
||||||
part->base + part->pos, scratch_size, &request_amount)){
|
part->base + part->pos, scratch_size, &request_amount)){
|
||||||
void *new_data = 0;
|
void *new_data = 0;
|
||||||
if (request_amount > 0){
|
if (request_amount > 0){
|
||||||
new_data = general_memory_allocate(general, request_amount, BUBBLE_BUFFER);
|
new_data = general_memory_allocate(general, request_amount, BUBBLE_BUFFER);
|
||||||
|
@ -1729,7 +1729,7 @@ file_do_single_edit(System_Functions *system,
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File *file,
|
file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File *file,
|
||||||
Edit_Spec spec, History_Mode history_mode, b32 use_high_permission = 0){
|
Edit_Spec spec, History_Mode history_mode, b32 use_high_permission = 0){
|
||||||
if (!use_high_permission && file->settings.read_only) return;
|
if (!use_high_permission && file->settings.read_only) return;
|
||||||
|
|
||||||
Mem_Options *mem = &models->mem;
|
Mem_Options *mem = &models->mem;
|
||||||
|
@ -1755,8 +1755,8 @@ file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File
|
||||||
Buffer_Batch_State state = {};
|
Buffer_Batch_State state = {};
|
||||||
i32 request_amount;
|
i32 request_amount;
|
||||||
while (buffer_batch_edit_step(&state, &file->state.buffer, batch,
|
while (buffer_batch_edit_step(&state, &file->state.buffer, batch,
|
||||||
(char*)str_base, batch_size, part->base + part->pos,
|
(char*)str_base, batch_size, part->base + part->pos,
|
||||||
scratch_size, &request_amount)){
|
scratch_size, &request_amount)){
|
||||||
void *new_data = 0;
|
void *new_data = 0;
|
||||||
if (request_amount > 0){
|
if (request_amount > 0){
|
||||||
new_data = general_memory_allocate(general, request_amount, BUBBLE_BUFFER);
|
new_data = general_memory_allocate(general, request_amount, BUBBLE_BUFFER);
|
||||||
|
@ -1789,6 +1789,7 @@ file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File
|
||||||
Cpp_Token_Stack tokens = file->state.token_stack;
|
Cpp_Token_Stack tokens = file->state.token_stack;
|
||||||
Cpp_Token *token = tokens.tokens;
|
Cpp_Token *token = tokens.tokens;
|
||||||
Cpp_Token *end_token = tokens.tokens + tokens.count;
|
Cpp_Token *end_token = tokens.tokens + tokens.count;
|
||||||
|
Cpp_Token original = {(Cpp_Token_Type)0};
|
||||||
|
|
||||||
Buffer_Edit *edit = batch;
|
Buffer_Edit *edit = batch;
|
||||||
Buffer_Edit *end_edit = batch + batch_size;
|
Buffer_Edit *end_edit = batch + batch_size;
|
||||||
|
@ -1796,27 +1797,56 @@ file_do_white_batch_edit(System_Functions *system, Models *models, Editing_File
|
||||||
i32 shift_amount = 0;
|
i32 shift_amount = 0;
|
||||||
i32 local_shift = 0;
|
i32 local_shift = 0;
|
||||||
|
|
||||||
for (; token < end_token && edit < end_edit; ++edit){
|
for (; token < end_token; ++token){
|
||||||
local_shift = (edit->len - (edit->end - edit->start));
|
original = *token;
|
||||||
for (; token->start < edit->start && edit->start < token->start + token->size &&
|
for (; edit < end_edit && edit->start <= original.start; ++edit){
|
||||||
token < end_token; ++token){
|
local_shift = (edit->len - (edit->end - edit->start));
|
||||||
token->size += local_shift;
|
shift_amount += local_shift;
|
||||||
token->start += shift_amount;
|
|
||||||
}
|
}
|
||||||
for (; token->start < edit->start && token < end_token; ++token){
|
token->start += shift_amount;
|
||||||
token->start += shift_amount;
|
local_shift = 0;
|
||||||
|
for (; edit < end_edit && edit->start < original.start + original.size; ++edit){
|
||||||
|
local_shift += (edit->len - (edit->end - edit->start));
|
||||||
}
|
}
|
||||||
|
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){
|
for (; token < end_token; ++token){
|
||||||
token->start += shift_amount;
|
token->start += shift_amount;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
file_replace_range(System_Functions *system, Models *models, Editing_File *file,
|
file_replace_range(System_Functions *system, Models *models, Editing_File *file,
|
||||||
i32 start, i32 end, char *str, i32 len, i32 next_cursor, b32 use_high_permission = 0){
|
i32 start, i32 end, char *str, i32 len, i32 next_cursor, b32 use_high_permission = 0){
|
||||||
Edit_Spec spec = {};
|
Edit_Spec spec = {};
|
||||||
spec.step.type = ED_NORMAL;
|
spec.step.type = ED_NORMAL;
|
||||||
spec.step.edit.start = start;
|
spec.step.edit.start = start;
|
||||||
|
@ -1836,7 +1866,7 @@ file_clear(System_Functions *system, Models *models, Editing_File *file, b32 use
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
view_replace_range(System_Functions *system, Models *models, View *view,
|
view_replace_range(System_Functions *system, Models *models, View *view,
|
||||||
i32 start, i32 end, char *str, i32 len, i32 next_cursor){
|
i32 start, i32 end, char *str, i32 len, i32 next_cursor){
|
||||||
file_replace_range(system, models, view->file_data.file, start, end, str, len, next_cursor);
|
file_replace_range(system, models, view->file_data.file, start, end, str, len, next_cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1863,8 +1893,8 @@ main_style(Models *models){
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_undo_redo(System_Functions *system,
|
view_undo_redo(System_Functions *system,
|
||||||
Models *models, View *view,
|
Models *models, View *view,
|
||||||
Edit_Stack *stack, Edit_Type expected_type){
|
Edit_Stack *stack, Edit_Type expected_type){
|
||||||
Editing_File *file = view->file_data.file;
|
Editing_File *file = view->file_data.file;
|
||||||
|
|
||||||
if (stack->edit_count > 0){
|
if (stack->edit_count > 0){
|
||||||
|
@ -1887,7 +1917,7 @@ view_undo_redo(System_Functions *system,
|
||||||
|
|
||||||
Style *style = main_style(models);
|
Style *style = main_style(models);
|
||||||
view_post_paste_effect(view, 10, step.edit.start, step.edit.len,
|
view_post_paste_effect(view, 10, step.edit.start, step.edit.len,
|
||||||
style->main.undo_color);
|
style->main.undo_color);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
TentativeAssert(spec.step.special_type == 1);
|
TentativeAssert(spec.step.special_type == 1);
|
||||||
|
@ -2056,7 +2086,7 @@ view_find_beginning_of_next_line(View *view, i32 pos){
|
||||||
Editing_File *file = view->file_data.file;
|
Editing_File *file = view->file_data.file;
|
||||||
char *data = file->state.buffer.data;
|
char *data = file->state.buffer.data;
|
||||||
while (pos < file->state.buffer.size &&
|
while (pos < file->state.buffer.size &&
|
||||||
!starts_new_line(data[pos])){
|
!starts_new_line(data[pos])){
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
if (pos < file->state.buffer.size){
|
if (pos < file->state.buffer.size){
|
||||||
|
@ -2135,24 +2165,24 @@ clipboard_copy(System_Functions *system, General_Memory *general, Working_Set *w
|
||||||
|
|
||||||
internal Edit_Spec
|
internal Edit_Spec
|
||||||
file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, i32 cursor_pos,
|
file_compute_whitespace_edit(Mem_Options *mem, Editing_File *file, i32 cursor_pos,
|
||||||
Buffer_Edit *edits, char *str_base, i32 str_size,
|
Buffer_Edit *edits, char *str_base, i32 str_size,
|
||||||
Buffer_Edit *inverse_array, char *inv_str, i32 inv_max,
|
Buffer_Edit *inverse_array, char *inv_str, i32 inv_max,
|
||||||
i32 edit_count){
|
i32 edit_count){
|
||||||
General_Memory *general = &mem->general;
|
General_Memory *general = &mem->general;
|
||||||
|
|
||||||
i32 inv_str_pos = 0;
|
i32 inv_str_pos = 0;
|
||||||
Buffer_Invert_Batch state = {};
|
Buffer_Invert_Batch state = {};
|
||||||
if (buffer_invert_batch(&state, &file->state.buffer, edits, edit_count,
|
if (buffer_invert_batch(&state, &file->state.buffer, edits, edit_count,
|
||||||
inverse_array, inv_str, &inv_str_pos, inv_max)){
|
inverse_array, inv_str, &inv_str_pos, inv_max)){
|
||||||
Assert(0);
|
Assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 first_child =
|
i32 first_child =
|
||||||
undo_children_push(general, &file->state.undo.children,
|
undo_children_push(general, &file->state.undo.children,
|
||||||
edits, edit_count, (u8*)(str_base), str_size);
|
edits, edit_count, (u8*)(str_base), str_size);
|
||||||
i32 inverse_first_child =
|
i32 inverse_first_child =
|
||||||
undo_children_push(general, &file->state.undo.children,
|
undo_children_push(general, &file->state.undo.children,
|
||||||
inverse_array, edit_count, (u8*)(inv_str), inv_str_pos);
|
inverse_array, edit_count, (u8*)(inv_str), inv_str_pos);
|
||||||
|
|
||||||
Edit_Spec spec = {};
|
Edit_Spec spec = {};
|
||||||
spec.step.type = ED_NORMAL;
|
spec.step.type = ED_NORMAL;
|
||||||
|
@ -2215,7 +2245,7 @@ view_clean_whitespace(System_Functions *system, Models *models, View *view){
|
||||||
char *inv_str = (char*)part->base + part->pos;
|
char *inv_str = (char*)part->base + part->pos;
|
||||||
Edit_Spec spec =
|
Edit_Spec spec =
|
||||||
file_compute_whitespace_edit(mem, file, view->file_data.cursor.pos, edits, str_base, str_size,
|
file_compute_whitespace_edit(mem, file, view->file_data.cursor.pos, edits, str_base, str_size,
|
||||||
inverse_array, inv_str, part->max - part->pos, edit_count);
|
inverse_array, inv_str, part->max - part->pos, edit_count);
|
||||||
|
|
||||||
file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal);
|
file_do_white_batch_edit(system, models, view->file_data.file, spec, hist_normal);
|
||||||
}
|
}
|
||||||
|
@ -2254,7 +2284,7 @@ get_first_token_at_line(Buffer *buffer, Cpp_Token_Stack tokens, i32 line){
|
||||||
|
|
||||||
internal Cpp_Token*
|
internal Cpp_Token*
|
||||||
seek_matching_token_backwards(Cpp_Token_Stack tokens, Cpp_Token *token,
|
seek_matching_token_backwards(Cpp_Token_Stack tokens, Cpp_Token *token,
|
||||||
Cpp_Token_Type open_type, Cpp_Token_Type close_type){
|
Cpp_Token_Type open_type, Cpp_Token_Type close_type){
|
||||||
int nesting_level = 0;
|
int nesting_level = 0;
|
||||||
if (token <= tokens.tokens){
|
if (token <= tokens.tokens){
|
||||||
token = tokens.tokens;
|
token = tokens.tokens;
|
||||||
|
@ -2288,7 +2318,7 @@ struct Indent_Parse_State{
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
compute_this_indent(Buffer *buffer, Indent_Parse_State indent,
|
compute_this_indent(Buffer *buffer, Indent_Parse_State indent,
|
||||||
Cpp_Token T, Cpp_Token prev_token, i32 line_i, i32 tab_width){
|
Cpp_Token T, Cpp_Token prev_token, i32 line_i, i32 tab_width){
|
||||||
|
|
||||||
i32 previous_indent = indent.previous_line_indent;
|
i32 previous_indent = indent.previous_line_indent;
|
||||||
i32 this_indent = 0;
|
i32 this_indent = 0;
|
||||||
|
@ -2303,8 +2333,8 @@ compute_this_indent(Buffer *buffer, Indent_Parse_State indent,
|
||||||
next_line_start = buffer_size(buffer);
|
next_line_start = buffer_size(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prev_token.type == CPP_TOKEN_COMMENT &&
|
if ((prev_token.type == CPP_TOKEN_COMMENT || prev_token.type == CPP_TOKEN_STRING_CONSTANT) &&
|
||||||
prev_token.start <= this_line_start && prev_token.start + prev_token.size > this_line_start){
|
prev_token.start <= this_line_start && prev_token.start + prev_token.size > this_line_start){
|
||||||
this_indent = previous_indent;
|
this_indent = previous_indent;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
Loading…
Reference in New Issue