Touch up to the edit position stack

master
Allen Webster 2019-02-09 14:48:53 -08:00
parent a19492dfd7
commit 4bdc1e6d21
10 changed files with 109 additions and 187 deletions

24
4ed.cpp
View File

@ -82,7 +82,9 @@ 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; File_Edit_Positions edit_pos = view_get_edit_pos(view);
edit_pos.mark = edit_pos.cursor.pos;
view_set_edit_pos(view, edit_pos);
} }
} }
@ -1292,8 +1294,9 @@ App_Step_Sig(app_step){
GUI_Scroll_Vars *scroll_vars = 0; GUI_Scroll_Vars *scroll_vars = 0;
i32 max_y = 0; i32 max_y = 0;
b32 file_scroll = false; b32 file_scroll = false;
File_Edit_Positions edit_pos = view_get_edit_pos(view);
if (!view->transient.ui_mode){ if (!view->transient.ui_mode){
scroll_vars = &view->transient.edit_pos.scroll; scroll_vars = &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;
} }
@ -1311,6 +1314,11 @@ App_Step_Sig(app_step){
app_result.animating = true; app_result.animating = true;
} }
if (file_scroll){
// TODO(allen): do(eliminate view_set_edit_pos if it is redundant)
view_set_edit_pos(view, edit_pos);
}
if (memcmp(scroll_vars, &ip_result.scroll, sizeof(*scroll_vars)) != 0){ if (memcmp(scroll_vars, &ip_result.scroll, sizeof(*scroll_vars)) != 0){
if (file_scroll){ if (file_scroll){
view_set_scroll(system, view, ip_result.scroll); view_set_scroll(system, view, ip_result.scroll);
@ -1328,9 +1336,10 @@ App_Step_Sig(app_step){
panel != 0; panel != 0;
panel = layout_get_next_open_panel(layout, panel)){ panel = layout_get_next_open_panel(layout, panel)){
View *view = panel->view; View *view = panel->view;
GUI_Scroll_Vars *scroll_vars = &view->transient.edit_pos.scroll; File_Edit_Positions edit_pos = view_get_edit_pos(view);
scroll_vars->scroll_x = (f32)scroll_vars->target_x; edit_pos.scroll.scroll_x = (f32)edit_pos.scroll.target_x;
scroll_vars->scroll_y = (f32)scroll_vars->target_y; edit_pos.scroll.scroll_y = (f32)edit_pos.scroll.target_y;
view_set_edit_pos(view, edit_pos);
} }
} }
@ -1418,11 +1427,14 @@ 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; File_Edit_Positions edit_pos = view_get_edit_pos(view);
GUI_Scroll_Vars *scroll_vars = &edit_pos.scroll;
b32 active = (panel == active_panel); b32 active = (panel == active_panel);
do_render_file_view(system, view, models, scroll_vars, active_view, inner, active, target); do_render_file_view(system, view, models, scroll_vars, active_view, inner, active, target);
view_set_edit_pos(view, edit_pos);
u32 margin_color = 0; u32 margin_color = 0;
if (active){ if (active){
margin_color = style->theme.colors[Stag_Margin_Active]; margin_color = style->theme.colors[Stag_Margin_Active];

View File

@ -66,9 +66,12 @@ 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); File_Edit_Positions edit_pos = view_get_edit_pos(vptr);
view->cursor = vptr->transient.edit_pos.cursor;
view->preferred_x = vptr->transient.edit_pos.preferred_x; view->mark = file_compute_cursor(system, data->file, seek_pos(edit_pos.mark), 0);
view->cursor = edit_pos.cursor;
view->preferred_x = edit_pos.preferred_x;
view->view_region = vptr->transient.panel->rect_inner; view->view_region = vptr->transient.panel->rect_inner;
view->file_region = vptr->transient.file_region; view->file_region = vptr->transient.file_region;
@ -76,7 +79,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 = edit_pos.scroll;
} }
} }
} }
@ -1408,9 +1411,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_positions[vptr_count] = view_it->transient.edit_pos; File_Edit_Positions edit_pos = view_get_edit_pos(view_it);
line_numbers[vptr_count] = view_it->transient.edit_pos.cursor.line; edit_positions[vptr_count] = edit_pos;
column_numbers[vptr_count] = view_it->transient.edit_pos.cursor.character; line_numbers[vptr_count] = edit_pos.cursor.line;
column_numbers[vptr_count] = edit_pos.cursor.character;
view_it->transient.file_data.file = models->scratch_buffer; view_it->transient.file_data.file = models->scratch_buffer;
++vptr_count; ++vptr_count;
} }
@ -1423,7 +1427,7 @@ Reopen_Buffer(Application_Links *app, Buffer_Summary *buffer, Buffer_Reopen_Flag
view_set_file(system, models, vptrs[i], file); view_set_file(system, models, vptrs[i], file);
vptrs[i]->transient.file_data.file = file; vptrs[i]->transient.file_data.file = file;
vptrs[i]->transient.edit_pos = edit_positions[i]; view_set_edit_pos(vptrs[i], edit_positions[i]);
Full_Cursor cursor = file_compute_cursor(system, file, seek_line_char(line_numbers[i], column_numbers[i]), 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);
@ -1944,15 +1948,17 @@ DOC_SEE(Buffer_Seek)
Editing_File *file = vptr->transient.file_data.file; Editing_File *file = vptr->transient.file_data.file;
Assert(file != 0); Assert(file != 0);
if (!file->is_loading){ if (!file->is_loading){
File_Edit_Positions edit_pos = view_get_edit_pos(vptr);
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; edit_pos.mark = cursor.pos;
} }
else{ else{
result = true; result = true;
vptr->transient.edit_pos.mark = seek.pos; edit_pos.mark = seek.pos;
} }
view_set_edit_pos(vptr, edit_pos);
fill_view_summary(system, view, vptr, models); fill_view_summary(system, view, vptr, models);
} }
} }

