tweaks to the existing wrap rules
This commit is contained in:
parent
7ac01f5918
commit
94c624a505
6
4ed.cpp
6
4ed.cpp
|
@ -650,7 +650,9 @@ COMMAND_DECL(close_panel){
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
panel_ptr = panel->next;
|
panel_ptr = panel->next;
|
||||||
if (panel_ptr == &models->layout.used_sentinel) panel_ptr = panel_ptr->next;
|
if (panel_ptr == &models->layout.used_sentinel){
|
||||||
|
panel_ptr = panel_ptr->next;
|
||||||
|
}
|
||||||
Assert(panel_ptr != panel);
|
Assert(panel_ptr != panel);
|
||||||
active = (i32)(panel_ptr - models->layout.panels);
|
active = (i32)(panel_ptr - models->layout.panels);
|
||||||
}
|
}
|
||||||
|
@ -732,7 +734,6 @@ command_caller(Coroutine *coroutine){
|
||||||
Models *models = command->models;
|
Models *models = command->models;
|
||||||
USE_VIEW(view);
|
USE_VIEW(view);
|
||||||
|
|
||||||
view->next_mode = view_mode_zero();
|
|
||||||
if (models->command_caller){
|
if (models->command_caller){
|
||||||
Generic_Command generic;
|
Generic_Command generic;
|
||||||
if (cmd_in->bind.function == command_user_callback){
|
if (cmd_in->bind.function == command_user_callback){
|
||||||
|
@ -747,7 +748,6 @@ command_caller(Coroutine *coroutine){
|
||||||
else{
|
else{
|
||||||
cmd_in->bind.function(command->system, command, cmd_in->bind);
|
cmd_in->bind.function(command->system, command, cmd_in->bind);
|
||||||
}
|
}
|
||||||
view->mode = view->next_mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
|
|
@ -120,15 +120,6 @@ enum Interactive_Interaction{
|
||||||
IInt_Sure_To_Close
|
IInt_Sure_To_Close
|
||||||
};
|
};
|
||||||
|
|
||||||
struct View_Mode{
|
|
||||||
i32 rewrite;
|
|
||||||
};
|
|
||||||
inline View_Mode
|
|
||||||
view_mode_zero(){
|
|
||||||
View_Mode mode={0};
|
|
||||||
return(mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum View_UI{
|
enum View_UI{
|
||||||
VUI_None,
|
VUI_None,
|
||||||
VUI_Theme,
|
VUI_Theme,
|
||||||
|
@ -161,11 +152,7 @@ struct File_Viewing_Data{
|
||||||
b32 show_whitespace;
|
b32 show_whitespace;
|
||||||
b32 file_locked;
|
b32 file_locked;
|
||||||
};
|
};
|
||||||
inline File_Viewing_Data
|
static File_Viewing_Data null_file_viewing_data = {0};
|
||||||
file_viewing_data_zero(){
|
|
||||||
File_Viewing_Data data={0};
|
|
||||||
return(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Scroll_Context{
|
struct Scroll_Context{
|
||||||
Editing_File *file;
|
Editing_File *file;
|
||||||
|
@ -260,7 +247,6 @@ struct View{
|
||||||
i32 line_height;
|
i32 line_height;
|
||||||
|
|
||||||
// TODO(allen): Do I still use mode?
|
// TODO(allen): Do I still use mode?
|
||||||
View_Mode mode, next_mode;
|
|
||||||
Query_Set query_set;
|
Query_Set query_set;
|
||||||
f32 widget_height;
|
f32 widget_height;
|
||||||
|
|
||||||
|
@ -1206,16 +1192,45 @@ wrap_state_consume_token(Code_Wrap_State *state, i32 fixed_end_point){
|
||||||
}
|
}
|
||||||
|
|
||||||
internal i32
|
internal i32
|
||||||
stickieness_guess(Cpp_Token_Type type, b32 on_left){
|
stickieness_guess(Cpp_Token_Type type, Cpp_Token_Type other_type, b32 on_left, b32 in_parens){
|
||||||
i32 guess = 0;
|
i32 guess = 0;
|
||||||
|
|
||||||
if (type == CPP_TOKEN_SEMICOLON ||
|
b32 is_words = 0, other_is_words = 0;
|
||||||
type == CPP_TOKEN_COLON ||
|
if (type == CPP_TOKEN_IDENTIFIER || (type >= CPP_TOKEN_KEY_TYPE && type <= CPP_TOKEN_KEY_OTHER)){
|
||||||
type == CPP_TOKEN_PARENTHESE_OPEN ||
|
is_words = 1;
|
||||||
|
}
|
||||||
|
if (other_type == CPP_TOKEN_IDENTIFIER || (other_type >= CPP_TOKEN_KEY_TYPE && other_type <= CPP_TOKEN_KEY_OTHER)){
|
||||||
|
other_is_words = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 operator_side_bias = 70*(!on_left);
|
||||||
|
|
||||||
|
if (is_words && other_is_words){
|
||||||
|
guess = 200;
|
||||||
|
}
|
||||||
|
else if (type == CPP_TOKEN_PARENTHESE_OPEN){
|
||||||
|
if (on_left){
|
||||||
|
guess = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (other_type == CPP_TOKEN_IDENTIFIER){
|
||||||
|
guess = 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == CPP_TOKEN_SEMICOLON){
|
||||||
|
if (on_left){
|
||||||
|
guess = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
guess = 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == CPP_TOKEN_COLON ||
|
||||||
type == CPP_TOKEN_PARENTHESE_CLOSE ||
|
type == CPP_TOKEN_PARENTHESE_CLOSE ||
|
||||||
|
type == CPP_TOKEN_COMMA ||
|
||||||
type == CPP_TOKEN_BRACKET_OPEN ||
|
type == CPP_TOKEN_BRACKET_OPEN ||
|
||||||
type == CPP_TOKEN_BRACKET_CLOSE ||
|
type == CPP_TOKEN_BRACKET_CLOSE){
|
||||||
type == CPP_TOKEN_COMMA){
|
|
||||||
if (on_left){
|
if (on_left){
|
||||||
guess = 0;
|
guess = 0;
|
||||||
}
|
}
|
||||||
|
@ -1255,19 +1270,33 @@ stickieness_guess(Cpp_Token_Type type, b32 on_left){
|
||||||
guess = 70;
|
guess = 70;
|
||||||
}
|
}
|
||||||
else if (type == CPP_TOKEN_PLUS){
|
else if (type == CPP_TOKEN_PLUS){
|
||||||
guess = 60;
|
guess = 60 + operator_side_bias;
|
||||||
}
|
}
|
||||||
else if (type >= CPP_TOKEN_LSHIFT && type <= CPP_TOKEN_RSHIFT){
|
else if (type >= CPP_TOKEN_LSHIFT && type <= CPP_TOKEN_RSHIFT){
|
||||||
guess = 50;
|
guess = 50;
|
||||||
}
|
}
|
||||||
else if (type >= CPP_TOKEN_LESS && type <= CPP_TOKEN_NOTEQ){
|
else if (type >= CPP_TOKEN_LESS && type <= CPP_TOKEN_NOTEQ){
|
||||||
|
guess = 40 + operator_side_bias;
|
||||||
|
}
|
||||||
|
else if (type >= CPP_TOKEN_BIT_XOR && type <= CPP_TOKEN_BIT_OR){
|
||||||
guess = 40;
|
guess = 40;
|
||||||
}
|
}
|
||||||
else if (type >= CPP_TOKEN_BIT_XOR && type <= CPP_TOKEN_OR){
|
else if (type >= CPP_TOKEN_AND && type <= CPP_TOKEN_OR){
|
||||||
guess = 20;
|
guess = 30 + operator_side_bias;
|
||||||
}
|
}
|
||||||
else if (type >= CPP_TOKEN_TERNARY_QMARK && type <= CPP_TOKEN_XOREQ){
|
else if (type >= CPP_TOKEN_TERNARY_QMARK && type <= CPP_TOKEN_COLON){
|
||||||
guess = 10;
|
guess = 20 + operator_side_bias;
|
||||||
|
}
|
||||||
|
else if (type == CPP_TOKEN_THROW){
|
||||||
|
if (on_left){
|
||||||
|
guess = 100;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
guess = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type >= CPP_TOKEN_EQ && type <= CPP_TOKEN_XOREQ){
|
||||||
|
guess = 15 + operator_side_bias;
|
||||||
}
|
}
|
||||||
|
|
||||||
return(guess);
|
return(guess);
|
||||||
|
@ -1498,6 +1527,9 @@ file_measure_wraps(Models *models, Editing_File *file, f32 font_height, f32 *adv
|
||||||
Cpp_Token *this_token = step.this_token;
|
Cpp_Token *this_token = step.this_token;
|
||||||
Cpp_Token *next_token = wrap_state.token_ptr;
|
Cpp_Token *next_token = wrap_state.token_ptr;
|
||||||
|
|
||||||
|
Cpp_Token_Type this_type = this_token->type;
|
||||||
|
Cpp_Token_Type next_type = CPP_TOKEN_JUNK;
|
||||||
|
|
||||||
if (this_token == next_token){
|
if (this_token == next_token){
|
||||||
next_token = 0;
|
next_token = 0;
|
||||||
}
|
}
|
||||||
|
@ -1506,29 +1538,29 @@ file_measure_wraps(Models *models, Editing_File *file, f32 font_height, f32 *adv
|
||||||
next_token = 0;
|
next_token = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
i32 this_stickieness = stickieness_guess(this_token->type, 1);
|
|
||||||
i32 general_stickieness = this_stickieness;
|
|
||||||
i32 next_stickieness = 0;
|
|
||||||
|
|
||||||
if (next_token){
|
if (next_token){
|
||||||
next_stickieness = stickieness_guess(next_token->type, 0);
|
next_type = next_token->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b32 in_parens = wrap_state.paren_top == 0;
|
||||||
|
i32 this_stickieness = stickieness_guess(this_type, next_type, 1, in_parens);
|
||||||
|
|
||||||
|
i32 next_stickieness = 0;
|
||||||
|
if (next_token){
|
||||||
|
next_stickieness = stickieness_guess(next_type, this_type, 0, in_parens);
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 general_stickieness = this_stickieness;
|
||||||
if (general_stickieness < next_stickieness){
|
if (general_stickieness < next_stickieness){
|
||||||
general_stickieness = next_stickieness;
|
general_stickieness = next_stickieness;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrappable_score = 64*50;
|
wrappable_score = 64*50;
|
||||||
if (wrap_state.paren_top == 0){
|
if (in_parens){
|
||||||
wrappable_score += 101 - general_stickieness;
|
wrappable_score += 101 - general_stickieness;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (this_token->type == CPP_TOKEN_COMMA){
|
wrappable_score += 101 - general_stickieness - wrap_state.paren_safe_top*80;
|
||||||
wrappable_score += 401 - wrap_state.paren_safe_top*20;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
wrappable_score += 101 - general_stickieness - wrap_state.paren_safe_top*20;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
potential_marks[potential_count].wrap_position = wrap_position;
|
potential_marks[potential_count].wrap_position = wrap_position;
|
||||||
|
@ -1554,7 +1586,9 @@ file_measure_wraps(Models *models, Editing_File *file, f32 font_height, f32 *adv
|
||||||
for (; i < potential_count; ++i){
|
for (; i < potential_count; ++i){
|
||||||
i32 this_score = potential_marks[i].wrappable_score;
|
i32 this_score = potential_marks[i].wrappable_score;
|
||||||
f32 x_shift = potential_marks[i].start_x - potential_marks[i].line_shift;
|
f32 x_shift = potential_marks[i].start_x - potential_marks[i].line_shift;
|
||||||
if (x_shift < x_gain_threshold){
|
|
||||||
|
f32 x_shift_adjusted = x_shift - x_gain_threshold;
|
||||||
|
if (x_shift_adjusted < 0){
|
||||||
this_score = 0;
|
this_score = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2385,7 +2419,7 @@ file_post_history(General_Memory *general, Editing_File *file,
|
||||||
// TODO(allen): burn this shit to the ground yo!
|
// TODO(allen): burn this shit to the ground yo!
|
||||||
inline void
|
inline void
|
||||||
file_view_nullify_file(View *view){
|
file_view_nullify_file(View *view){
|
||||||
view->file_data = file_viewing_data_zero();
|
view->file_data = null_file_viewing_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
internal void
|
||||||
|
|
3
TODO.txt
3
TODO.txt
|
@ -93,6 +93,8 @@
|
||||||
; [] API docs have duplicate ids?
|
; [] API docs have duplicate ids?
|
||||||
; [] query buffer font info
|
; [] query buffer font info
|
||||||
; [] option to not open *messages* every startup
|
; [] option to not open *messages* every startup
|
||||||
|
; [] issues with drive letters
|
||||||
|
; [] strong options for indentation rules for text & presentation
|
||||||
;
|
;
|
||||||
|
|
||||||
; TODOS
|
; TODOS
|
||||||
|
@ -176,6 +178,7 @@
|
||||||
; [] handle unclosed statements
|
; [] handle unclosed statements
|
||||||
; [] handle comments
|
; [] handle comments
|
||||||
; [] fix issues when relexing happens in parallel
|
; [] fix issues when relexing happens in parallel
|
||||||
|
; [] additional width for nesting?
|
||||||
; [] remeasure version of measure_wraps
|
; [] remeasure version of measure_wraps
|
||||||
|
|
||||||
; Buffer behavior cleanup
|
; Buffer behavior cleanup
|
||||||
|
|
Loading…
Reference in New Issue