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
11 changes: 11 additions & 0 deletions src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ void editor_move_char_right(Editor *e)
if (e->cursor < e->data.count) e->cursor += 1;
}

void editor_move_char_begin(Editor *e)
{
size_t cursor_row = editor_cursor_row(e);
e->cursor = e->lines.items[cursor_row].begin;
}
void editor_move_char_end(Editor *e)
{
size_t cursor_row = editor_cursor_row(e);
e->cursor = e->lines.items[cursor_row].end;
}

void editor_insert_char(Editor *e, char x)
{
if (e->cursor > e->data.count) {
Expand Down
2 changes: 2 additions & 0 deletions src/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void editor_move_line_up(Editor *e);
void editor_move_line_down(Editor *e);
void editor_move_char_left(Editor *e);
void editor_move_char_right(Editor *e);
void editor_move_char_begin(Editor *e);
void editor_move_char_end(Editor *e);
void editor_insert_char(Editor *e, char x);
void editor_recompute_lines(Editor *e);

Expand Down
28 changes: 28 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,34 @@ int main(int argc, char **argv)

}
break;

case SDLK_HOME: {
editor_move_char_begin(&editor);
cursor_renderer_use(&cr);
glUniform1f(cr.uniforms[UNIFORM_SLOT_LAST_STROKE], (float) SDL_GetTicks() / 1000.0f);

}
break;

case SDLK_END: {
editor_move_char_end(&editor);
cursor_renderer_use(&cr);
glUniform1f(cr.uniforms[UNIFORM_SLOT_LAST_STROKE], (float) SDL_GetTicks() / 1000.0f);

}
break;

case SDLK_TAB: {
const char *text = " ";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it should be similar to SDLK_RETURN and add \t instead of 4 spaces

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but that unfortunately doesn't work. Besides, SDLK_RETURN inserts a '\n'.

size_t text_len = strlen(text);
for (size_t i = 0; i < text_len; ++i) {
editor_insert_char(&editor, text[i]);
}
cursor_renderer_use(&cr);
glUniform1f(cr.uniforms[UNIFORM_SLOT_LAST_STROKE], (float) SDL_GetTicks() / 1000.0f);
}
break;

}
}
break;
Expand Down