merge pre-commit

This commit is contained in:
Allen Webster 2016-09-23 16:02:58 -04:00
parent e5d1d71175
commit fbbb50b105
5 changed files with 126 additions and 187 deletions

View File

@ -395,7 +395,7 @@ COMMAND_DECL(reopen){
*vptrs[i]->edit_pos = edit_poss[i];
Full_Cursor cursor =
view_compute_cursor_from_line_pos(vptrs[i], line, column);
view_compute_cursor_from_line_char(vptrs[i], line, column);
view_set_cursor(vptrs[i], cursor, true,
file->settings.unwrapped_lines);

View File

@ -645,7 +645,7 @@ DOC_SEE(Partial_Cursor)
bool32 result = false;
if (file){
if (file_compute_cursor(file, seek, cursor_out)){
if (file_compute_partial_cursor(file, seek, cursor_out)){
result = true;
fill_buffer_summary(buffer, file, cmd);
}

View File

@ -377,6 +377,44 @@ file_compute_lowest_line(Editing_File *file, f32 font_height){
return(lowest_line);
}
//
// File Cursor Seeking
//
inline Partial_Cursor
file_compute_cursor_from_pos(Editing_File *file, i32 pos){
Partial_Cursor result = buffer_partial_from_pos(&file->state.buffer, pos);
return(result);
}
inline Partial_Cursor
file_compute_cursor_from_line_character(Editing_File *file, i32 line, i32 character){
Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character);
return(result);
}
inline b32
file_compute_partial_cursor(Editing_File *file, Buffer_Seek seek, Partial_Cursor *cursor){
b32 result = 1;
switch (seek.type){
case buffer_seek_pos:
{
*cursor = file_compute_cursor_from_pos(file, seek.pos);
}break;
case buffer_seek_line_char:
{
*cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character);
}break;
default:
{
result = 0;
}break;
}
return(result);
}
//

View File

@ -386,53 +386,23 @@ view_cursor_limits(View *view){
return(limits);
}
inline Partial_Cursor
file_compute_cursor_from_pos(Editing_File *file, i32 pos){
Partial_Cursor result = buffer_partial_from_pos(&file->state.buffer, pos);
return(result);
}
inline Partial_Cursor
file_compute_cursor_from_line_character(Editing_File *file, i32 line, i32 character){
Partial_Cursor result = buffer_partial_from_line_character(&file->state.buffer, line, character);
return(result);
}
inline b32
file_compute_cursor(Editing_File *file, Buffer_Seek seek, Partial_Cursor *cursor){
b32 result = 1;
switch (seek.type){
case buffer_seek_pos:
{
*cursor = file_compute_cursor_from_pos(file, seek.pos);
}break;
case buffer_seek_line_char:
{
*cursor = file_compute_cursor_from_line_character(file, seek.line, seek.character);
}break;
default:
{
result = 0;
}break;
}
return(result);
}
inline Full_Cursor
view_compute_cursor_from_pos(View *view, i32 pos){
Editing_File *file = view->file_data.file;
Models *models = view->persistent.models;
Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font;
Full_Cursor result = {};
if (font){
f32 max_width = view_file_display_width(view);
result = buffer_cursor_from_pos(&file->state.buffer, file->state.wraps, pos, max_width,
(f32)view->line_height, font->advance_data);
}
return result;
Buffer_Cursor_Seek_Params params;
params.buffer = &file->state.buffer;
params.seek = seek_pos(pos);
params.max_width = view_file_display_width(view);
params.font_height = (f32)font->height;
params.adv = font->advance_data;
params.wraps = file->state.wraps;
Full_Cursor result = buffer_cursor_seek(params);
return(result);
}
inline Full_Cursor
@ -441,14 +411,17 @@ view_compute_cursor_from_unwrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 ro
Models *models = view->persistent.models;
Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font;
Full_Cursor result = {};
if (font){
f32 max_width = view_file_display_width(view);
result = buffer_cursor_from_unwrapped_xy(&file->state.buffer, file->state.wraps, seek_x, seek_y,
round_down, max_width, (f32)view->line_height, font->advance_data);
}
Buffer_Cursor_Seek_Params params;
params.buffer = &file->state.buffer;
params.seek = seek_unwrapped_xy(seek_x, seek_y, round_down);
params.max_width = view_file_display_width(view);
params.font_height = (f32)font->height;
params.adv = font->advance_data;
params.wraps = file->state.wraps;
return result;
Full_Cursor result = buffer_cursor_seek(params);
return(result);
}
internal Full_Cursor
@ -457,30 +430,36 @@ view_compute_cursor_from_wrapped_xy(View *view, f32 seek_x, f32 seek_y, b32 roun
Models *models = view->persistent.models;
Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font;
Full_Cursor result = {};
if (font){
f32 max_width = view_file_display_width(view);
result = buffer_cursor_from_wrapped_xy(&file->state.buffer, file->state.wraps, seek_x, seek_y, round_down,
max_width, (f32)view->line_height, font->advance_data);
}
Buffer_Cursor_Seek_Params params;
params.buffer = &file->state.buffer;
params.seek = seek_wrapped_xy(seek_x, seek_y, round_down);
params.max_width = view_file_display_width(view);
params.font_height = (f32)font->height;
params.adv = font->advance_data;
params.wraps = file->state.wraps;
return (result);
Full_Cursor result = buffer_cursor_seek(params);
return(result);
}
internal Full_Cursor
view_compute_cursor_from_line_pos(View *view, i32 line, i32 pos){
view_compute_cursor_from_line_char(View *view, i32 line, i32 character){
Editing_File *file = view->file_data.file;
Models *models = view->persistent.models;
Render_Font *font = get_font_info(models->font_set, file->settings.font_id)->font;
Full_Cursor result = {};
if (font){
f32 max_width = view_file_display_width(view);
result = buffer_cursor_from_line_character(&file->state.buffer, file->state.wraps, line, pos,
max_width, (f32)view->line_height, font->advance_data);
}
Buffer_Cursor_Seek_Params params;
params.buffer = &file->state.buffer;
params.seek = seek_line_char(line, character);
params.max_width = view_file_display_width(view);
params.font_height = (f32)font->height;
params.adv = font->advance_data;
params.wraps = file->state.wraps;
return (result);
Full_Cursor result = buffer_cursor_seek(params);
return(result);
}
inline Full_Cursor
@ -501,7 +480,7 @@ view_compute_cursor(View *view, Buffer_Seek seek){
break;
case buffer_seek_line_char:
result = view_compute_cursor_from_line_pos(view, seek.line, seek.character);
result = view_compute_cursor_from_line_char(view, seek.line, seek.character);
break;
}
@ -1730,7 +1709,7 @@ view_cursor_move(View *view, f32 x, f32 y, b32 round_down = 0){
inline void
view_cursor_move(View *view, i32 line, i32 pos){
Full_Cursor cursor = view_compute_cursor_from_line_pos(view, line, pos);
Full_Cursor cursor = view_compute_cursor_from_line_char(view, line, pos);
view_cursor_move(view, cursor);
}
@ -4821,8 +4800,6 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
Render_Font *font = get_font_info(models->font_set, font_id)->font;
float *advance_data = font->advance_data;
Full_Cursor render_cursor = {0};
f32 scroll_x = view->edit_pos->scroll.scroll_x;
f32 scroll_y = view->edit_pos->scroll.scroll_y;
@ -4831,9 +4808,24 @@ draw_file_loaded(View *view, i32_Rect rect, b32 is_active, Render_Target *target
// to the gui system.
scroll_y += view->widget_height;
render_cursor = buffer_get_start_cursor(&file->state.buffer, file->state.wraps, scroll_y,
!file->settings.unwrapped_lines,
max_x, advance_data, (f32)line_height);
Full_Cursor render_cursor = {0};
{
Buffer_Cursor_Seek_Params params;
params.buffer = &file->state.buffer;
params.max_width = max_x;
params.font_height = (f32)line_height;
params.adv = advance_data;
params.wraps = file->state.wraps;
if (!file->settings.unwrapped_lines){
params.seek = seek_wrapped_xy(0, scroll_y, 0);
}
else{
params.seek = seek_unwrapped_xy(0, scroll_y, 0);
}
render_cursor = buffer_cursor_seek(params);
}
view->edit_pos->scroll_i = render_cursor.pos;

View File

@ -444,10 +444,11 @@ struct Buffer_Cursor_Seek_Params{
};
internal_4tech Full_Cursor
buffer_cursor_seek(Buffer_Cursor_Seek_Params params, Full_Cursor cursor_hint){
buffer_cursor_seek(Buffer_Cursor_Seek_Params params){
i32 size = buffer_size(params.buffer);
Full_Cursor cursor = {0};
switch (params.seek.type){
case buffer_seek_pos:
{
@ -459,7 +460,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params, Full_Cursor cursor_hint){
}
i32 line_index = buffer_get_line_index_range(params.buffer, params.seek.pos, 0, params.buffer->line_count);
cursor_hint = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
if (cursor.pos >= params.seek.pos){
goto buffer_cursor_seek_end;
}
}break;
case buffer_seek_line_char:
@ -473,7 +478,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params, Full_Cursor cursor_hint){
line_index = 0;
}
cursor_hint = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
if (params.seek.x == 0 && cursor.wrapped_y >= params.seek.y){
goto buffer_cursor_seek_end;
}
}break;
case buffer_seek_unwrapped_xy:
@ -487,7 +496,11 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params, Full_Cursor cursor_hint){
line_index = 0;
}
cursor_hint = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
if (params.seek.x == 0 && cursor.unwrapped_y >= params.seek.y){
goto buffer_cursor_seek_end;
}
}break;
case buffer_seek_wrapped_xy:
@ -495,32 +508,14 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params, Full_Cursor cursor_hint){
i32 line_index = buffer_get_line_index_from_wrapped_y(params.wraps, params.seek.y,
params.font_height, 0, params.buffer->line_count);
cursor_hint = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
}break;
}
Full_Cursor cursor = cursor_hint;
switch(params.seek.type){
case buffer_seek_pos:
if (cursor.pos >= params.seek.pos){
goto buffer_cursor_seek_end;
cursor = make_cursor_hint(line_index, params.buffer->line_starts, params.wraps, params.font_height);
if (cursor.line >= params.seek.line && cursor.character >= params.seek.character){
goto buffer_cursor_seek_end;
}
}break;
case buffer_seek_wrapped_xy:
if (params.seek.x == 0 && cursor.wrapped_y >= params.seek.y){
goto buffer_cursor_seek_end;
}break;
case buffer_seek_unwrapped_xy:
if (params.seek.x == 0 && cursor.unwrapped_y >= params.seek.y){
goto buffer_cursor_seek_end;
}break;
case buffer_seek_line_char:
if (cursor.line >= params.seek.line && cursor.character >= params.seek.character){
goto buffer_cursor_seek_end;
}break;
default: InvalidCodePath;
}
if (params.adv){
@ -630,75 +625,6 @@ buffer_cursor_seek(Buffer_Cursor_Seek_Params params, Full_Cursor cursor_hint){
return(cursor);
}
internal_4tech Full_Cursor
buffer_cursor_from_pos(Buffer_Type *buffer, f32 *wraps, i32 pos,
f32 max_width, f32 font_height, f32 *adv){
Full_Cursor result = {0};
Buffer_Cursor_Seek_Params params;
params.buffer = buffer;
params.seek = seek_pos(pos);
params.max_width = max_width;
params.font_height = font_height;
params.adv = adv;
params.wraps = wraps;
result = buffer_cursor_seek(params, result);
return(result);
}
internal_4tech Full_Cursor
buffer_cursor_from_line_character(Buffer_Type *buffer, f32 *wraps, i32 line, i32 character,
f32 max_width, f32 font_height, f32 *adv){
Full_Cursor result = {0};
Buffer_Cursor_Seek_Params params;
params.buffer = buffer;
params.seek = seek_line_char(line, character);
params.max_width = max_width;
params.font_height = font_height;
params.adv = adv;
params.wraps = wraps;
result = buffer_cursor_seek(params, result);
return(result);
}
internal_4tech Full_Cursor
buffer_cursor_from_unwrapped_xy(Buffer_Type *buffer, f32 *wraps, f32 x, f32 y, i32 round_down,
f32 max_width, f32 font_height, f32 *adv){
Full_Cursor result = {0};
Buffer_Cursor_Seek_Params params;
params.buffer = buffer;
params.seek = seek_unwrapped_xy(x, y, round_down);
params.max_width = max_width;
params.font_height = font_height;
params.adv = adv;
params.wraps = wraps;
result = buffer_cursor_seek(params, result);
return(result);
}
internal_4tech Full_Cursor
buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, f32 *wraps, f32 x, f32 y, i32 round_down,
f32 max_width, f32 font_height, f32 *adv){
Full_Cursor result = {0};
Buffer_Cursor_Seek_Params params;
params.buffer = buffer;
params.seek = seek_wrapped_xy(x, y, round_down);
params.max_width = max_width;
params.font_height = font_height;
params.adv = adv;
params.wraps = wraps;
result = buffer_cursor_seek(params, result);
return(result);
}
internal_4tech void
buffer_invert_edit_shift(Buffer_Type *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings,
i32 *str_pos, i32 max, i32 shift_amount){
@ -753,23 +679,6 @@ buffer_invert_batch(Buffer_Invert_Batch *state, Buffer_Type *buffer, Buffer_Edit
return(result);
}
internal_4tech Full_Cursor
buffer_get_start_cursor(Buffer_Type *buffer, f32 *wraps, f32 scroll_y,
i32 wrapped, f32 width, f32 *adv, f32 font_height){
Full_Cursor result;
if (wrapped){
result = buffer_cursor_from_wrapped_xy(buffer, wraps, 0, scroll_y, 0,
width, font_height, adv);
}
else{
result = buffer_cursor_from_unwrapped_xy(buffer, wraps, 0, scroll_y, 0,
width, font_height, adv);
}
return(result);
}
enum Buffer_Render_Flag{
BRFlag_Special_Character = (1 << 0)
};