Skip to content

Commit

Permalink
Insert 4 spaces on TAB
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Feb 17, 2023
1 parent 9de5ffb commit 52c7c6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ void editor_delete(Editor *e)
editor_retokenize(e);
}

// TODO: make sure that you always have new line at the end of the file while saving
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206

Errno editor_save_as(Editor *e, const char *file_path)
{
printf("Saving as %s...\n", file_path);
Expand Down
24 changes: 20 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
// TODO: Save file dialog
// Needed when ded is ran without any file so it does not know where to save.

// TODO: Jump up/down by paragraph
// TODO: An ability to create a new file
// TODO: Jump up/down by paragraph
// TODO: Delete a word
// TODO: Delete selection
// TODO: Jump to the beginning/end of the line

void MessageCallback(GLenum source,
GLenum type,
Expand Down Expand Up @@ -242,11 +243,11 @@ int main(int argc, char **argv)
if (editor.file_path.count > 0) {
err = editor_save(&editor);
if (err != 0) {
flash_error("Could not save file currently edited file: %s", strerror(err));
flash_error("Could not save currently edited file: %s", strerror(err));
}
} else {
// TODO: ask the user for the path to save to in this situation
flash_error("No where to save the text");
flash_error("Nowhere to save the text");
}
}
break;
Expand Down Expand Up @@ -282,6 +283,19 @@ int main(int argc, char **argv)
}
break;

case SDLK_TAB: {
// TODO: indent on Tab instead of just inserting 4 spaces at the cursor
// That is insert the spaces at the beginning of the line. Shift+TAB should
// do unindent, that is remove 4 spaces from the beginning of the line.
// TODO: customizable indentation style
// - tabs/spaces
// - tab width
// - etc.
for (size_t i = 0; i < 4; ++i) {
editor_insert_char(&editor, ' ');
}
} break;

case SDLK_c: {
if (event.key.keysym.mod & KMOD_CTRL) {
editor_clipboard_copy(&editor);
Expand Down Expand Up @@ -336,7 +350,8 @@ int main(int argc, char **argv)

case SDL_TEXTINPUT: {
if (file_browser) {
// TODO: file browser keys
// Nothing for now
// Once we have incremental search in the file browser this may become useful
} else {
const char *text = event.text.text;
size_t text_len = strlen(text);
Expand Down Expand Up @@ -382,3 +397,4 @@ int main(int argc, char **argv)
// TODO: ability to search within file browser
// Very useful when you have a lot of files
// TODO: ability to search with the text editor
// TODO: ability to remove trailing whitespaces

0 comments on commit 52c7c6f

Please sign in to comment.