updown seeks
This commit is contained in:
parent
20706a2e5d
commit
67c15443e0
66
4ed.cpp
66
4ed.cpp
|
@ -234,36 +234,22 @@ COMMAND_DECL(seek_whitespace_left){
|
|||
}
|
||||
|
||||
COMMAND_DECL(seek_whitespace_up){
|
||||
#if BUFFER_EXPERIMENT_SCALPEL
|
||||
ProfileMomentFunction();
|
||||
REQ_FILE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
|
||||
char* data = file->buffer.data;
|
||||
u32 pos = view->cursor.pos;
|
||||
while (pos > 0 && char_is_whitespace(data[pos])){
|
||||
--pos;
|
||||
}
|
||||
|
||||
bool32 no_hard_character = 0;
|
||||
while (pos > 0){
|
||||
if (starts_new_line(data[pos])){
|
||||
if (no_hard_character) break;
|
||||
else no_hard_character = 1;
|
||||
}
|
||||
else if (!char_is_whitespace(data[pos])){
|
||||
no_hard_character = 0;
|
||||
}
|
||||
--pos;
|
||||
}
|
||||
|
||||
if (pos != 0) ++pos;
|
||||
|
||||
i32 pos = buffer_seek_whitespace_up(&file->buffer, view->cursor.pos);
|
||||
view_cursor_move(view, pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
COMMAND_DECL(seek_whitespace_down){
|
||||
ProfileMomentFunction();
|
||||
REQ_FILE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
|
||||
i32 pos = buffer_seek_whitespace_down(&file->buffer, view->cursor.pos);
|
||||
view_cursor_move(view, pos);
|
||||
|
||||
#if BUFFER_EXPERIMENT_SCALPEL
|
||||
ProfileMomentFunction();
|
||||
REQ_FILE_VIEW(view);
|
||||
|
@ -382,40 +368,13 @@ COMMAND_DECL(seek_white_or_token_left){
|
|||
#endif
|
||||
}
|
||||
|
||||
internal i32
|
||||
seek_alphanumeric_right(u8 *data, i32 size, i32 pos){
|
||||
while (pos < size && !char_is_alpha_numeric_true(data[pos])){
|
||||
++pos;
|
||||
}
|
||||
while (pos < size && char_is_alpha_numeric_true(data[pos])){
|
||||
++pos;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
internal i32
|
||||
seek_alphanumeric_left(u8 *data, i32 pos){
|
||||
--pos;
|
||||
while (pos > 0 && !char_is_alpha_numeric_true(data[pos])){
|
||||
--pos;
|
||||
}
|
||||
while (pos >= 0 && char_is_alpha_numeric_true(data[pos])){
|
||||
--pos;
|
||||
}
|
||||
++pos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
COMMAND_DECL(seek_alphanumeric_right){
|
||||
#if BUFFER_EXPERIMENT_SCALPEL
|
||||
ProfileMomentFunction();
|
||||
REQ_FILE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
|
||||
i32 pos = seek_alphanumeric_right(
|
||||
(u8*)file->buffer.data, file->buffer.size, view->cursor.pos);
|
||||
i32 pos = buffer_seek_alphanumeric_right(&file->buffer, view->cursor.pos);
|
||||
view_cursor_move(view, pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
COMMAND_DECL(seek_alphanumeric_left){
|
||||
|
@ -423,8 +382,7 @@ COMMAND_DECL(seek_alphanumeric_left){
|
|||
REQ_FILE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
|
||||
i32 pos = seek_alphanumeric_left(
|
||||
(u8*)file->buffer.data, view->cursor.pos);
|
||||
i32 pos = buffer_seek_alphanumeric_left(&file->buffer, view->cursor.pos);
|
||||
view_cursor_move(view, pos);
|
||||
}
|
||||
|
||||
|
@ -455,6 +413,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_right){
|
|||
}
|
||||
|
||||
COMMAND_DECL(seek_alphanumeric_or_camel_left){
|
||||
#if BUFFER_EXPERIMENT_SCALPEL
|
||||
ProfileMomentFunction();
|
||||
REQ_FILE_VIEW(view);
|
||||
REQ_FILE(file, view);
|
||||
|
@ -462,7 +421,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_left){
|
|||
u8 *data = (u8*)file->buffer.data;
|
||||
|
||||
i32 an_pos, camel_pos;
|
||||
an_pos = seek_alphanumeric_left(
|
||||
an_pos = buffer_seek_alphanumeric_left(
|
||||
data, view->cursor.pos);
|
||||
|
||||
char curr_char;
|
||||
|
@ -476,6 +435,7 @@ COMMAND_DECL(seek_alphanumeric_or_camel_left){
|
|||
}
|
||||
|
||||
view_cursor_move(view, camel_pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
COMMAND_DECL(search){
|
||||
|
|
|
@ -1347,7 +1347,7 @@ file_create_from_string(General_Memory *general, Editing_File *file, u8 *filenam
|
|||
*file = {};
|
||||
file->buffer.data = (char*)data;
|
||||
file->buffer.max = request_size;
|
||||
gap_buffer_initialize(&file->buffer, val.str, val.size);
|
||||
buffer_initialize(&file->buffer, val.str, val.size);
|
||||
|
||||
file_synchronize_times(file, filename);
|
||||
file_init_strings(file);
|
||||
|
|
|
@ -13,11 +13,8 @@
|
|||
|
||||
// TOP
|
||||
|
||||
#define CAT_(a,b) a##b
|
||||
#define CAT(a,b) CAT_(a,b)
|
||||
|
||||
#define Buffer_Stringify_Type CAT(Buffer_Type, _Stringify_Loop)
|
||||
#define Buffer_Backify_Type CAT(Buffer_Type, _Backify_Loop)
|
||||
#define Buffer_Stringify_Type cat_4tech(Buffer_Type, _Stringify_Loop)
|
||||
#define Buffer_Backify_Type cat_4tech(Buffer_Type, _Backify_Loop)
|
||||
|
||||
internal_4tech int
|
||||
buffer_count_newlines(Buffer_Type *buffer, int start, int end){
|
||||
|
@ -42,6 +39,98 @@ buffer_count_newlines(Buffer_Type *buffer, int start, int end){
|
|||
return(count);
|
||||
}
|
||||
|
||||
internal_4tech int
|
||||
buffer_seek_whitespace_down(Buffer_Type *buffer, int pos){
|
||||
Buffer_Stringify_Type loop;
|
||||
char *data;
|
||||
int end;
|
||||
int size;
|
||||
int no_hard;
|
||||
int prev_endline;
|
||||
|
||||
size = buffer_size(buffer);
|
||||
loop = buffer_stringify_loop(buffer, pos, size, size);
|
||||
|
||||
for (;buffer_stringify_good(&loop);
|
||||
buffer_stringify_next(&loop)){
|
||||
end = loop.size + loop.absolute_pos;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (;pos < end; ++pos){
|
||||
if (!is_whitespace(data[pos])) goto buffer_seek_whitespace_down_mid;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_seek_whitespace_down_mid:
|
||||
no_hard = 0;
|
||||
prev_endline = -1;
|
||||
for (;buffer_stringify_good(&loop);
|
||||
buffer_stringify_next(&loop)){
|
||||
end = loop.size + loop.absolute_pos;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (; pos < end; ++pos){
|
||||
if (data[pos] == '\n'){
|
||||
if (no_hard) goto buffer_seek_whitespace_down_end;
|
||||
else{
|
||||
no_hard = 1;
|
||||
prev_endline = pos;
|
||||
}
|
||||
}
|
||||
else if (!is_whitespace(data[pos])){
|
||||
no_hard = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buffer_seek_whitespace_down_end:
|
||||
if (prev_endline == -1 || prev_endline+1 >= size) pos = size;
|
||||
else pos = prev_endline+1;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
internal_4tech int
|
||||
buffer_seek_whitespace_up(Buffer_Type *buffer, int pos){
|
||||
Buffer_Backify_Type loop;
|
||||
char *data;
|
||||
int end;
|
||||
int size;
|
||||
int no_hard;
|
||||
|
||||
size = buffer_size(buffer);
|
||||
loop = buffer_backify_loop(buffer, pos, 0, size);
|
||||
|
||||
for (;buffer_backify_good(&loop);
|
||||
buffer_backify_next(&loop)){
|
||||
end = loop.absolute_pos;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (;pos > end; --pos){
|
||||
if (!is_whitespace(data[pos])) goto buffer_seek_whitespace_up_mid;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_seek_whitespace_up_mid:
|
||||
no_hard = 0;
|
||||
for (;buffer_backify_good(&loop);
|
||||
buffer_backify_next(&loop)){
|
||||
end = loop.absolute_pos;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (; pos > end; --pos){
|
||||
if (data[pos] == '\n'){
|
||||
if (no_hard) goto buffer_seek_whitespace_up_end;
|
||||
else no_hard = 1;
|
||||
}
|
||||
else if (!is_whitespace(data[pos])){
|
||||
no_hard = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buffer_seek_whitespace_up_end:
|
||||
if (pos != 0) ++pos;
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
internal_4tech int
|
||||
buffer_seek_whitespace_right(Buffer_Type *buffer, int pos){
|
||||
Buffer_Stringify_Type loop;
|
||||
|
@ -77,24 +166,90 @@ buffer_seek_whitespace_left(Buffer_Type *buffer, int pos){
|
|||
char *data;
|
||||
int end;
|
||||
int size;
|
||||
|
||||
|
||||
size = buffer_size(buffer);
|
||||
loop = buffer_backify_loop(buffer, pos, 0, size);
|
||||
|
||||
for (;buffer_backify_good(&loop);
|
||||
buffer_backify_next(&loop)){
|
||||
end = loop.absolute_pos;
|
||||
data = loop.data - end;
|
||||
for (; pos > end && is_whitespace(data[pos]); --pos);
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (; pos >= end && is_whitespace(data[pos]); --pos);
|
||||
if (!is_whitespace(data[pos])) break;
|
||||
}
|
||||
|
||||
for (;buffer_backify_good(&loop);
|
||||
buffer_backify_next(&loop)){
|
||||
end = loop.absolute_pos;
|
||||
data = loop.data - end;
|
||||
for (; pos > end && !is_whitespace(data[pos]); --pos);
|
||||
if (is_whitespace(data[pos])) break;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (; pos >= end && is_whitespace(data[pos]); --pos);
|
||||
if (!is_whitespace(data[pos])) break;
|
||||
}
|
||||
|
||||
return(pos);
|
||||
}
|
||||
|
||||
internal_4tech int
|
||||
buffer_seek_alphanumeric_right(Buffer_Type *buffer, int pos){
|
||||
Buffer_Stringify_Type loop;
|
||||
char *data;
|
||||
int end;
|
||||
int size;
|
||||
|
||||
size = buffer_size(buffer);
|
||||
loop = buffer_stringify_loop(buffer, pos, size, size);
|
||||
|
||||
for (;buffer_stringify_good(&loop);
|
||||
buffer_stringify_next(&loop)){
|
||||
end = loop.size + loop.absolute_pos;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (; pos < end && is_alphanumeric_true(data[pos]); ++pos);
|
||||
if (!is_alphanumeric_true(data[pos])) break;
|
||||
}
|
||||
|
||||
for (;buffer_stringify_good(&loop);
|
||||
buffer_stringify_next(&loop)){
|
||||
end = loop.size + loop.absolute_pos;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (; pos < end && !is_alphanumeric_true(data[pos]); ++pos);
|
||||
if (is_alphanumeric_true(data[pos])) break;
|
||||
}
|
||||
|
||||
return(pos);
|
||||
}
|
||||
|
||||
internal_4tech int
|
||||
buffer_seek_alphanumeric_left(Buffer_Type *buffer, int pos){
|
||||
Buffer_Backify_Type loop;
|
||||
char *data;
|
||||
int end;
|
||||
int size;
|
||||
|
||||
--pos;
|
||||
if (pos >= 0){
|
||||
size = buffer_size(buffer);
|
||||
loop = buffer_backify_loop(buffer, pos, 0, size);
|
||||
|
||||
for (;buffer_backify_good(&loop);
|
||||
buffer_backify_next(&loop)){
|
||||
end = loop.absolute_pos;
|
||||
data = loop.data - end;
|
||||
for (; pos >= end && !is_alphanumeric_true(data[pos]); --pos);
|
||||
if (is_alphanumeric_true(data[pos])) break;
|
||||
}
|
||||
|
||||
for (;buffer_backify_good(&loop);
|
||||
buffer_backify_next(&loop)){
|
||||
end = loop.absolute_pos;
|
||||
data = loop.data - end;
|
||||
for (; pos >= end && is_alphanumeric_true(data[pos]); --pos);
|
||||
if (!is_alphanumeric_true(data[pos])) break;
|
||||
}
|
||||
|
||||
++pos;
|
||||
}
|
||||
else{
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
return(pos);
|
||||
|
@ -329,7 +484,7 @@ buffer_get_line_index(Buffer_Type *buffer, int pos, int l_bound, int u_bound){
|
|||
return(start);
|
||||
}
|
||||
|
||||
#ifndef NON_ABSTRACT_PORTION_4TECH
|
||||
#ifndef NON_ABSTRACT_4TECH
|
||||
internal_4tech int
|
||||
buffer_get_line_index_from_wrapped_y(float *wraps, float y, float font_height, int l_bound, int u_bound){
|
||||
int start, end, i, result;
|
||||
|
@ -352,6 +507,159 @@ buffer_get_line_index_from_wrapped_y(float *wraps, float y, float font_height, i
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifndef NON_ABSTRACT_4TECH
|
||||
|
||||
typedef struct{
|
||||
Full_Cursor cursor, prev_cursor;
|
||||
} Seek_State;
|
||||
|
||||
internal_4tech int
|
||||
cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_width, float font_height,
|
||||
char *advances, int stride, int size, char ch){
|
||||
Full_Cursor cursor, prev_cursor;
|
||||
float ch_width;
|
||||
int result;
|
||||
float x, px, y;
|
||||
|
||||
cursor = state->cursor;
|
||||
prev_cursor = state->prev_cursor;
|
||||
|
||||
result = 1;
|
||||
prev_cursor = cursor;
|
||||
switch (ch){
|
||||
case '\n':
|
||||
++cursor.line;
|
||||
cursor.unwrapped_y += font_height;
|
||||
cursor.wrapped_y += font_height;
|
||||
cursor.character = 1;
|
||||
cursor.unwrapped_x = 0;
|
||||
cursor.wrapped_x = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
++cursor.character;
|
||||
if (ch == '\r') ch_width = *(float*)(advances + stride * '\\') + *(float*)(advances + stride * 'r');
|
||||
else ch_width = *(float*)(advances + stride * ch);
|
||||
|
||||
if (cursor.wrapped_x + ch_width >= max_width){
|
||||
cursor.wrapped_y += font_height;
|
||||
cursor.wrapped_x = 0;
|
||||
prev_cursor = cursor;
|
||||
}
|
||||
|
||||
cursor.unwrapped_x += ch_width;
|
||||
cursor.wrapped_x += ch_width;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
++cursor.pos;
|
||||
|
||||
if (cursor.pos > size){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
|
||||
x = y = px = 0;
|
||||
|
||||
switch (seek.type){
|
||||
case buffer_seek_pos:
|
||||
if (cursor.pos > seek.pos){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}break;
|
||||
|
||||
case buffer_seek_wrapped_xy:
|
||||
x = cursor.wrapped_x; px = prev_cursor.wrapped_x;
|
||||
y = cursor.wrapped_y; break;
|
||||
|
||||
case buffer_seek_unwrapped_xy:
|
||||
x = cursor.unwrapped_x; px = prev_cursor.unwrapped_x;
|
||||
y = cursor.unwrapped_y; break;
|
||||
|
||||
case buffer_seek_line_char:
|
||||
if (cursor.line == seek.line && cursor.character >= seek.character){
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
else if (cursor.line > seek.line){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}break;
|
||||
}
|
||||
|
||||
if (xy_seek){
|
||||
if (y > seek.y){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
|
||||
if (y > seek.y - font_height && x >= seek.x){
|
||||
if (!seek.round_down){
|
||||
if (ch != '\n' && (seek.x - px) < (x - seek.x)) cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
|
||||
if (x > seek.x){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cursor_seek_step_end:
|
||||
state->cursor = cursor;
|
||||
state->prev_cursor = prev_cursor;
|
||||
|
||||
return(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
internal_4tech Full_Cursor
|
||||
buffer_cursor_seek(Buffer_Type *buffer, Buffer_Seek seek, float max_width, float font_height,
|
||||
void *advance_data, int stride, Full_Cursor cursor){
|
||||
Buffer_Stringify_Type loop;
|
||||
char *data;
|
||||
int size, end;
|
||||
int i;
|
||||
int result;
|
||||
|
||||
Seek_State state;
|
||||
char *advances;
|
||||
int xy_seek;
|
||||
|
||||
size = buffer_size(buffer);
|
||||
advances = (char*)advance_data;
|
||||
xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy);
|
||||
state.cursor = cursor;
|
||||
|
||||
result = 1;
|
||||
i = cursor.pos;
|
||||
for (loop = buffer_stringify_loop(buffer, i, size, size);
|
||||
buffer_stringify_good(&loop);
|
||||
buffer_stringify_next(&loop)){
|
||||
end = loop.size + loop.absolute_pos;
|
||||
data = loop.data - loop.absolute_pos;
|
||||
for (; i < end && result; ++i){
|
||||
result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height,
|
||||
advances, stride, size, data[i]);
|
||||
}
|
||||
}
|
||||
if (result){
|
||||
result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height,
|
||||
advances, stride, size, 0);
|
||||
assert_4tech(result == 0);
|
||||
}
|
||||
|
||||
return(state.cursor);
|
||||
}
|
||||
|
||||
internal_4tech Full_Cursor
|
||||
buffer_cursor_from_pos(Buffer_Type *buffer, int pos, float *wraps,
|
||||
float max_width, float font_height, void *advance_data, int stride){
|
||||
|
@ -399,9 +707,10 @@ buffer_cursor_from_wrapped_xy(Buffer_Type *buffer, float x, float y, int round_d
|
|||
|
||||
internal_4tech void
|
||||
buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *items, int max, int *count,
|
||||
float port_x, float port_y, float scroll_x, float scroll_y, Full_Cursor start_cursor, int wrapped,
|
||||
float port_x, float port_y, float scroll_x, float scroll_y, int wrapped,
|
||||
float width, float height, void *advance_data, int stride, float font_height){
|
||||
Buffer_Stringify_Type loop;
|
||||
Full_Cursor start_cursor;
|
||||
Buffer_Render_Item *item;
|
||||
char *data;
|
||||
int size, end;
|
||||
|
@ -410,14 +719,22 @@ buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *it
|
|||
int i, item_i;
|
||||
float ch_width, ch_width_sub;
|
||||
char ch;
|
||||
|
||||
|
||||
size = buffer_size(buffer);
|
||||
|
||||
|
||||
shift_x = port_x - scroll_x;
|
||||
shift_y = port_y - scroll_y;
|
||||
if (wrapped) shift_y += start_cursor.wrapped_y;
|
||||
else shift_y += start_cursor.unwrapped_y;
|
||||
|
||||
if (wrapped){
|
||||
start_cursor = buffer_cursor_from_wrapped_xy(buffer, 0, scroll_y, 0, wraps,
|
||||
width, font_height, advance_data, stride);
|
||||
shift_y += start_cursor.wrapped_y;
|
||||
}
|
||||
else{
|
||||
start_cursor = buffer_cursor_from_unwrapped_xy(buffer, 0, scroll_y, 0, wraps,
|
||||
width, font_height, advance_data, stride);
|
||||
shift_y += start_cursor.unwrapped_y;
|
||||
}
|
||||
|
||||
x = shift_x;
|
||||
y = shift_y;
|
||||
item_i = 0;
|
||||
|
@ -502,26 +819,8 @@ buffer_get_render_data_end:
|
|||
*count = item_i;
|
||||
}
|
||||
|
||||
internal_4tech void
|
||||
buffer_get_render_data(Buffer_Type *buffer, float *wraps, Buffer_Render_Item *items, int max, int *count,
|
||||
float port_x, float port_y, float scroll_x, float scroll_y, int wrapped,
|
||||
float width, float height, void *advance_data, int stride, float font_height){
|
||||
Full_Cursor start_cursor;
|
||||
if (wrapped){
|
||||
start_cursor = buffer_cursor_from_wrapped_xy(buffer, 0, scroll_y, 0, wraps,
|
||||
width, font_height, advance_data, stride);
|
||||
}
|
||||
else{
|
||||
start_cursor = buffer_cursor_from_unwrapped_xy(buffer, 0, scroll_y, 0, wraps,
|
||||
width, font_height, advance_data, stride);
|
||||
}
|
||||
buffer_get_render_data(buffer, wraps, items, max, count,
|
||||
port_x, port_y, scroll_x, scroll_y, start_cursor, wrapped,
|
||||
width, height, advance_data, stride, font_height);
|
||||
}
|
||||
|
||||
#ifndef NON_ABSTRACT_PORTION_4TECH
|
||||
#define NON_ABSTRACT_PORTION_4TECH 1
|
||||
#ifndef NON_ABSTRACT_4TECH
|
||||
#define NON_ABSTRACT_4TECH 1
|
||||
#endif
|
||||
// BOTTOM
|
||||
|
||||
|
|
|
@ -25,25 +25,26 @@ typedef struct{
|
|||
} Gap_Buffer;
|
||||
|
||||
inline_4tech void
|
||||
gap_buffer_initialize(Gap_Buffer *buffer, char *data, int size){
|
||||
int size1, size2, gap_size;
|
||||
buffer_initialize(Gap_Buffer *buffer, char *data, int size){
|
||||
int osize1, size1, size2;
|
||||
|
||||
assert_4tech(buffer->max >= size);
|
||||
|
||||
size1 = size >> 1;
|
||||
size2 = size - size1;
|
||||
gap_size = buffer->max - size1 - size2;
|
||||
size2 = size >> 1;
|
||||
size1 = osize1 = size - size2;
|
||||
|
||||
if (size1 > 0){
|
||||
size1 = eol_convert_in(buffer->data, data, size1);
|
||||
|
||||
if (size2 > 0){
|
||||
size2 = eol_convert_in(buffer->data + size1, data + osize1, size2);
|
||||
}
|
||||
}
|
||||
|
||||
buffer->size1 = size1;
|
||||
buffer->size2 = size2;
|
||||
buffer->gap_size = gap_size;
|
||||
|
||||
if (buffer->size1 > 0){
|
||||
memcpy_4tech(buffer->data, data, size1);
|
||||
}
|
||||
|
||||
if (buffer->size2 > 0){
|
||||
memcpy_4tech(buffer->data + size1 + gap_size, data + size1, size2);
|
||||
}
|
||||
buffer->gap_size = buffer->max - size1 - size2;
|
||||
memmove_4tech(buffer->data + size1 + buffer->gap_size, buffer->data + size1, size2);
|
||||
}
|
||||
|
||||
inline_4tech int
|
||||
|
@ -246,50 +247,5 @@ buffer_stringify(Gap_Buffer *buffer, int start, int end, char *out){
|
|||
}
|
||||
}
|
||||
|
||||
internal_4tech Full_Cursor
|
||||
buffer_cursor_seek(Gap_Buffer *buffer, Buffer_Seek seek, float max_width, float font_height,
|
||||
void *advance_data, int stride, Full_Cursor cursor){
|
||||
char *data;
|
||||
int size1, size2, gap_size;
|
||||
int total_size, end, i;
|
||||
int step;
|
||||
int result;
|
||||
|
||||
Seek_State state;
|
||||
char *advances;
|
||||
int xy_seek;
|
||||
char ch;
|
||||
|
||||
data = buffer->data;
|
||||
size1 = buffer->size1;
|
||||
gap_size = buffer->gap_size;
|
||||
size2 = buffer->size2;
|
||||
total_size = size1 + gap_size + size2;
|
||||
|
||||
advances = (char*)advance_data;
|
||||
xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy);
|
||||
state.cursor = cursor;
|
||||
|
||||
result = 1;
|
||||
i = cursor.pos;
|
||||
end = size1;
|
||||
for (step = 0; step < 2; ++step){
|
||||
for (; i < end && result; ++i){
|
||||
ch = data[i];
|
||||
result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height,
|
||||
advances, stride, size1 + size2, ch);
|
||||
}
|
||||
end = total_size;
|
||||
i += gap_size;
|
||||
}
|
||||
if (result){
|
||||
result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height,
|
||||
advances, stride, size1 + size2, 0);
|
||||
assert_4tech(result == 0);
|
||||
}
|
||||
|
||||
return(state.cursor);
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
||||
|
|
|
@ -24,6 +24,12 @@ typedef struct{
|
|||
int widths_max;
|
||||
} Buffer;
|
||||
|
||||
internal_4tech void
|
||||
buffer_initialize(Buffer *buffer, char *data, int size){
|
||||
assert_4tech(size <= buffer->max);
|
||||
buffer->size = eol_convert_in(buffer->data, data, size);
|
||||
}
|
||||
|
||||
inline_4tech int
|
||||
buffer_size(Buffer *buffer){
|
||||
return buffer->size;
|
||||
|
@ -150,36 +156,6 @@ buffer_replace_range(Buffer *buffer, int start, int end, char *str, int len, int
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech Full_Cursor
|
||||
buffer_cursor_seek(Buffer *buffer, Buffer_Seek seek, float max_width, float font_height,
|
||||
void *advance_data, int stride, Full_Cursor cursor){
|
||||
char *data;
|
||||
int size;
|
||||
|
||||
Seek_State state;
|
||||
char *advances;
|
||||
char ch;
|
||||
int xy_seek;
|
||||
int result;
|
||||
|
||||
data = buffer->data;
|
||||
size = buffer->size;
|
||||
assert_4tech(size < buffer->max);
|
||||
data[size] = 0;
|
||||
|
||||
advances = (char*)advance_data;
|
||||
xy_seek = (seek.type == buffer_seek_wrapped_xy || seek.type == buffer_seek_unwrapped_xy);
|
||||
state.cursor = cursor;
|
||||
|
||||
do{
|
||||
ch = data[state.cursor.pos];
|
||||
result = cursor_seek_step(&state, seek, xy_seek, max_width, font_height,
|
||||
advances, stride, size, ch);
|
||||
}while(result);
|
||||
|
||||
return(state.cursor);
|
||||
}
|
||||
|
||||
internal_4tech void
|
||||
buffer_invert_edit_shift(Buffer *buffer, Buffer_Edit edit, Buffer_Edit *inverse, char *strings, int *str_pos, int max, int shift_amount){
|
||||
int pos;
|
||||
|
@ -313,18 +289,6 @@ buffer_find_hard_start(Buffer *buffer, int line_start, int *all_whitespace, int
|
|||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech void
|
||||
buffer_eol_convert_in(Buffer *buffer){
|
||||
buffer->size = eol_convert_in(buffer->data, buffer->size);
|
||||
}
|
||||
|
||||
inline_4tech int
|
||||
buffer_eol_convert_out_size(Buffer *buffer){
|
||||
int size;
|
||||
size = buffer->size + buffer->line_count;
|
||||
return(size);
|
||||
}
|
||||
|
||||
internal_4tech void
|
||||
buffer_eol_convert_out(Buffer *buffer){
|
||||
int size;
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
#define assert_4tech assert
|
||||
|
||||
#define ceil_4tech CEIL32
|
||||
|
||||
#define cat_4tech_(a,b) a##b
|
||||
#define cat_4tech(a,b) cat_4tech_(a,b)
|
||||
#endif
|
||||
|
||||
inline_4tech float
|
||||
|
@ -147,117 +150,6 @@ make_cursor_hint(int line_index, int *starts, float *wrap_ys, float font_height)
|
|||
return(hint);
|
||||
}
|
||||
|
||||
typedef struct{
|
||||
Full_Cursor cursor, prev_cursor;
|
||||
} Seek_State;
|
||||
|
||||
internal_4tech int
|
||||
cursor_seek_step(Seek_State *state, Buffer_Seek seek, int xy_seek, float max_width, float font_height,
|
||||
char *advances, int stride, int size, char ch){
|
||||
Full_Cursor cursor, prev_cursor;
|
||||
float ch_width;
|
||||
int result;
|
||||
float x, px, y;
|
||||
|
||||
cursor = state->cursor;
|
||||
prev_cursor = state->prev_cursor;
|
||||
|
||||
result = 1;
|
||||
prev_cursor = cursor;
|
||||
switch (ch){
|
||||
case '\n':
|
||||
++cursor.line;
|
||||
cursor.unwrapped_y += font_height;
|
||||
cursor.wrapped_y += font_height;
|
||||
cursor.character = 1;
|
||||
cursor.unwrapped_x = 0;
|
||||
cursor.wrapped_x = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
++cursor.character;
|
||||
if (ch == '\r') ch_width = *(float*)(advances + stride * '\\') + *(float*)(advances + stride * 'r');
|
||||
else ch_width = *(float*)(advances + stride * ch);
|
||||
|
||||
if (cursor.wrapped_x + ch_width >= max_width){
|
||||
cursor.wrapped_y += font_height;
|
||||
cursor.wrapped_x = 0;
|
||||
prev_cursor = cursor;
|
||||
}
|
||||
|
||||
cursor.unwrapped_x += ch_width;
|
||||
cursor.wrapped_x += ch_width;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
++cursor.pos;
|
||||
|
||||
if (cursor.pos > size){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
|
||||
x = y = px = 0;
|
||||
|
||||
switch (seek.type){
|
||||
case buffer_seek_pos:
|
||||
if (cursor.pos > seek.pos){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}break;
|
||||
|
||||
case buffer_seek_wrapped_xy:
|
||||
x = cursor.wrapped_x; px = prev_cursor.wrapped_x;
|
||||
y = cursor.wrapped_y; break;
|
||||
|
||||
case buffer_seek_unwrapped_xy:
|
||||
x = cursor.unwrapped_x; px = prev_cursor.unwrapped_x;
|
||||
y = cursor.unwrapped_y; break;
|
||||
|
||||
case buffer_seek_line_char:
|
||||
if (cursor.line == seek.line && cursor.character >= seek.character){
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
else if (cursor.line > seek.line){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}break;
|
||||
}
|
||||
|
||||
if (xy_seek){
|
||||
if (y > seek.y){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
|
||||
if (y > seek.y - font_height && x >= seek.x){
|
||||
if (!seek.round_down){
|
||||
if (ch != '\n' && (seek.x - px) < (x - seek.x)) cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
|
||||
if (x > seek.x){
|
||||
cursor = prev_cursor;
|
||||
result = 0;
|
||||
goto cursor_seek_step_end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cursor_seek_step_end:
|
||||
state->cursor = cursor;
|
||||
state->prev_cursor = prev_cursor;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
typedef struct{
|
||||
int pos, index;
|
||||
} Cursor_With_Index;
|
||||
|
@ -409,11 +301,23 @@ buffer_batch_edit_update_cursors(Cursor_With_Index *sorted_positions, int count,
|
|||
}
|
||||
|
||||
internal_4tech int
|
||||
eol_convert_in(char *data, int size){
|
||||
eol_convert_in(char *dest, char *src, int size){
|
||||
int i, j;
|
||||
|
||||
for (i = 0, j = 0; i < size; ++i, ++j){
|
||||
if (src[i] == '\r' && i+1 < size && src[i+1] == '\n') ++i;
|
||||
dest[j] = src[i];
|
||||
}
|
||||
|
||||
return(j);
|
||||
}
|
||||
|
||||
internal_4tech int
|
||||
eol_in_place_convert_in(char *data, int size){
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; ++i){
|
||||
if (data[i] == '\r' && data[i+1] == '\n'){
|
||||
if (data[i] == '\r' && i+1 < size && data[i+1] == '\n'){
|
||||
memmove_4tech(data + i, data + i + 1, size - i);
|
||||
size -= 1;
|
||||
}
|
||||
|
@ -423,11 +327,34 @@ eol_convert_in(char *data, int size){
|
|||
}
|
||||
|
||||
internal_4tech int
|
||||
eol_convert_out(char *data, int size, int max, int *size_out){
|
||||
eol_convert_out(char *dest, int max, char *src, int size, int *size_out){
|
||||
int result;
|
||||
int i, j;
|
||||
|
||||
// TODO(allen): iterative memory check?
|
||||
result = 1;
|
||||
i = 0;
|
||||
j = 0;
|
||||
|
||||
for (; i < size; ++i, ++j){
|
||||
if (src[i] == '\n'){
|
||||
dest[j] = '\r';
|
||||
++j;
|
||||
dest[j] = '\n';
|
||||
}
|
||||
else dest[j] = src[i];
|
||||
}
|
||||
|
||||
*size_out = j;
|
||||
return(result);
|
||||
}
|
||||
|
||||
internal_4tech int
|
||||
eol_in_place_convert_out(char *data, int size, int max, int *size_out){
|
||||
int result;
|
||||
int i;
|
||||
|
||||
// TODO(allen): iterative memory check
|
||||
// TODO(allen): iterative memory check?
|
||||
result = 1;
|
||||
i = 0;
|
||||
|
||||
|
@ -451,5 +378,10 @@ is_whitespace(char c){
|
|||
return(result);
|
||||
}
|
||||
|
||||
inline_4tech int
|
||||
is_alphanumeric_true(char c){
|
||||
return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
// BOTTOM
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
#define FPS 30
|
||||
#define FRAME_TIME (1000000 / FPS)
|
||||
|
||||
#define BUFFER_EXPERIMENT_SCALPEL 1
|
||||
#define BUFFER_EXPERIMENT_SCALPEL 0
|
||||
|
||||
#include "4ed_meta.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue