From: Daniel Carl Date: Sat, 23 Feb 2013 10:41:27 +0000 (+0100) Subject: Moved mode switching to command also if command not found. X-Git-Url: https://git.owens.tech/dummy.html/dummy.html/git?a=commitdiff_plain;h=9d0f5699e3c0985131ef4967d4c83d45646662c9;p=vimb.git Moved mode switching to command also if command not found. This make the mode switching more unique. If command_run is called, this will switch to the right mode, independent if the command exists or could be run or not. --- diff --git a/src/command.c b/src/command.c index 12e2580..900f8ce 100644 --- a/src/command.c +++ b/src/command.c @@ -124,6 +124,8 @@ gboolean command_run(const char* name, const char* param) c = g_hash_table_lookup(vp.behave.commands, name); if (!c) { vp_echo(VP_MSG_ERROR, TRUE, "Command '%s' not found", name); + vp_set_mode(VP_MODE_NORMAL, FALSE); + return FALSE; } a.i = c->arg.i; @@ -531,7 +533,7 @@ gboolean command_history(const Arg* arg) const int len = g_list_length(state->history); char* message = NULL; const int count = state->count ? state->count : 1; - + if (!len) { return FALSE; } @@ -540,7 +542,7 @@ gboolean command_history(const Arg* arg) } else { state->history_pointer = (len + state->history_pointer + count) % len; } - + const char* command = (char*)g_list_nth_data(state->history, state->history_pointer); message = g_strconcat(arg->s, command, NULL); command_write_input(message); diff --git a/src/main.c b/src/main.c index 65f6a15..2bb47a7 100644 --- a/src/main.c +++ b/src/main.c @@ -152,7 +152,6 @@ static void vp_destroy_window_cb(GtkWidget* widget, GtkWidget* window, gpointer static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data) { - gboolean success = FALSE; const char *text; guint16 length = gtk_entry_get_text_length(entry); Gui* gui = &vp.gui; @@ -182,13 +181,8 @@ static void vp_inputbox_activate_cb(GtkEntry *entry, gpointer user_data) case ':': completion_clean(); - success = vp_process_input((text + 1)); - if (!success) { - /* switch to normal mode after running command without success the - * mode after success is set by command_run to the value defined - * for the command */ - vp_set_mode(VP_MODE_NORMAL, FALSE); - } + vp_process_input((text + 1)); + /* save the command in history */ history_append((text + 1));