Bläddra i källkod

Insert 4 spaces on TAB

rexim 2 år sedan
förälder
incheckning
52c7c6f610
2 ändrade filer med 23 tillägg och 4 borttagningar
  1. 3 0
      src/editor.c
  2. 20 4
      src/main.c

+ 3 - 0
src/editor.c

@@ -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);

+ 20 - 4
src/main.c

@@ -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,
@@ -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;
@@ -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);
@@ -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);
@@ -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