View File

@ -177,63 +177,6 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count,
return(shift_amount); return(shift_amount);
} }
#if 0
internal i32
buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, i32 count, Buffer_Edit *sorted_edits, i32 edit_count, b32 lean_right){
Cursor_With_Index *position = sorted_positions;
Cursor_With_Index *end_position = sorted_positions + count;
Buffer_Edit *edit = sorted_edits;
Buffer_Edit *end_edit = sorted_edits + edit_count;
i32 shift_amount = 0;
if (lean_right){
for (; edit < end_edit && position < end_position; ++edit){
i32 start = edit->start;
i32 end = edit->end;
for (; position->pos < start && position < end_position; ++position){
position->pos += shift_amount;
}
i32 new_end = start + edit->len + shift_amount;
for (; position->pos <= end && position < end_position; ++position){
position->pos = new_end;
}
shift_amount += (edit->len - (end - start));
}
}
else{
for (; edit < end_edit && position < end_position; ++edit){
i32 start = edit->start;
i32 end = edit->end;
for (; position->pos < start && position < end_position; ++position){
position->pos += shift_amount;
}
i32 new_end = start + shift_amount;
for (; position->pos <= end && position < end_position; ++position){
position->pos = new_end;
}
shift_amount += (edit->len - (end - start));
}
}
for (; position < end_position; ++position){
position->pos += shift_amount;
}
for (; edit < end_edit; ++edit){
shift_amount += (edit->len - (edit->end - edit->start));
}
return(shift_amount);
}
#endif
////////////////////////////////////// //////////////////////////////////////
internal i32 internal i32
@ -554,35 +497,6 @@ buffer_batch_edit_step(Buffer_Batch_State *state, Gap_Buffer *buffer, Edit_Array
return(result); return(result);
} }
#if 0
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_Edit *edit = 0;
i32 shift_total = state->shift_total;
i32 result = 0;
i32 i = state->i;
edit = sorted_edits + i;
for (; i < edit_count; ++i, ++edit){
i32 start = edit->start + shift_total;
i32 end = edit->end + shift_total;
i32 len = edit->len;
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;
}
state->shift_total = shift_total;
state->i = i;
return(result);
}
#endif
internal void* internal void*
buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){ buffer_edit_provide_memory(Gap_Buffer *buffer, void *new_data, i32 new_max){
void *result = buffer->data; void *result = buffer->data;

View File

@ -114,9 +114,10 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
panel = layout_get_next_open_panel(layout, panel)){ panel = layout_get_next_open_panel(layout, panel)){
View *view = panel->view; View *view = panel->view;
if (view->transient.file_data.file == file){ if (view->transient.file_data.file == file){
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos.cursor.pos); File_Edit_Positions edit_pos = view_get_edit_pos(view);
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos.mark); write_cursor_with_index(cursors, &cursor_count, edit_pos.cursor.pos);
write_cursor_with_index(cursors, &cursor_count, view->transient.edit_pos.scroll_i); write_cursor_with_index(cursors, &cursor_count, edit_pos.mark );
write_cursor_with_index(cursors, &cursor_count, edit_pos.scroll_i );
} }
} }
@ -139,17 +140,6 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
if (cursor_count > 0 || r_cursor_count > 0){ if (cursor_count > 0 || r_cursor_count > 0){
buffer_sort_cursors(cursors, cursor_count); buffer_sort_cursors(cursors, cursor_count);
#if 0
if (desc.is_batch){
buffer_batch_edit_update_cursors(cursors, cursor_count, desc.batch, desc.batch_size, false);
buffer_batch_edit_update_cursors(r_cursors, r_cursor_count, desc.batch, desc.batch_size, true);
}
else{
buffer_update_cursors(cursors, cursor_count, desc.start, desc.end, desc.shift_amount + (desc.end - desc.start), false);
buffer_update_cursors(r_cursors, r_cursor_count, desc.start, desc.end, desc.shift_amount + (desc.end - desc.start), true);
}
#endif
if (edits.count > 1){ if (edits.count > 1){
buffer_batch_edit_update_cursors( cursors, cursor_count, edits, false); buffer_batch_edit_update_cursors( cursors, cursor_count, edits, false);
buffer_batch_edit_update_cursors(r_cursors, r_cursor_count, edits, true); buffer_batch_edit_update_cursors(r_cursors, r_cursor_count, edits, true);
@ -172,16 +162,17 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
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; File_Edit_Positions edit_pos = view_get_edit_pos(view);
GUI_Scroll_Vars scroll = edit_pos.scroll;
view->transient.edit_pos.mark = cursors[cursor_count++].pos; 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 (edit_pos.scroll_i != new_scroll_i){
view->transient.edit_pos.scroll_i = new_scroll_i; 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(edit_pos.scroll_i), 0);
f32 y_offset = MOD(view->transient.edit_pos.scroll.scroll_y, view->transient.line_height); f32 y_offset = MOD(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;
@ -192,7 +183,9 @@ edit_fix_markers(System_Functions *system, Models *models, Editing_File *file, E
scroll.scroll_y = y_position; scroll.scroll_y = y_position;
} }
view_set_cursor_and_scroll(view, new_cursor, 1, view->transient.file_data.file->settings.unwrapped_lines, scroll); // TODO(allen): do(remove view_set_edit_pos from marker unrolling if it is redundant)
view_set_edit_pos(view, edit_pos);
view_set_cursor_and_scroll(view, new_cursor, true, view->transient.file_data.file->settings.unwrapped_lines, scroll);
} }
} }
@ -301,31 +294,6 @@ edit_single(System_Functions *system, Models *models, Editing_File *file, Edit e
} }
} }
#if 0
internal Edit_Spec
edit_compute_batch_spec(Heap *heap, Editing_File *file, Buffer_Edit *edits, char *str_base, i32 str_size,
Buffer_Edit *inverse_array, char *inv_str, i32 inv_max, i32 edit_count, i32 batch_type){
i32 inv_str_pos = 0;
Buffer_Invert_Batch state = {};
if (buffer_invert_batch(&state, &file->state.buffer, edits, edit_count, inverse_array, inv_str, &inv_str_pos, inv_max)){
InvalidCodePath;
}
i32 first_child = undo_children_push(heap, &file->state.undo.children, edits, edit_count, (u8*)(str_base), str_size);
i32 inverse_first_child = undo_children_push(heap, &file->state.undo.children, inverse_array, edit_count, (u8*)(inv_str), inv_str_pos);
Edit_Spec spec = {};
spec.step.type = ED_NORMAL;
spec.step.first_child = first_child;
spec.step.inverse_first_child = inverse_first_child;
spec.step.special_type = batch_type;
spec.step.child_count = edit_count;
spec.step.inverse_child_count = edit_count;
return(spec);
}
#endif
internal void internal void
edit_batch(System_Functions *system, Models *models, Editing_File *file, Edit_Array edits, Edit_Behaviors behaviors){ edit_batch(System_Functions *system, Models *models, Editing_File *file, Edit_Array edits, Edit_Behaviors behaviors){
Mem_Options *mem = &models->mem; Mem_Options *mem = &models->mem;

View File

@ -22,10 +22,12 @@ internal void
edit_pos_set_cursor(File_Edit_Positions *edit_pos, Full_Cursor cursor, b32 set_preferred_x, b32 unwrapped_lines){ edit_pos_set_cursor(File_Edit_Positions *edit_pos, Full_Cursor cursor, b32 set_preferred_x, b32 unwrapped_lines){
edit_pos->cursor = cursor; edit_pos->cursor = cursor;
if (set_preferred_x){ if (set_preferred_x){
edit_pos->preferred_x = cursor.wrapped_x;
if (unwrapped_lines){ if (unwrapped_lines){
edit_pos->preferred_x = cursor.unwrapped_x; edit_pos->preferred_x = cursor.unwrapped_x;
} }
else{
edit_pos->preferred_x = cursor.wrapped_x;
}
} }
edit_pos->last_set_type = EditPos_CursorSet; edit_pos->last_set_type = EditPos_CursorSet;
} }
@ -51,6 +53,9 @@ edit_pos_pop(Editing_File *file){
edit_pos = file->state.edit_pos_stack[file->state.edit_pos_stack_top]; edit_pos = file->state.edit_pos_stack[file->state.edit_pos_stack_top];
file->state.edit_pos_stack_top -= 1; file->state.edit_pos_stack_top -= 1;
} }
else{
edit_pos = file->state.edit_pos_most_recent;
}
return(edit_pos); return(edit_pos);
} }

