diff options
-rw-r--r-- | src/cmds.c | 2 | ||||
-rw-r--r-- | src/cmds_insert.c | 7 | ||||
-rw-r--r-- | src/input.c | 27 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/main.h | 3 |
5 files changed, 33 insertions, 7 deletions
@@ -2,6 +2,7 @@ #include <ctype.h> // for isdigit #include <wchar.h> #include <wctype.h> +#include "main.h" #include "maps.h" #include "yank.h" #include "marks.h" @@ -838,6 +839,7 @@ void center(int sr, int sc, int er, int ec) { } void chg_mode(char strcmd){ + lastmode = curmode; switch (strcmd) { case '=': curmode = INSERT_MODE; diff --git a/src/cmds_insert.c b/src/cmds_insert.c index 6116279..447d0eb 100644 --- a/src/cmds_insert.c +++ b/src/cmds_insert.c @@ -97,7 +97,12 @@ void do_insertmode(struct block * sb) { //ui_show_header(); } else if (sb->value == OKEY_TAB) { // TAB - chg_mode('e'); + if (inputline_pos && wcslen(inputline) >= inputline_pos) { + real_inputline_pos--; + int l = wcwidth(inputline[real_inputline_pos]); + inputline_pos -= l; + } + chg_mode(insert_edit_submode == '=' ? 'e' : 'E'); ui_show_header(); } else if (find_val(sb, OKEY_ENTER)) { // ENTER diff --git a/src/input.c b/src/input.c index 9e7902d..e0871f8 100644 --- a/src/input.c +++ b/src/input.c @@ -5,6 +5,7 @@ #include <wchar.h> #include <wctype.h> +#include "main.h" #include "tui.h" #include "maps.h" #include "cmds.h" @@ -21,7 +22,6 @@ int cmd_multiplier = 0; // Multiplier int cmd_pending = 0; // Command pending int shall_quit; // Break loop if ESC key is pressed - /* * Reads stdin for a valid command. * Details: Read characters from stdin to a input buffer. @@ -129,13 +129,28 @@ void break_waitcmd_loop(struct block * buffer) { } else if (curmode == VISUAL_MODE) { exit_visualmode(); } - - chg_mode('.'); + if (curmode == INSERT_MODE && lastmode == EDIT_MODE) { + if (inputline_pos && wcslen(inputline) >= inputline_pos) { + real_inputline_pos--; + int l = wcwidth(inputline[real_inputline_pos]); + inputline_pos -= l; + } + chg_mode(insert_edit_submode == '=' ? 'e' : 'E'); + lastmode=NORMAL_MODE; + ui_show_header(); + } else if (curmode == EDIT_MODE && lastmode == INSERT_MODE) { + chg_mode(insert_edit_submode); + lastmode=NORMAL_MODE; + ui_show_header(); + } else { + chg_mode('.'); + lastmode=NORMAL_MODE; + inputline[0] = L'\0'; // clean inputline + flush_buf(buffer); + ui_update(TRUE); + } cmd_pending = 0; // No longer wait for command. Set flag. cmd_multiplier = 0; // Reset the multiplier - inputline[0] = L'\0'; // clean inputline - flush_buf(buffer); - ui_update(TRUE); return; } @@ -49,6 +49,7 @@ int modflg; // a change was made since last save struct ent *** tbl; int shall_quit = 0; unsigned int curmode; +unsigned int lastmode; int maxrow, maxcol; char curfile[PATHLEN]; char * exepath; @@ -15,3 +15,6 @@ void sig_int(); void winchg(); extern FILE * fdoutput; // output file descriptor (stdout or file) +extern unsigned int curmode; +extern unsigned int lastmode; + |