Show whitespace

This commit is contained in:
Allen Webster 2020-02-07 17:37:10 -08:00
parent 3ef04faead
commit d05a3f6a0d
4 changed files with 88 additions and 12 deletions

View File

@ -1639,15 +1639,31 @@ CUSTOM_DOC("Parse the current buffer as a theme file and add the theme to the th
String_Const_u8 error_text = config_stringize_errors(app, scratch, config);
print_message(app, error_text);
String_Const_u8 name = string_front_of_path(file_name);
if (string_match(string_postfix(name, 7), string_u8_litexpr(".4coder"))){
name = string_chop(name, 7);
u64 problem_score = 0;
if (color_table.count < defcolor_line_numbers_text){
problem_score = defcolor_line_numbers_text - color_table.count;
}
for (u32 i = 0; i < color_table.count; i += 1){
if (color_table.arrays[i].count == 0){
problem_score += 1;
}
}
save_theme(color_table, name);
Color_Table_Node *node = global_theme_list.last;
if (node != 0 && string_match(node->name, name)){
active_color_table = node->table;
if (error_text.size > 0 || problem_score >= 10){
String_Const_u8 string = push_u8_stringf(scratch, "There appears to be a problem parsing %.*s; no theme change applied\n", string_expand(file_name));
print_message(app, string);
}
else{
String_Const_u8 name = string_front_of_path(file_name);
if (string_match(string_postfix(name, 7), string_u8_litexpr(".4coder"))){
name = string_chop(name, 7);
}
save_theme(color_table, name);
Color_Table_Node *node = global_theme_list.last;
if (node != 0 && string_match(node->name, name)){
active_color_table = node->table;
}
}
}
}

View File

@ -288,6 +288,13 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id,
b32 is_active_view = (active_view == view_id);
Rect_f32 prev_clip = draw_set_clip(app, rect);
Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
// NOTE(allen): Cursor shape
Face_Metrics metrics = get_face_metrics(app, face_id);
f32 cursor_roundness = (metrics.normal_advance*0.5f)*0.9f;
f32 mark_thickness = 2.f;
// NOTE(allen): Token colorizing
Token_Array token_array = get_token_array_from_buffer(app, buffer);
if (token_array.tokens != 0){
@ -304,7 +311,6 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id,
}
}
else{
Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
paint_text_color_fcolor(app, text_layout_id, visible_range, fcolor_id(defcolor_text_default));
}
@ -349,10 +355,17 @@ default_render_buffer(Application_Links *app, View_ID view_id, Face_ID face_id,
fcolor_id(defcolor_highlight_cursor_line));
}
// NOTE(allen): Cursor shape
Face_Metrics metrics = get_face_metrics(app, face_id);
f32 cursor_roundness = (metrics.normal_advance*0.5f)*0.9f;
f32 mark_thickness = 2.f;
// NOTE(allen): Whitespace highlight
b64 show_whitespace = false;
view_get_setting(app, view_id, ViewSetting_ShowWhitespace, &show_whitespace);
if (show_whitespace){
if (token_array.tokens == 0){
draw_whitespace_highlight(app, buffer, text_layout_id, cursor_roundness);
}
else{
draw_whitespace_highlight(app, text_layout_id, &token_array, cursor_roundness);
}
}
// NOTE(allen): Cursor
switch (fcoder_mode){

View File

@ -520,6 +520,51 @@ draw_cpp_token_colors(Application_Links *app, Text_Layout_ID text_layout_id, Tok
}
}
function void
draw_whitespace_highlight(Application_Links *app, Text_Layout_ID text_layout_id, Token_Array *array, f32 roundness){
Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
i64 first_index = token_index_from_pos(array, visible_range.first);
Token_Iterator_Array it = token_iterator_index(0, array, first_index);
for (;;){
Token *token = token_it_read(&it);
if (token->pos >= visible_range.one_past_last){
break;
}
if (token->kind == TokenBaseKind_Whitespace){
Range_i64 range = Ii64(token);
draw_character_block(app, text_layout_id, range, roundness,
fcolor_id(defcolor_highlight_white));
}
if (!token_it_inc_all(&it)){
break;
}
}
}
function void
draw_whitespace_highlight(Application_Links *app, Buffer_ID buffer, Text_Layout_ID text_layout_id, f32 roundness){
Range_i64 visible_range = text_layout_get_visible_range(app, text_layout_id);
for (i64 i = visible_range.first; i < visible_range.one_past_last;){
u8 c = buffer_get_char(app, buffer, i);
if (character_is_whitespace(c)){
i64 s = i;
i += 1;
for (; i < visible_range.one_past_last; i += 1){
c = buffer_get_char(app, buffer, i);
if (!character_is_whitespace(c)){
break;
}
}
Range_i64 range = Ii64(s, i);
draw_character_block(app, text_layout_id, range, roundness,
fcolor_id(defcolor_highlight_white));
}
else{
i += 1;
}
}
}
function void
draw_comment_highlights(Application_Links *app, Buffer_ID buffer, Text_Layout_ID text_layout_id,
Token_Array *array, Comment_Highlight_Pair *pairs, i32 pair_count){

View File

@ -4,9 +4,11 @@
+ clipboard is only read when the requests to, or when the collect-all mode is started via the command 'begin_clipboard_collection_mode'
+ 'clear_clipboard' command
+ in config.4coder the variable virtual_whitespace_regular_indent determines the number of space-widths to use as the regular indentation in a virtual whitespace layout
+ show whitespace mode implemented in 'default_render_buffer'
+ Fix: tabs are measured with the correct amount of width for the user's settings
+ Fix: virtual whitespace toggling works when the config initially diabled virtual whitespace
+ Fix: never miss the most recent post to the clipboard on windows
+ Fix: command `load_theme_current_buffer` gaurds against destroying the active color palette when bad files are loaded
4.1.3
+ Unkillable buffer setting