View File

@ -89,6 +89,7 @@ struct Editing_File_State{
Dirty_State dirty; Dirty_State dirty;
u32 ignore_behind_os; u32 ignore_behind_os;
File_Edit_Positions edit_pos_most_recent;
File_Edit_Positions edit_pos_stack[16]; File_Edit_Positions edit_pos_stack[16];
i32 edit_pos_stack_top; i32 edit_pos_stack_top;
}; };

View File

@ -60,17 +60,6 @@ history__merge_record_ptr_range_to_one_ptr(Record_Ptr_Lookup_Table *lookup, i32
lookup->records[first] = record; lookup->records[first] = record;
} }
#if 0
internal Node*
history__to_node(History *history, i32 index){
Node *result = 0;
if (0 <= index && index <= history->record_count){
Node *sentinel = &history->records;
result = history__to_node(sentinel, index);
}
return(result);
}
#else
internal Node* internal Node*
history__to_node(History *history, i32 index){ history__to_node(History *history, i32 index){
Node *result = 0; Node *result = 0;
@ -84,7 +73,6 @@ history__to_node(History *history, i32 index){
} }
return(result); return(result);
} }
#endif
//////////////////////////////// ////////////////////////////////

View File

@ -58,6 +58,19 @@ live_set_free_view(Heap *heap, Lifetime_Allocator *lifetime_allocator, Live_View
//////////////////////////////// ////////////////////////////////
internal File_Edit_Positions
view_get_edit_pos(View *view){
return(view->transient.edit_pos_);
}
internal void
view_set_edit_pos(View *view, File_Edit_Positions edit_pos){
view->transient.edit_pos_ = edit_pos;
view->transient.file_data.file->state.edit_pos_most_recent = edit_pos;
}
////////////////////////////////
// TODO(allen): Switch over to using an i32 for these. // TODO(allen): Switch over to using an i32 for these.
internal f32 internal f32
view_width(View *view){ view_width(View *view){
@ -80,7 +93,8 @@ view_get_cursor_xy(View *view){
cursor = &view->transient.file_data.temp_highlight; cursor = &view->transient.file_data.temp_highlight;
} }
else{ else{
cursor = &view->transient.edit_pos.cursor; File_Edit_Positions edit_pos = view_get_edit_pos(view);
cursor = &edit_pos.cursor;
} }
Vec2 result = V2(cursor->wrapped_x, cursor->wrapped_y); Vec2 result = V2(cursor->wrapped_x, cursor->wrapped_y);
if (view->transient.file_data.file->settings.unwrapped_lines){ if (view->transient.file_data.file->settings.unwrapped_lines){
@ -241,44 +255,52 @@ 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){
edit_pos_set_cursor(&view->transient.edit_pos, cursor, set_preferred_x, unwrapped_lines); File_Edit_Positions edit_pos = view_get_edit_pos(view);
GUI_Scroll_Vars scroll = view->transient.edit_pos.scroll; edit_pos_set_cursor(&edit_pos, cursor, set_preferred_x, unwrapped_lines);
GUI_Scroll_Vars scroll = 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; edit_pos.scroll = scroll;
} }
view_set_edit_pos(view, edit_pos);
} }
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){
edit_pos_set_scroll(&view->transient.edit_pos, scroll); File_Edit_Positions edit_pos = view_get_edit_pos(view);
Full_Cursor cursor = view->transient.edit_pos.cursor; edit_pos_set_scroll(&edit_pos, scroll);
if (view_move_cursor_to_view(system, view, view->transient.edit_pos.scroll, &cursor, view->transient.edit_pos.preferred_x)){ Full_Cursor cursor = edit_pos.cursor;
view->transient.edit_pos.cursor = cursor; if (view_move_cursor_to_view(system, view, edit_pos.scroll, &cursor, edit_pos.preferred_x)){
edit_pos.cursor = cursor;
} }
view_set_edit_pos(view, edit_pos);
} }
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_get_edit_pos(view);
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;
view_set_edit_pos(view, edit_pos);
} }
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); Vec2 cursor = view_get_cursor_xy(view);
File_Edit_Positions edit_pos = view_get_edit_pos(view);
Relative_Scrolling result = {}; Relative_Scrolling result = {};
result.scroll_y = cursor.y - view->transient.edit_pos.scroll.scroll_y; result.scroll_y = cursor.y - edit_pos.scroll.scroll_y;
result.target_y = cursor.y - view->transient.edit_pos.scroll.target_y; result.target_y = cursor.y - 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);
view->transient.edit_pos.scroll.scroll_y = cursor.y - scrolling.scroll_y; File_Edit_Positions edit_pos = view_get_edit_pos(view);
view->transient.edit_pos.scroll.target_y = round32(clamp_bottom(0.f, cursor.y - scrolling.target_y)); edit_pos.scroll.scroll_y = cursor.y - scrolling.scroll_y;
edit_pos.scroll.target_y = round32(clamp_bottom(0.f, cursor.y - scrolling.target_y));
view_set_edit_pos(view, edit_pos);
} }
internal void internal void
@ -319,18 +341,20 @@ view_set_file(System_Functions *system, Models *models, View *view, Editing_File
Editing_File *old_file = view->transient.file_data.file; Editing_File *old_file = view->transient.file_data.file;
if (old_file != 0){ if (old_file != 0){
file_touch(&models->working_set, old_file); file_touch(&models->working_set, old_file);
edit_pos_push(old_file, view->transient.edit_pos); edit_pos_push(old_file, view_get_edit_pos(view));
} }
block_zero(&view->transient.file_data, sizeof(view->transient.file_data)); block_zero(&view->transient.file_data, sizeof(view->transient.file_data));
view->transient.file_data.file = file; view->transient.file_data.file = file;
view->transient.edit_pos = edit_pos_pop(file); // TODO(allen): do(set edit pos without updating file when popping)
view->transient.edit_pos_ = edit_pos_pop(file);
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 (view->transient.edit_pos.cursor.line == 0){ File_Edit_Positions edit_pos = view_get_edit_pos(view);
if (edit_pos.cursor.line == 0){
view_cursor_move(system, view, 0); view_cursor_move(system, view, 0);
} }
} }
@ -362,7 +386,8 @@ 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){
i32 pos = view->transient.edit_pos.cursor.pos; File_Edit_Positions edit_pos = view_get_edit_pos(view);
i32 pos = 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);
} }
@ -1202,8 +1227,9 @@ 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; File_Edit_Positions edit_pos = view_get_edit_pos(view);
f32 scroll_y = view->transient.edit_pos.scroll.scroll_y; f32 scroll_x = edit_pos.scroll.scroll_x;
f32 scroll_y = 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
@ -1218,7 +1244,8 @@ 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; // TODO(allen): do(eliminate scroll_i nonsense)
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;

View File

@ -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;

View File

@ -183,12 +183,13 @@ draw_file_bar(System_Functions *system, Render_Target *target, View *view, Model
intbar_draw_string(system, target, &bar, lit(" loading"), base_color); intbar_draw_string(system, target, &bar, lit(" loading"), base_color);
} }
else{ else{
File_Edit_Positions edit_pos = view_get_edit_pos(view);
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, 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, edit_pos.cursor.character);
append_ss(&bar_text, lit(" -")); append_ss(&bar_text, lit(" -"));