Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/free_glyph.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ void free_glyph_atlas_init(Free_Glyph_Atlas *atlas, FT_Face face)
face->glyph->bitmap.buffer);
x += face->glyph->bitmap.width;
}

// Set tab character metric as 4 times the space metric
Glyph_Metric space_metric = atlas->metrics[(size_t)' '];
atlas->metrics[(size_t)'\t'].ax = space_metric.ax * 4;
atlas->metrics[(size_t)'\t'].ay = space_metric.ay;
atlas->metrics[(size_t)'\t'].bw = space_metric.bw;
atlas->metrics[(size_t)'\t'].bh = space_metric.bh;
atlas->metrics[(size_t)'\t'].bl = space_metric.bl;
atlas->metrics[(size_t)'\t'].bt = space_metric.bt;
atlas->metrics[(size_t)'\t'].tx = space_metric.tx;
}

float free_glyph_atlas_cursor_pos(const Free_Glyph_Atlas *atlas, const char *text, size_t text_size, Vec2f pos, size_t col)
Expand Down
16 changes: 15 additions & 1 deletion src/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ void lexer_chop_char(Lexer *l, size_t len)
l->line += 1;
l->bol = l->cursor;
l->x = 0;
} else if(x == '\t') {
if(l->atlas) {
Glyph_Metric space_metric = l->atlas->metrics[(size_t)' '];
l->x += space_metric.ax * 4;
}
} else {
if (l->atlas) {
size_t glyph_index = x;
Expand All @@ -118,7 +123,9 @@ void lexer_chop_char(Lexer *l, size_t len)

void lexer_trim_left(Lexer *l)
{
while (l->cursor < l->content_len && isspace(l->content[l->cursor])) {
while (l->cursor < l->content_len && isspace(l->content[l->cursor])
&& l->content[l->cursor] != '\t'
) {
lexer_chop_char(l, 1);
}
}
Expand Down Expand Up @@ -146,6 +153,13 @@ Token lexer_next(Lexer *l)

if (l->cursor >= l->content_len) return token;

if (l->content[l->cursor] == '\t') {
token.kind = TOKEN_TAB;
token.text_len = 1;
lexer_chop_char(l, 1);
return token;
}

if (l->content[l->cursor] == '"') {
// TODO: TOKEN_STRING should also handle escape sequences
token.kind = TOKEN_STRING;
Expand Down
1 change: 1 addition & 0 deletions src/lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
typedef enum {
TOKEN_END = 0,
TOKEN_INVALID,
TOKEN_TAB,
TOKEN_PREPROC,
TOKEN_SYMBOL,
TOKEN_OPEN_PAREN,
Expand Down
4 changes: 1 addition & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ int main(int argc, char **argv)
// - tabs/spaces
// - tab width
// - etc.
for (size_t i = 0; i < 4; ++i) {
editor_insert_char(&editor, ' ');
}
editor_insert_char(&editor, '\t');
}
break;

Expand Down