Edit position stack cleanup
This commit is contained in:
parent
d9f71adcb3
commit
5926d9fdd9
|
@ -752,7 +752,7 @@ OPEN_FILE_HOOK_SIG(default_file_save){
|
||||||
|
|
||||||
FILE_EDIT_FINISHED_SIG(default_file_edit){
|
FILE_EDIT_FINISHED_SIG(default_file_edit){
|
||||||
for (int32_t i = 0; i < buffer_id_count; i += 1){
|
for (int32_t i = 0; i < buffer_id_count; i += 1){
|
||||||
#if 0
|
#if 1
|
||||||
// NOTE(allen|4.0.31): This code is example usage, it's not a particularly nice feature to actually have.
|
// NOTE(allen|4.0.31): This code is example usage, it's not a particularly nice feature to actually have.
|
||||||
|
|
||||||
Buffer_Summary buffer = get_buffer(app, buffer_ids[i], AccessAll);
|
Buffer_Summary buffer = get_buffer(app, buffer_ids[i], AccessAll);
|
||||||
|
|
16
4ed.cpp
16
4ed.cpp
|
@ -74,7 +74,7 @@ file_cursor_to_end(System_Functions *system, Models *models, Editing_File *file)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
view_cursor_move(system, view, pos);
|
view_cursor_move(system, view, pos);
|
||||||
view->transient.edit_pos->mark = view->transient.edit_pos->cursor.pos;
|
view->transient.edit_pos.mark = view->transient.edit_pos.cursor.pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,6 @@ internal void
|
||||||
view_undo_redo(System_Functions *system, Models *models, View *view, Edit_Stack *stack, Edit_Type expected_type){
|
view_undo_redo(System_Functions *system, Models *models, View *view, Edit_Stack *stack, Edit_Type expected_type){
|
||||||
Editing_File *file = view->transient.file_data.file;
|
Editing_File *file = view->transient.file_data.file;
|
||||||
Assert(file != 0);
|
Assert(file != 0);
|
||||||
Assert(view->transient.edit_pos != 0);
|
|
||||||
if (stack->edit_count > 0){
|
if (stack->edit_count > 0){
|
||||||
Edit_Step step = stack->edits[stack->edit_count - 1];
|
Edit_Step step = stack->edits[stack->edit_count - 1];
|
||||||
Assert(step.type == expected_type);
|
Assert(step.type == expected_type);
|
||||||
|
@ -1522,7 +1521,7 @@ App_Step_Sig(app_step){
|
||||||
i32 max_y = 0;
|
i32 max_y = 0;
|
||||||
b32 file_scroll = false;
|
b32 file_scroll = false;
|
||||||
if (!view->transient.ui_mode){
|
if (!view->transient.ui_mode){
|
||||||
scroll_vars = &view->transient.edit_pos->scroll;
|
scroll_vars = &view->transient.edit_pos.scroll;
|
||||||
max_y = view_compute_max_target_y(view);
|
max_y = view_compute_max_target_y(view);
|
||||||
file_scroll = true;
|
file_scroll = true;
|
||||||
}
|
}
|
||||||
|
@ -1557,11 +1556,9 @@ App_Step_Sig(app_step){
|
||||||
panel != &models->layout.used_sentinel;
|
panel != &models->layout.used_sentinel;
|
||||||
panel = panel->next){
|
panel = panel->next){
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
if (view->transient.edit_pos != 0){
|
GUI_Scroll_Vars *scroll_vars = &view->transient.edit_pos.scroll;
|
||||||
GUI_Scroll_Vars *scroll_vars = &view->transient.edit_pos->scroll;
|
scroll_vars->scroll_x = (f32)scroll_vars->target_x;
|
||||||
scroll_vars->scroll_x = (f32)scroll_vars->target_x;
|
scroll_vars->scroll_y = (f32)scroll_vars->target_y;
|
||||||
scroll_vars->scroll_y = (f32)scroll_vars->target_y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1590,6 +1587,7 @@ App_Step_Sig(app_step){
|
||||||
Editing_File *file = CastFromMember(Editing_File, edit_finished_mark_node, node);
|
Editing_File *file = CastFromMember(Editing_File, edit_finished_mark_node, node);
|
||||||
Buffer_ID *new_id = push_array(scratch, Buffer_ID, 1);
|
Buffer_ID *new_id = push_array(scratch, Buffer_ID, 1);
|
||||||
*new_id = file->id.id;
|
*new_id = file->id.id;
|
||||||
|
|
||||||
}
|
}
|
||||||
i32 id_count = (i32)(push_array(scratch, Buffer_ID, 0) - ids);
|
i32 id_count = (i32)(push_array(scratch, Buffer_ID, 0) - ids);
|
||||||
|
|
||||||
|
@ -1647,7 +1645,7 @@ App_Step_Sig(app_step){
|
||||||
|
|
||||||
draw_rectangle(target, full, style->theme.colors[Stag_Back]);
|
draw_rectangle(target, full, style->theme.colors[Stag_Back]);
|
||||||
|
|
||||||
GUI_Scroll_Vars *scroll_vars = &view->transient.edit_pos->scroll;
|
GUI_Scroll_Vars *scroll_vars = &view->transient.edit_pos.scroll;
|
||||||
|
|
||||||
b32 active = (panel == active_panel);
|
b32 active = (panel == active_panel);
|
||||||
do_render_file_view(system, view, models, scroll_vars, active_view, panel->inner, active, target);
|
do_render_file_view(system, view, models, scroll_vars, active_view, panel->inner, active, target);
|
||||||
|
|
|
@ -66,9 +66,9 @@ fill_view_summary(System_Functions *system, View_Summary *view, View *vptr, Live
|
||||||
view->buffer_id = vptr->transient.file_data.file->id.id;
|
view->buffer_id = vptr->transient.file_data.file->id.id;
|
||||||
|
|
||||||
Assert(data->file != 0);
|
Assert(data->file != 0);
|
||||||
view->mark = file_compute_cursor(system, data->file, seek_pos(vptr->transient.edit_pos->mark), 0);
|
view->mark = file_compute_cursor(system, data->file, seek_pos(vptr->transient.edit_pos.mark), 0);
|
||||||
view->cursor = vptr->transient.edit_pos->cursor;
|
view->cursor = vptr->transient.edit_pos.cursor;
|
||||||
view->preferred_x = vptr->transient.edit_pos->preferred_x;
|
view->preferred_x = vptr->transient.edit_pos.preferred_x;
|
||||||
|
|
||||||
view->view_region = vptr->transient.panel->inner;
|
view->view_region = vptr->transient.panel->inner;
|
||||||
view->file_region = vptr->transient.file_region;
|
view->file_region = vptr->transient.file_region;
|
||||||
|
@ -76,7 +76,7 @@ fill_view_summary(System_Functions *system, View_Summary *view, View *vptr, Live
|
||||||
view->scroll_vars = vptr->transient.ui_scroll;
|
view->scroll_vars = vptr->transient.ui_scroll;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
view->scroll_vars = vptr->transient.edit_pos->scroll;
|
view->scroll_vars = vptr->transient.edit_pos.scroll;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1401,9 +1401,9 @@ Reopen_Buffer(Application_Links *app, Buffer_Summary *buffer, Buffer_Reopen_Flag
|
||||||
|
|
||||||
// TODO(allen): try(perform a diff maybe apply edits in reopen)
|
// TODO(allen): try(perform a diff maybe apply edits in reopen)
|
||||||
|
|
||||||
File_Edit_Positions edit_poss[16];
|
File_Edit_Positions edit_positions[16];
|
||||||
int32_t line_number[16];
|
int32_t line_numbers[16];
|
||||||
int32_t column_number[16];
|
int32_t column_numbers[16];
|
||||||
View *vptrs[16];
|
View *vptrs[16];
|
||||||
i32 vptr_count = 0;
|
i32 vptr_count = 0;
|
||||||
|
|
||||||
|
@ -1415,11 +1415,10 @@ Reopen_Buffer(Application_Links *app, Buffer_Summary *buffer, Buffer_Reopen_Flag
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
vptrs[vptr_count] = view_it;
|
vptrs[vptr_count] = view_it;
|
||||||
edit_poss[vptr_count] = view_it->transient.edit_pos[0];
|
edit_positions[vptr_count] = view_it->transient.edit_pos;
|
||||||
line_number[vptr_count] = view_it->transient.edit_pos[0].cursor.line;
|
line_numbers[vptr_count] = view_it->transient.edit_pos.cursor.line;
|
||||||
column_number[vptr_count] = view_it->transient.edit_pos[0].cursor.character;
|
column_numbers[vptr_count] = view_it->transient.edit_pos.cursor.character;
|
||||||
view_it->transient.file_data.file = models->scratch_buffer;
|
view_it->transient.file_data.file = models->scratch_buffer;
|
||||||
view_it->transient.edit_pos = 0;
|
|
||||||
++vptr_count;
|
++vptr_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1430,12 +1429,9 @@ Reopen_Buffer(Application_Links *app, Buffer_Summary *buffer, Buffer_Reopen_Flag
|
||||||
for (i32 i = 0; i < vptr_count; ++i){
|
for (i32 i = 0; i < vptr_count; ++i){
|
||||||
view_set_file(system, models, vptrs[i], file);
|
view_set_file(system, models, vptrs[i], file);
|
||||||
|
|
||||||
int32_t line = line_number[i];
|
|
||||||
int32_t character = column_number[i];
|
|
||||||
|
|
||||||
vptrs[i]->transient.file_data.file = file;
|
vptrs[i]->transient.file_data.file = file;
|
||||||
*vptrs[i]->transient.edit_pos = edit_poss[i];
|
vptrs[i]->transient.edit_pos = edit_positions[i];
|
||||||
Full_Cursor cursor = file_compute_cursor(system, file, seek_line_char(line, character), 0);
|
Full_Cursor cursor = file_compute_cursor(system, file, seek_line_char(line_numbers[i], column_numbers[i]), 0);
|
||||||
|
|
||||||
view_set_cursor(vptrs[i], cursor, true, file->settings.unwrapped_lines);
|
view_set_cursor(vptrs[i], cursor, true, file->settings.unwrapped_lines);
|
||||||
}
|
}
|
||||||
|
@ -2034,11 +2030,11 @@ DOC_SEE(Buffer_Seek)
|
||||||
if (seek.type != buffer_seek_pos){
|
if (seek.type != buffer_seek_pos){
|
||||||
result = true;
|
result = true;
|
||||||
Full_Cursor cursor = file_compute_cursor(system, file, seek, 0);
|
Full_Cursor cursor = file_compute_cursor(system, file, seek, 0);
|
||||||
vptr->transient.edit_pos->mark = cursor.pos;
|
vptr->transient.edit_pos.mark = cursor.pos;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
result = true;
|
result = true;
|
||||||
vptr->transient.edit_pos->mark = seek.pos;
|
vptr->transient.edit_pos.mark = seek.pos;
|
||||||
}
|
}
|
||||||
fill_view_summary(system, view, vptr, models);
|
fill_view_summary(system, view, vptr, models);
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,19 +422,23 @@ buffer_stringify_next(Gap_Buffer_Stream *stream){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 *shift_amount,
|
buffer_replace_range_compute_shift(i32 start, i32 end, i32 len){
|
||||||
|
return(len - (end - start));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal i32
|
||||||
|
buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len, i32 shift_amount,
|
||||||
void *scratch, i32 scratch_memory, i32 *request_amount){
|
void *scratch, i32 scratch_memory, i32 *request_amount){
|
||||||
char *data = buffer->data;
|
char *data = buffer->data;
|
||||||
i32 size = buffer_size(buffer);
|
i32 size = buffer_size(buffer);
|
||||||
i32 result = 0;
|
i32 result = false;
|
||||||
i32 move_size = 0;
|
i32 move_size = 0;
|
||||||
|
|
||||||
Assert(0 <= start);
|
Assert(0 <= start);
|
||||||
Assert(start <= end);
|
Assert(start <= end);
|
||||||
Assert(end <= size);
|
Assert(end <= size);
|
||||||
|
|
||||||
*shift_amount = (len - (end - start));
|
if (shift_amount + size <= buffer->max){
|
||||||
if (*shift_amount + size <= buffer->max){
|
|
||||||
if (end < buffer->size1){
|
if (end < buffer->size1){
|
||||||
move_size = buffer->size1 - end;
|
move_size = buffer->size1 - end;
|
||||||
memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size);
|
memmove(data + buffer->size1 + buffer->gap_size - move_size, data + end, move_size);
|
||||||
|
@ -451,35 +455,40 @@ buffer_replace_range(Gap_Buffer *buffer, i32 start, i32 end, char *str, i32 len,
|
||||||
memcpy(data + start, str, len);
|
memcpy(data + start, str, len);
|
||||||
buffer->size2 = size - end;
|
buffer->size2 = size - end;
|
||||||
buffer->size1 = start + len;
|
buffer->size1 = start + len;
|
||||||
buffer->gap_size -= *shift_amount;
|
buffer->gap_size -= shift_amount;
|
||||||
|
|
||||||
Assert(buffer->size1 + buffer->size2 == size + *shift_amount);
|
Assert(buffer->size1 + buffer->size2 == size + shift_amount);
|
||||||
Assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
|
Assert(buffer->size1 + buffer->gap_size + buffer->size2 == buffer->max);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
*request_amount = l_round_up_i32(2*(*shift_amount + size), 4 << 10);
|
*request_amount = l_round_up_i32(2*(shift_amount + size), 4 << 10);
|
||||||
result = 1;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(allen): Now that we are just using Gap_Buffer we could afford to improve
|
// TODO(allen): do(optimize Gap_Buffer batch edit)
|
||||||
|
// Now that we are just using Gap_Buffer we could afford to improve
|
||||||
// this for the Gap_Buffer's behavior.
|
// this for the Gap_Buffer's behavior.
|
||||||
internal i32
|
internal i32
|
||||||
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, i32 edit_count, void *scratch, i32 scratch_size, i32 *request_amount){
|
buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Buffer_Edit *sorted_edits, char *strings, i32 edit_count,
|
||||||
|
void *scratch, i32 scratch_size, i32 *request_amount){
|
||||||
Buffer_Edit *edit = 0;
|
Buffer_Edit *edit = 0;
|
||||||
i32 i = state->i;
|
|
||||||
i32 shift_total = state->shift_total;
|
i32 shift_total = state->shift_total;
|
||||||
i32 shift_amount = 0;
|
|
||||||
i32 result = 0;
|
i32 result = 0;
|
||||||
|
|
||||||
|
i32 i = state->i;
|
||||||
edit = sorted_edits + i;
|
edit = sorted_edits + i;
|
||||||
for (; i < edit_count; ++i, ++edit){
|
for (; i < edit_count; ++i, ++edit){
|
||||||
result = buffer_replace_range(buffer, edit->start + shift_total, edit->end + shift_total,
|
i32 start = edit->start + shift_total;
|
||||||
strings + edit->str_start, edit->len, &shift_amount,
|
i32 end = edit->end + shift_total;
|
||||||
scratch, scratch_size, request_amount);
|
i32 len = edit->len;
|
||||||
if (result) break;
|
i32 shift_amount = buffer_replace_range_compute_shift(start, end, len);
|
||||||
|
result = buffer_replace_range(buffer, start, end, strings + edit->str_start, len, shift_amount, scratch, scratch_size, request_amount);
|
||||||
|
if (result){
|
||||||
|
break;
|
||||||
|
}
|
||||||
shift_total += shift_amount;
|
shift_total += shift_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
165
4ed_edit.cpp
165
4ed_edit.cpp
|
@ -71,12 +71,12 @@ edit_fix_markers__read_workspace_markers(Dynamic_Workspace *workspace, Buffer_ID
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, Editing_Layout *layout, Cursor_Fix_Descriptor desc){
|
edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, Editing_Layout *layout, Cursor_Fix_Descriptor desc){
|
||||||
|
|
||||||
Partition *part = &models->mem.part;
|
Partition *part = &models->mem.part;
|
||||||
|
|
||||||
Temp_Memory cursor_temp = begin_temp_memory(part);
|
Temp_Memory cursor_temp = begin_temp_memory(part);
|
||||||
|
|
||||||
Lifetime_Object *file_lifetime_object = file->lifetime_object;
|
Lifetime_Object *file_lifetime_object = file->lifetime_object;
|
||||||
|
Buffer_ID file_id = file->id.id;
|
||||||
Assert(file_lifetime_object != 0);
|
Assert(file_lifetime_object != 0);
|
||||||
|
|
||||||
i32 cursor_max = layout->panel_max_count * 3;
|
i32 cursor_max = layout->panel_max_count * 3;
|
||||||
|
@ -111,15 +111,13 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
|
||||||
panel = panel->next){
|
panel = panel->next){
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
if (view->transient.file_data.file == file){
|
if (view->transient.file_data.file == file){
|
||||||
Assert(view->transient.edit_pos != 0);
|
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos.cursor.pos);
|
||||||
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos->cursor.pos);
|
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos.mark);
|
||||||
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos->mark);
|
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos.scroll_i);
|
||||||
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos->scroll_i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_fix_markers__write_workspace_markers(&file_lifetime_object->workspace, file->id.id,
|
edit_fix_markers__write_workspace_markers(&file_lifetime_object->workspace, file_id, cursors, r_cursors, &cursor_count, &r_cursor_count);
|
||||||
cursors, r_cursors, &cursor_count, &r_cursor_count);
|
|
||||||
|
|
||||||
{
|
{
|
||||||
i32 key_count = file_lifetime_object->key_count;
|
i32 key_count = file_lifetime_object->key_count;
|
||||||
|
@ -130,8 +128,7 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
|
||||||
i32 count = clamp_top(lifetime_key_reference_per_node, key_count - key_index);
|
i32 count = clamp_top(lifetime_key_reference_per_node, key_count - key_index);
|
||||||
for (i32 i = 0; i < count; i += 1){
|
for (i32 i = 0; i < count; i += 1){
|
||||||
Lifetime_Key *key = key_node->keys[i];
|
Lifetime_Key *key = key_node->keys[i];
|
||||||
edit_fix_markers__write_workspace_markers(&key->dynamic_workspace, file->id.id,
|
edit_fix_markers__write_workspace_markers(&key->dynamic_workspace, file_id, cursors, r_cursors, &cursor_count, &r_cursor_count);
|
||||||
cursors, r_cursors, &cursor_count, &r_cursor_count);
|
|
||||||
}
|
}
|
||||||
key_index += count;
|
key_index += count;
|
||||||
}
|
}
|
||||||
|
@ -156,21 +153,19 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
|
||||||
panel = panel->next){
|
panel = panel->next){
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
if (view->transient.file_data.file == file){
|
if (view->transient.file_data.file == file){
|
||||||
Assert(view->transient.edit_pos != 0);
|
|
||||||
|
|
||||||
i32 cursor_pos = cursors[cursor_count++].pos;
|
i32 cursor_pos = cursors[cursor_count++].pos;
|
||||||
Full_Cursor new_cursor = file_compute_cursor(system, file, seek_pos(cursor_pos), 0);
|
Full_Cursor new_cursor = file_compute_cursor(system, file, seek_pos(cursor_pos), 0);
|
||||||
|
|
||||||
GUI_Scroll_Vars scroll = view->transient.edit_pos->scroll;
|
GUI_Scroll_Vars scroll = view->transient.edit_pos.scroll;
|
||||||
|
|
||||||
view->transient.edit_pos->mark = cursors[cursor_count++].pos;
|
view->transient.edit_pos.mark = cursors[cursor_count++].pos;
|
||||||
i32 new_scroll_i = cursors[cursor_count++].pos;
|
i32 new_scroll_i = cursors[cursor_count++].pos;
|
||||||
if (view->transient.edit_pos->scroll_i != new_scroll_i){
|
if (view->transient.edit_pos.scroll_i != new_scroll_i){
|
||||||
view->transient.edit_pos->scroll_i = new_scroll_i;
|
view->transient.edit_pos.scroll_i = new_scroll_i;
|
||||||
|
|
||||||
Full_Cursor temp_cursor = file_compute_cursor(system, file, seek_pos(view->transient.edit_pos->scroll_i), 0);
|
Full_Cursor temp_cursor = file_compute_cursor(system, file, seek_pos(view->transient.edit_pos.scroll_i), 0);
|
||||||
|
|
||||||
f32 y_offset = MOD(view->transient.edit_pos->scroll.scroll_y, view->transient.line_height);
|
f32 y_offset = MOD(view->transient.edit_pos.scroll.scroll_y, view->transient.line_height);
|
||||||
f32 y_position = temp_cursor.wrapped_y;
|
f32 y_position = temp_cursor.wrapped_y;
|
||||||
if (file->settings.unwrapped_lines){
|
if (file->settings.unwrapped_lines){
|
||||||
y_position = temp_cursor.unwrapped_y;
|
y_position = temp_cursor.unwrapped_y;
|
||||||
|
@ -185,8 +180,7 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_fix_markers__read_workspace_markers(&file_lifetime_object->workspace, file->id.id,
|
edit_fix_markers__read_workspace_markers(&file_lifetime_object->workspace, file_id, cursors, r_cursors, &cursor_count, &r_cursor_count);
|
||||||
cursors, r_cursors, &cursor_count, &r_cursor_count);
|
|
||||||
|
|
||||||
i32 key_count = file_lifetime_object->key_count;
|
i32 key_count = file_lifetime_object->key_count;
|
||||||
i32 key_index = 0;
|
i32 key_index = 0;
|
||||||
|
@ -196,8 +190,7 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
|
||||||
i32 count = clamp_top(lifetime_key_reference_per_node, key_count - key_index);
|
i32 count = clamp_top(lifetime_key_reference_per_node, key_count - key_index);
|
||||||
for (i32 i = 0; i < count; i += 1){
|
for (i32 i = 0; i < count; i += 1){
|
||||||
Lifetime_Key *key = key_node->keys[i];
|
Lifetime_Key *key = key_node->keys[i];
|
||||||
edit_fix_markers__read_workspace_markers(&key->dynamic_workspace, file->id.id,
|
edit_fix_markers__read_workspace_markers(&key->dynamic_workspace, file_id, cursors, r_cursors, &cursor_count, &r_cursor_count);
|
||||||
cursors, r_cursors, &cursor_count, &r_cursor_count);
|
|
||||||
}
|
}
|
||||||
key_index += count;
|
key_index += count;
|
||||||
}
|
}
|
||||||
|
@ -207,32 +200,36 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
|
edit_single__inner(System_Functions *system, Models *models, Editing_File *file, Edit_Spec spec, History_Mode history_mode){
|
||||||
Edit_Spec spec, History_Mode history_mode){
|
|
||||||
|
|
||||||
Mem_Options *mem = &models->mem;
|
Mem_Options *mem = &models->mem;
|
||||||
Editing_Layout *layout = &models->layout;
|
Editing_Layout *layout = &models->layout;
|
||||||
|
Heap *heap = &mem->heap;
|
||||||
|
Partition *part = &mem->part;
|
||||||
|
|
||||||
// NOTE(allen): fixing stuff beforewards????
|
// NOTE(allen): fixing stuff beforewards????
|
||||||
file_update_history_before_edit(mem, file, spec.step, spec.str, history_mode);
|
file_update_history_before_edit(mem, file, spec.step, spec.str, history_mode);
|
||||||
edit_pre_state_change(system, &mem->heap, models, file);
|
edit_pre_state_change(system, &mem->heap, models, file);
|
||||||
|
|
||||||
// NOTE(allen): actual text replacement
|
// NOTE(allen): expand spec, compute shift
|
||||||
i32 shift_amount = 0;
|
|
||||||
Heap *heap = &mem->heap;
|
|
||||||
Partition *part = &mem->part;
|
|
||||||
|
|
||||||
char *str = (char*)spec.str;
|
char *str = (char*)spec.str;
|
||||||
i32 start = spec.step.edit.start;
|
i32 start = spec.step.edit.start;
|
||||||
i32 end = spec.step.edit.end;
|
i32 end = spec.step.edit.end;
|
||||||
i32 str_len = spec.step.edit.len;
|
i32 str_len = spec.step.edit.len;
|
||||||
|
i32 shift_amount = buffer_replace_range_compute_shift(start, end, str_len);
|
||||||
|
|
||||||
|
// NOTE(allen): cursor fixing
|
||||||
|
Cursor_Fix_Descriptor desc = {};
|
||||||
|
desc.start = start;
|
||||||
|
desc.end = end;
|
||||||
|
desc.shift_amount = shift_amount;
|
||||||
|
edit_fix_markers(system, models, file, layout, desc);
|
||||||
|
|
||||||
|
// NOTE(allen): actual text replacement
|
||||||
i32 scratch_size = partition_remaining(part);
|
i32 scratch_size = partition_remaining(part);
|
||||||
|
|
||||||
Assert(scratch_size > 0);
|
Assert(scratch_size > 0);
|
||||||
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, part->base + part->pos, scratch_size, &request_amount)){
|
for (;buffer_replace_range(&file->state.buffer, start, end, str, str_len, shift_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 = heap_allocate(heap, request_amount);
|
new_data = heap_allocate(heap, request_amount);
|
||||||
|
@ -243,15 +240,7 @@ edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): token fixing
|
// NOTE(allen): line meta data
|
||||||
if (file->settings.tokens_exist){
|
|
||||||
file_relex(system, models, file, start, end, shift_amount);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
file_mark_edit_finished(&models->working_set, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE(allen): meta data
|
|
||||||
Gap_Buffer *buffer = &file->state.buffer;
|
Gap_Buffer *buffer = &file->state.buffer;
|
||||||
i32 line_start = buffer_get_line_number(&file->state.buffer, start);
|
i32 line_start = buffer_get_line_number(&file->state.buffer, start);
|
||||||
i32 line_end = buffer_get_line_number(&file->state.buffer, end);
|
i32 line_end = buffer_get_line_number(&file->state.buffer, end);
|
||||||
|
@ -268,14 +257,23 @@ edit_single__inner(System_Functions *system, Models *models, Editing_File *file,
|
||||||
file_allocate_character_starts_as_needed(heap, file);
|
file_allocate_character_starts_as_needed(heap, file);
|
||||||
buffer_remeasure_character_starts(system, font, buffer, line_start, line_end, line_shift, file->state.character_starts, 0, file->settings.virtual_white);
|
buffer_remeasure_character_starts(system, font, buffer, line_start, line_end, line_shift, file->state.character_starts, 0, file->settings.virtual_white);
|
||||||
|
|
||||||
file_measure_wraps(system, &models->mem, file, font);
|
// NOTE(allen): token fixing
|
||||||
|
if (file->settings.tokens_exist){
|
||||||
|
file_relex(system, models, file, start, end, shift_amount);
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE(allen): cursor fixing
|
// NOTE(allen): mark edit finished
|
||||||
Cursor_Fix_Descriptor desc = {};
|
if (file->settings.tokens_exist){
|
||||||
desc.start = start;
|
if (file->settings.virtual_white){
|
||||||
desc.end = end;
|
file_mark_edit_finished(&models->working_set, file);
|
||||||
desc.shift_amount = shift_amount;
|
}
|
||||||
edit_fix_markers(system, models, file, layout, desc);
|
}
|
||||||
|
else{
|
||||||
|
file_mark_edit_finished(&models->working_set, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE(allen): wrap meta data
|
||||||
|
file_measure_wraps(system, &models->mem, file, font);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
@ -317,9 +315,7 @@ edit_compute_batch_spec(Heap *heap,
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
edit_batch(System_Functions *system, Models *models, Editing_File *file,
|
edit_batch(System_Functions *system, Models *models, Editing_File *file, Edit_Spec spec, History_Mode history_mode, Buffer_Batch_Edit_Type batch_type){
|
||||||
Edit_Spec spec, History_Mode history_mode, Buffer_Batch_Edit_Type batch_type){
|
|
||||||
|
|
||||||
Mem_Options *mem = &models->mem;
|
Mem_Options *mem = &models->mem;
|
||||||
Heap *heap = &mem->heap;
|
Heap *heap = &mem->heap;
|
||||||
Partition *part = &mem->part;
|
Partition *part = &mem->part;
|
||||||
|
@ -330,20 +326,25 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file,
|
||||||
file_update_history_before_edit(mem, file, spec.step, 0, history_mode);
|
file_update_history_before_edit(mem, file, spec.step, 0, history_mode);
|
||||||
edit_pre_state_change(system, &mem->heap, models, file);
|
edit_pre_state_change(system, &mem->heap, models, file);
|
||||||
|
|
||||||
// NOTE(allen): actual text replacement
|
// NOTE(allen): expand spec
|
||||||
u8 *str_base = file->state.undo.children.strings;
|
u8 *str_base = file->state.undo.children.strings;
|
||||||
i32 batch_size = spec.step.child_count;
|
i32 batch_size = spec.step.child_count;
|
||||||
Buffer_Edit *batch = file->state.undo.children.edits + spec.step.first_child;
|
Buffer_Edit *batch = file->state.undo.children.edits + spec.step.first_child;
|
||||||
|
|
||||||
Assert(spec.step.first_child < file->state.undo.children.edit_count);
|
Assert(spec.step.first_child < file->state.undo.children.edit_count);
|
||||||
Assert(batch_size >= 0);
|
Assert(batch_size >= 0);
|
||||||
|
|
||||||
|
// NOTE(allen): cursor fixing
|
||||||
|
Cursor_Fix_Descriptor desc = {};
|
||||||
|
desc.is_batch = true;
|
||||||
|
desc.batch = batch;
|
||||||
|
desc.batch_size = batch_size;
|
||||||
|
edit_fix_markers(system, models, file, layout, desc);
|
||||||
|
|
||||||
|
// NOTE(allen): actual text replacement
|
||||||
i32 scratch_size = partition_remaining(part);
|
i32 scratch_size = partition_remaining(part);
|
||||||
Buffer_Batch_State state = {};
|
Buffer_Batch_State state = {};
|
||||||
i32 request_amount = 0;
|
i32 request_amount = 0;
|
||||||
while (buffer_batch_edit_step(&state, &file->state.buffer, batch,
|
for (;buffer_batch_edit_step(&state, &file->state.buffer, batch, (char*)str_base, batch_size, part->base + part->pos, scratch_size, &request_amount);){
|
||||||
(char*)str_base, batch_size, 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 = heap_allocate(heap, request_amount);
|
new_data = heap_allocate(heap, request_amount);
|
||||||
|
@ -353,9 +354,18 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file,
|
||||||
heap_free(heap, old_data);
|
heap_free(heap, old_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 shift_total = state.shift_total;
|
i32 shift_total = state.shift_total;
|
||||||
|
|
||||||
|
// NOTE(allen): line meta data
|
||||||
|
// TODO(allen): Let's try to switch to remeasuring here moron!
|
||||||
|
file_measure_starts(heap, &file->state.buffer);
|
||||||
|
|
||||||
|
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
|
||||||
|
Assert(font.valid);
|
||||||
|
|
||||||
|
file_allocate_character_starts_as_needed(heap, file);
|
||||||
|
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
|
||||||
|
|
||||||
// NOTE(allen): token fixing
|
// NOTE(allen): token fixing
|
||||||
switch (batch_type){
|
switch (batch_type){
|
||||||
case BatchEdit_Normal:
|
case BatchEdit_Normal:
|
||||||
|
@ -404,29 +414,18 @@ edit_batch(System_Functions *system, Models *models, Editing_File *file,
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(allen): Let's try to switch to remeasuring here moron!
|
// NOTE(allen): mark edit finished
|
||||||
// We'll need to get the total shift from the actual batch edit state
|
if (file->settings.tokens_exist){
|
||||||
// instead of from the cursor fixing. The only reason we're getting
|
if (file->settings.virtual_white){
|
||||||
// it from cursor fixing is because you're a lazy asshole.
|
file_mark_edit_finished(&models->working_set, file);
|
||||||
|
}
|
||||||
// NOTE(allen): meta data
|
}
|
||||||
file_measure_starts(heap, &file->state.buffer);
|
else{
|
||||||
|
file_mark_edit_finished(&models->working_set, file);
|
||||||
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
|
}
|
||||||
Assert(font.valid);
|
|
||||||
|
|
||||||
// TODO(allen): write the remeasurement version
|
|
||||||
file_allocate_character_starts_as_needed(heap, file);
|
|
||||||
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
|
|
||||||
|
|
||||||
|
// NOTE(allen): wrap meta data
|
||||||
file_measure_wraps(system, &models->mem, file, font);
|
file_measure_wraps(system, &models->mem, file, font);
|
||||||
|
|
||||||
// NOTE(allen): cursor fixing
|
|
||||||
Cursor_Fix_Descriptor desc = {};
|
|
||||||
desc.is_batch = true;
|
|
||||||
desc.batch = batch;
|
|
||||||
desc.batch_size = batch_size;
|
|
||||||
edit_fix_markers(system, models, file, layout, desc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
@ -463,12 +462,11 @@ edit_clear(System_Functions *system, Models *models, Editing_File *file){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (no_views_see_file){
|
if (no_views_see_file){
|
||||||
memset(file->state.edit_pos_space, 0, sizeof(file->state.edit_pos_space));
|
block_zero(file->state.edit_pos_stack, sizeof(file->state.edit_pos_stack));
|
||||||
file->state.edit_poss_count = 0;
|
file->state.edit_pos_stack_top = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_single(system, models, file,
|
edit_single(system, models, file, 0, buffer_size(&file->state.buffer), 0, 0);
|
||||||
0, buffer_size(&file->state.buffer), 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
@ -481,12 +479,11 @@ edit_historical(System_Functions *system, Models *models, Editing_File *file, Vi
|
||||||
spec.step.edit.str_start = 0;
|
spec.step.edit.str_start = 0;
|
||||||
spec.str = stack->strings + step.edit.str_start;
|
spec.str = stack->strings + step.edit.str_start;
|
||||||
|
|
||||||
edit_single__inner(system, models, file,
|
edit_single__inner(system, models, file, spec, history_mode);
|
||||||
spec, history_mode);
|
|
||||||
|
|
||||||
if (view != 0){
|
if (view != 0){
|
||||||
view_cursor_move(system, view, step.edit.start + step.edit.len);
|
view_cursor_move(system, view, step.edit.start + step.edit.len);
|
||||||
view->transient.edit_pos->mark = view->transient.edit_pos->cursor.pos;
|
view->transient.edit_pos.mark = view->transient.edit_pos.cursor.pos;
|
||||||
|
|
||||||
Style *style = &models->styles.styles[0];
|
Style *style = &models->styles.styles[0];
|
||||||
view_post_paste_effect(view, 0.333f, step.edit.start, step.edit.len, style->theme.colors[Stag_Undo]);
|
view_post_paste_effect(view, 0.333f, step.edit.start, step.edit.len, style->theme.colors[Stag_Undo]);
|
||||||
|
|
104
4ed_file.cpp
104
4ed_file.cpp
|
@ -36,102 +36,22 @@ edit_pos_set_scroll(File_Edit_Positions *edit_pos, GUI_Scroll_Vars scroll){
|
||||||
edit_pos->last_set_type = EditPos_ScrollSet;
|
edit_pos->last_set_type = EditPos_ScrollSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal i32
|
internal void
|
||||||
edit_pos_get_index(Editing_File *file, File_Edit_Positions *edit_pos){
|
edit_pos_push(Editing_File *file, File_Edit_Positions edit_pos){
|
||||||
i32 edit_pos_index = -1;
|
if (file->state.edit_pos_stack_top + 1 < ArrayCount(file->state.edit_pos_stack)){
|
||||||
|
file->state.edit_pos_stack_top += 1;
|
||||||
i32 count = file->state.edit_poss_count;
|
file->state.edit_pos_stack[file->state.edit_pos_stack_top] = edit_pos;
|
||||||
File_Edit_Positions **edit_poss = file->state.edit_poss;
|
|
||||||
for (i32 i = 0; i < count; ++i){
|
|
||||||
if (edit_poss[i] == edit_pos){
|
|
||||||
edit_pos_index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(edit_pos_index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal b32
|
internal File_Edit_Positions
|
||||||
edit_pos_move_to_front(Editing_File *file, File_Edit_Positions *edit_pos){
|
edit_pos_pop(Editing_File *file){
|
||||||
b32 result = false;
|
File_Edit_Positions edit_pos = {};
|
||||||
|
if (file->state.edit_pos_stack_top >= 0){
|
||||||
if (file && edit_pos){
|
edit_pos = file->state.edit_pos_stack[file->state.edit_pos_stack_top];
|
||||||
i32 edit_pos_index = edit_pos_get_index(file, edit_pos);
|
file->state.edit_pos_stack_top -= 1;
|
||||||
Assert(edit_pos_index != -1);
|
|
||||||
|
|
||||||
File_Edit_Positions **edit_poss = file->state.edit_poss;
|
|
||||||
|
|
||||||
memmove(edit_poss + 1, edit_poss, edit_pos_index*sizeof(*edit_poss));
|
|
||||||
|
|
||||||
edit_poss[0] = edit_pos;
|
|
||||||
result = true;
|
|
||||||
}
|
}
|
||||||
|
return(edit_pos);
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal b32
|
|
||||||
edit_pos_unset(Editing_File *file, File_Edit_Positions *edit_pos){
|
|
||||||
b32 result = false;
|
|
||||||
|
|
||||||
if (file && edit_pos){
|
|
||||||
i32 edit_pos_index = edit_pos_get_index(file, edit_pos);
|
|
||||||
Assert(edit_pos_index != -1);
|
|
||||||
|
|
||||||
i32 count = file->state.edit_poss_count;
|
|
||||||
File_Edit_Positions **edit_poss = file->state.edit_poss;
|
|
||||||
|
|
||||||
memmove(edit_poss + edit_pos_index,
|
|
||||||
edit_poss + edit_pos_index + 1,
|
|
||||||
(count - edit_pos_index - 1)*sizeof(*edit_poss));
|
|
||||||
|
|
||||||
edit_pos->in_view = false;
|
|
||||||
|
|
||||||
if (file->state.edit_poss_count > 1){
|
|
||||||
file->state.edit_poss_count -= 1;
|
|
||||||
}
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal File_Edit_Positions*
|
|
||||||
edit_pos_get_new(Editing_File *file, i32 index){
|
|
||||||
File_Edit_Positions *result = 0;
|
|
||||||
|
|
||||||
if (file && 0 <= index && index < 16){
|
|
||||||
result = file->state.edit_pos_space + index;
|
|
||||||
i32 edit_pos_index = edit_pos_get_index(file, result);
|
|
||||||
|
|
||||||
if (edit_pos_index == -1){
|
|
||||||
File_Edit_Positions **edit_poss = file->state.edit_poss;
|
|
||||||
i32 count = file->state.edit_poss_count;
|
|
||||||
|
|
||||||
if (count > 0){
|
|
||||||
if (edit_poss[0]->in_view){
|
|
||||||
memcpy(result, edit_poss[0], sizeof(*result));
|
|
||||||
memmove(edit_poss+1, edit_poss, sizeof(*edit_poss)*count);
|
|
||||||
file->state.edit_poss_count = count + 1;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Assert(count == 1);
|
|
||||||
memcpy(result, edit_poss[0], sizeof(*result));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
memset(result, 0, sizeof(*result));
|
|
||||||
file->state.edit_poss_count = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
edit_poss[0] = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
result->in_view = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
|
@ -88,9 +88,8 @@ struct Editing_File_State{
|
||||||
Dirty_State dirty;
|
Dirty_State dirty;
|
||||||
u32 ignore_behind_os;
|
u32 ignore_behind_os;
|
||||||
|
|
||||||
File_Edit_Positions edit_pos_space[16];
|
File_Edit_Positions edit_pos_stack[16];
|
||||||
File_Edit_Positions *edit_poss[16];
|
i32 edit_pos_stack_top;
|
||||||
i32 edit_poss_count;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Editing_File_Name{
|
struct Editing_File_Name{
|
||||||
|
|
|
@ -152,7 +152,7 @@ file_kill_tokens(System_Functions *system, Heap *heap, Editing_File *file){
|
||||||
if (file->state.token_array.tokens){
|
if (file->state.token_array.tokens){
|
||||||
heap_free(heap, file->state.token_array.tokens);
|
heap_free(heap, file->state.token_array.tokens);
|
||||||
}
|
}
|
||||||
file->state.tokens_complete = 0;
|
file->state.tokens_complete = false;
|
||||||
file->state.token_array = null_cpp_token_array;
|
file->state.token_array = null_cpp_token_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ file_relex_parallel(System_Functions *system, Models *models, Editing_File *file
|
||||||
|
|
||||||
file->state.still_lexing = true;
|
file->state.still_lexing = true;
|
||||||
|
|
||||||
Job_Data job;
|
Job_Data job = {};
|
||||||
job.callback = job_full_lex;
|
job.callback = job_full_lex;
|
||||||
job.data[0] = file;
|
job.data[0] = file;
|
||||||
job.data[1] = heap;
|
job.data[1] = heap;
|
||||||
|
@ -487,11 +487,10 @@ file_relex_serial(System_Functions *system, Models *models, Editing_File *file,
|
||||||
}
|
}
|
||||||
|
|
||||||
cpp_relex_complete(&state, array, &relex_array);
|
cpp_relex_complete(&state, array, &relex_array);
|
||||||
file_mark_edit_finished(&models->working_set, file);
|
|
||||||
|
|
||||||
end_temp_memory(temp);
|
end_temp_memory(temp);
|
||||||
|
|
||||||
return(1);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
|
141
4ed_view.cpp
141
4ed_view.cpp
|
@ -85,13 +85,10 @@ view_get_cursor_xy(View *view){
|
||||||
if (view->transient.file_data.show_temp_highlight){
|
if (view->transient.file_data.show_temp_highlight){
|
||||||
cursor = &view->transient.file_data.temp_highlight;
|
cursor = &view->transient.file_data.temp_highlight;
|
||||||
}
|
}
|
||||||
else if (view->transient.edit_pos){
|
else{
|
||||||
cursor = &view->transient.edit_pos->cursor;
|
cursor = &view->transient.edit_pos.cursor;
|
||||||
}
|
}
|
||||||
Assert(cursor != 0);
|
Vec2 result = V2(cursor->wrapped_x, cursor->wrapped_y);
|
||||||
Vec2 result;
|
|
||||||
result.x = cursor->wrapped_x;
|
|
||||||
result.y = cursor->wrapped_y;
|
|
||||||
if (view->transient.file_data.file->settings.unwrapped_lines){
|
if (view->transient.file_data.file->settings.unwrapped_lines){
|
||||||
result.x = cursor->unwrapped_x;
|
result.x = cursor->unwrapped_x;
|
||||||
result.y = cursor->unwrapped_y;
|
result.y = cursor->unwrapped_y;
|
||||||
|
@ -214,40 +211,35 @@ view_move_view_to_cursor(View *view, GUI_Scroll_Vars *scroll, b32 center_view){
|
||||||
|
|
||||||
internal b32
|
internal b32
|
||||||
view_move_cursor_to_view(System_Functions *system, View *view, GUI_Scroll_Vars scroll, Full_Cursor *cursor, f32 preferred_x){
|
view_move_cursor_to_view(System_Functions *system, View *view, GUI_Scroll_Vars scroll, Full_Cursor *cursor, f32 preferred_x){
|
||||||
b32 result = false;
|
i32 line_height = view->transient.line_height;
|
||||||
|
f32 old_cursor_y = cursor->wrapped_y;
|
||||||
|
Editing_File *file = view->transient.file_data.file;
|
||||||
|
if (file->settings.unwrapped_lines){
|
||||||
|
old_cursor_y = cursor->unwrapped_y;
|
||||||
|
}
|
||||||
|
f32 cursor_y = old_cursor_y;
|
||||||
|
f32 target_y = scroll.target_y + view->transient.widget_height;
|
||||||
|
|
||||||
if (view->transient.edit_pos){
|
Cursor_Limits limits = view_cursor_limits(view);
|
||||||
i32 line_height = view->transient.line_height;
|
|
||||||
f32 old_cursor_y = cursor->wrapped_y;
|
if (cursor_y > target_y + limits.max){
|
||||||
Editing_File *file = view->transient.file_data.file;
|
cursor_y = target_y + limits.max;
|
||||||
if (file->settings.unwrapped_lines){
|
}
|
||||||
old_cursor_y = cursor->unwrapped_y;
|
if (target_y != 0 && cursor_y < target_y + limits.min){
|
||||||
|
cursor_y = target_y + limits.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
b32 result = false;
|
||||||
|
if (cursor_y != old_cursor_y){
|
||||||
|
if (cursor_y > old_cursor_y){
|
||||||
|
cursor_y += line_height;
|
||||||
}
|
}
|
||||||
f32 cursor_y = old_cursor_y;
|
else{
|
||||||
f32 target_y = scroll.target_y + view->transient.widget_height;
|
cursor_y -= line_height;
|
||||||
|
|
||||||
Cursor_Limits limits = view_cursor_limits(view);
|
|
||||||
|
|
||||||
if (cursor_y > target_y + limits.max){
|
|
||||||
cursor_y = target_y + limits.max;
|
|
||||||
}
|
|
||||||
if (target_y != 0 && cursor_y < target_y + limits.min){
|
|
||||||
cursor_y = target_y + limits.min;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cursor_y != old_cursor_y){
|
|
||||||
if (cursor_y > old_cursor_y){
|
|
||||||
cursor_y += line_height;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
cursor_y -= line_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
Buffer_Seek seek = seek_xy(preferred_x, cursor_y, false, file->settings.unwrapped_lines);
|
|
||||||
*cursor = file_compute_cursor(system, file, seek, false);
|
|
||||||
|
|
||||||
result = true;
|
|
||||||
}
|
}
|
||||||
|
Buffer_Seek seek = seek_xy(preferred_x, cursor_y, false, file->settings.unwrapped_lines);
|
||||||
|
*cursor = file_compute_cursor(system, file, seek, false);
|
||||||
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
|
@ -255,54 +247,44 @@ view_move_cursor_to_view(System_Functions *system, View *view, GUI_Scroll_Vars s
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_set_cursor(View *view, Full_Cursor cursor, b32 set_preferred_x, b32 unwrapped_lines){
|
view_set_cursor(View *view, Full_Cursor cursor, b32 set_preferred_x, b32 unwrapped_lines){
|
||||||
if (edit_pos_move_to_front(view->transient.file_data.file, view->transient.edit_pos)){
|
edit_pos_set_cursor(&view->transient.edit_pos, cursor, set_preferred_x, unwrapped_lines);
|
||||||
edit_pos_set_cursor(view->transient.edit_pos, cursor, set_preferred_x, unwrapped_lines);
|
GUI_Scroll_Vars scroll = view->transient.edit_pos.scroll;
|
||||||
GUI_Scroll_Vars scroll = view->transient.edit_pos->scroll;
|
if (view_move_view_to_cursor(view, &scroll, 0)){
|
||||||
if (view_move_view_to_cursor(view, &scroll, 0)){
|
view->transient.edit_pos.scroll = scroll;
|
||||||
view->transient.edit_pos->scroll = scroll;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_set_scroll(System_Functions *system, View *view, GUI_Scroll_Vars scroll){
|
view_set_scroll(System_Functions *system, View *view, GUI_Scroll_Vars scroll){
|
||||||
if (edit_pos_move_to_front(view->transient.file_data.file, view->transient.edit_pos)){
|
edit_pos_set_scroll(&view->transient.edit_pos, scroll);
|
||||||
edit_pos_set_scroll(view->transient.edit_pos, scroll);
|
Full_Cursor cursor = view->transient.edit_pos.cursor;
|
||||||
Full_Cursor cursor = view->transient.edit_pos->cursor;
|
if (view_move_cursor_to_view(system, view, view->transient.edit_pos.scroll, &cursor, view->transient.edit_pos.preferred_x)){
|
||||||
if (view_move_cursor_to_view(system, view, view->transient.edit_pos->scroll, &cursor, view->transient.edit_pos->preferred_x)){
|
view->transient.edit_pos.cursor = cursor;
|
||||||
view->transient.edit_pos->cursor = cursor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_set_cursor_and_scroll(View *view, Full_Cursor cursor, b32 set_preferred_x, b32 unwrapped_lines, GUI_Scroll_Vars scroll){
|
view_set_cursor_and_scroll(View *view, Full_Cursor cursor, b32 set_preferred_x, b32 unwrapped_lines, GUI_Scroll_Vars scroll){
|
||||||
File_Edit_Positions *edit_pos = view->transient.edit_pos;
|
File_Edit_Positions *edit_pos = &view->transient.edit_pos;
|
||||||
if (edit_pos_move_to_front(view->transient.file_data.file, edit_pos)){
|
edit_pos_set_cursor(edit_pos, cursor, set_preferred_x, unwrapped_lines);
|
||||||
edit_pos_set_cursor(edit_pos, cursor, set_preferred_x, unwrapped_lines);
|
edit_pos_set_scroll(edit_pos, scroll);
|
||||||
edit_pos_set_scroll(edit_pos, scroll);
|
edit_pos->last_set_type = EditPos_None;
|
||||||
edit_pos->last_set_type = EditPos_None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Relative_Scrolling
|
internal Relative_Scrolling
|
||||||
view_get_relative_scrolling(View *view){
|
view_get_relative_scrolling(View *view){
|
||||||
|
Vec2 cursor = view_get_cursor_xy(view);
|
||||||
Relative_Scrolling result = {};
|
Relative_Scrolling result = {};
|
||||||
if (view->transient.edit_pos != 0){
|
result.scroll_y = cursor.y - view->transient.edit_pos.scroll.scroll_y;
|
||||||
Vec2 cursor = view_get_cursor_xy(view);
|
result.target_y = cursor.y - view->transient.edit_pos.scroll.target_y;
|
||||||
result.scroll_y = cursor.y - view->transient.edit_pos->scroll.scroll_y;
|
|
||||||
result.target_y = cursor.y - view->transient.edit_pos->scroll.target_y;
|
|
||||||
}
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
view_set_relative_scrolling(View *view, Relative_Scrolling scrolling){
|
view_set_relative_scrolling(View *view, Relative_Scrolling scrolling){
|
||||||
Vec2 cursor = view_get_cursor_xy(view);
|
Vec2 cursor = view_get_cursor_xy(view);
|
||||||
if (view->transient.edit_pos != 0){
|
view->transient.edit_pos.scroll.scroll_y = cursor.y - scrolling.scroll_y;
|
||||||
view->transient.edit_pos->scroll.scroll_y = cursor.y - scrolling.scroll_y;
|
view->transient.edit_pos.scroll.target_y = round32(clamp_bottom(0.f, cursor.y - scrolling.target_y));
|
||||||
view->transient.edit_pos->scroll.target_y = round32(clamp_bottom(0.f, cursor.y - scrolling.target_y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
@ -340,27 +322,21 @@ internal void
|
||||||
view_set_file(System_Functions *system, Models *models, View *view, Editing_File *file){
|
view_set_file(System_Functions *system, Models *models, View *view, Editing_File *file){
|
||||||
Assert(file != 0);
|
Assert(file != 0);
|
||||||
|
|
||||||
if (view->transient.file_data.file != 0){
|
Editing_File *old_file = view->transient.file_data.file;
|
||||||
file_touch(&models->working_set, view->transient.file_data.file);
|
if (old_file != 0){
|
||||||
|
file_touch(&models->working_set, old_file);
|
||||||
|
edit_pos_push(old_file, view->transient.edit_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
File_Edit_Positions *edit_pos = view->transient.edit_pos;
|
block_zero(&view->transient.file_data, sizeof(view->transient.file_data));
|
||||||
|
|
||||||
if (edit_pos != 0){
|
|
||||||
edit_pos_unset(view->transient.file_data.file, edit_pos);
|
|
||||||
edit_pos = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&view->transient.file_data, 0, sizeof(view->transient.file_data));
|
|
||||||
view->transient.file_data.file = file;
|
view->transient.file_data.file = file;
|
||||||
|
|
||||||
edit_pos = edit_pos_get_new(file, view->persistent.id);
|
view->transient.edit_pos = edit_pos_pop(file);
|
||||||
view->transient.edit_pos = edit_pos;
|
|
||||||
|
|
||||||
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
|
Font_Pointers font = system->font.get_pointers_by_id(file->settings.font_id);
|
||||||
view->transient.line_height = font.metrics->height;
|
view->transient.line_height = font.metrics->height;
|
||||||
|
|
||||||
if (edit_pos->cursor.line == 0){
|
if (view->transient.edit_pos.cursor.line == 0){
|
||||||
view_cursor_move(system, view, 0);
|
view_cursor_move(system, view, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,8 +368,7 @@ adjust_views_looking_at_file_to_new_cursor(System_Functions *system, Models *mod
|
||||||
View *view = panel->view;
|
View *view = panel->view;
|
||||||
if (view->transient.file_data.file == file){
|
if (view->transient.file_data.file == file){
|
||||||
if (!view->transient.file_data.show_temp_highlight){
|
if (!view->transient.file_data.show_temp_highlight){
|
||||||
Assert(view->transient.edit_pos != 0);
|
i32 pos = view->transient.edit_pos.cursor.pos;
|
||||||
i32 pos = view->transient.edit_pos->cursor.pos;
|
|
||||||
Full_Cursor cursor = file_compute_cursor(system, file, seek_pos(pos), 0);
|
Full_Cursor cursor = file_compute_cursor(system, file, seek_pos(pos), 0);
|
||||||
view_set_cursor(view, cursor, 1, file->settings.unwrapped_lines);
|
view_set_cursor(view, cursor, 1, file->settings.unwrapped_lines);
|
||||||
}
|
}
|
||||||
|
@ -813,7 +788,6 @@ render_loaded_file_in_view__inner(Models *models, Render_Target *target, View *v
|
||||||
Assert(file != 0);
|
Assert(file != 0);
|
||||||
Assert(!file->is_dummy);
|
Assert(!file->is_dummy);
|
||||||
Assert(buffer_good(&file->state.buffer));
|
Assert(buffer_good(&file->state.buffer));
|
||||||
Assert(view->transient.edit_pos != 0);
|
|
||||||
|
|
||||||
b32 tokens_use = file->state.tokens_complete && (file->state.token_array.count > 0);
|
b32 tokens_use = file->state.tokens_complete && (file->state.token_array.count > 0);
|
||||||
Cpp_Token_Array token_array = file->state.token_array;
|
Cpp_Token_Array token_array = file->state.token_array;
|
||||||
|
@ -1219,7 +1193,6 @@ render_loaded_file_in_view(System_Functions *system, View *view, Models *models,
|
||||||
Assert(file != 0);
|
Assert(file != 0);
|
||||||
Assert(!file->is_dummy);
|
Assert(!file->is_dummy);
|
||||||
Assert(buffer_good(&file->state.buffer));
|
Assert(buffer_good(&file->state.buffer));
|
||||||
Assert(view->transient.edit_pos != 0);
|
|
||||||
|
|
||||||
Partition *part = &models->mem.part;
|
Partition *part = &models->mem.part;
|
||||||
Temp_Memory temp = begin_temp_memory(part);
|
Temp_Memory temp = begin_temp_memory(part);
|
||||||
|
@ -1235,8 +1208,8 @@ render_loaded_file_in_view(System_Functions *system, View *view, Models *models,
|
||||||
Face_ID font_id = file->settings.font_id;
|
Face_ID font_id = file->settings.font_id;
|
||||||
Font_Pointers font = system->font.get_pointers_by_id(font_id);
|
Font_Pointers font = system->font.get_pointers_by_id(font_id);
|
||||||
|
|
||||||
f32 scroll_x = view->transient.edit_pos->scroll.scroll_x;
|
f32 scroll_x = view->transient.edit_pos.scroll.scroll_x;
|
||||||
f32 scroll_y = view->transient.edit_pos->scroll.scroll_y;
|
f32 scroll_y = view->transient.edit_pos.scroll.scroll_y;
|
||||||
|
|
||||||
// NOTE(allen): For now we will temporarily adjust scroll_y to try
|
// NOTE(allen): For now we will temporarily adjust scroll_y to try
|
||||||
// to prevent the view moving around until floating sections are added
|
// to prevent the view moving around until floating sections are added
|
||||||
|
@ -1251,7 +1224,7 @@ render_loaded_file_in_view(System_Functions *system, View *view, Models *models,
|
||||||
render_cursor = file_compute_cursor(system, file, seek_unwrapped_xy(0, scroll_y, 0), true);
|
render_cursor = file_compute_cursor(system, file, seek_unwrapped_xy(0, scroll_y, 0), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
view->transient.edit_pos->scroll_i = render_cursor.pos;
|
view->transient.edit_pos.scroll_i = render_cursor.pos;
|
||||||
|
|
||||||
i32 item_count = 0;
|
i32 item_count = 0;
|
||||||
i32 end_pos = 0;
|
i32 end_pos = 0;
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct View_Transient{
|
||||||
i32_Rect file_region;
|
i32_Rect file_region;
|
||||||
|
|
||||||
i32_Rect scroll_region;
|
i32_Rect scroll_region;
|
||||||
File_Edit_Positions *edit_pos;
|
File_Edit_Positions edit_pos;
|
||||||
|
|
||||||
b32 ui_mode;
|
b32 ui_mode;
|
||||||
UI_Quit_Function_Type *ui_quit;
|
UI_Quit_Function_Type *ui_quit;
|
||||||
|
|
|
@ -186,9 +186,9 @@ draw_file_bar(System_Functions *system, Render_Target *target, View *view, Model
|
||||||
char bar_space[526];
|
char bar_space[526];
|
||||||
String bar_text = make_fixed_width_string(bar_space);
|
String bar_text = make_fixed_width_string(bar_space);
|
||||||
append_ss (&bar_text, lit(" L#"));
|
append_ss (&bar_text, lit(" L#"));
|
||||||
append_int_to_str(&bar_text, view->transient.edit_pos->cursor.line);
|
append_int_to_str(&bar_text, view->transient.edit_pos.cursor.line);
|
||||||
append_ss (&bar_text, lit(" C#"));
|
append_ss (&bar_text, lit(" C#"));
|
||||||
append_int_to_str(&bar_text, view->transient.edit_pos->cursor.character);
|
append_int_to_str(&bar_text, view->transient.edit_pos.cursor.character);
|
||||||
|
|
||||||
append_ss(&bar_text, lit(" -"));
|
append_ss(&bar_text, lit(" -"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue