summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cmds.c2
-rw-r--r--src/cmds_insert.c7
-rw-r--r--src/input.c27
-rw-r--r--src/main.c1
-rw-r--r--src/main.h3
5 files changed, 33 insertions, 7 deletions
diff --git a/src/cmds.c b/src/cmds.c
index 86e0a61..dd07347 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -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;
}
diff --git a/src/main.c b/src/main.c
index ad39e6e..75bf151 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
diff --git a/src/main.h b/src/main.h
index 1887902..e967162 100644
--- a/src/main.h
+++ b/src/main.h
@@ -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;
+