From: David Lawrence Ramsey Date: Tue, 11 Jan 2005 23:05:05 +0000 (+0000) Subject: miscellaneous high-level input routine fixes: in do_statusbar_input(), X-Git-Tag: v1.3.6~156 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=cac0293bce6feb61f64b686576dbb786f6141294;p=nano.git miscellaneous high-level input routine fixes: in do_statusbar_input(), indicate when we run a normal shortcut's associated function with the ran_func parameter, reset the statusbar cursor position when we do, and don't call print_view_warning() when we try to run a function not allowed in view mode; also apply the first of these changes to do_input() so that both the edit window and statusbar routines are in sync again git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2246 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/src/nano.c b/src/nano.c index 5027dd38..ade57e4d 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2717,7 +2717,7 @@ void do_justify(bool full_justify) size_t mark_beginx_save = mark_beginx; #endif int kbinput; - bool meta_key, func_key, s_or_t, finished; + bool meta_key, func_key, s_or_t, ran_func, finished; /* If we're justifying the entire file, start at the beginning. */ if (full_justify) @@ -2983,7 +2983,8 @@ void do_justify(bool full_justify) /* Now get a keystroke and see if it's unjustify. If not, put back * the keystroke and return. */ - kbinput = do_input(&meta_key, &func_key, &s_or_t, &finished, FALSE); + kbinput = do_input(&meta_key, &func_key, &s_or_t, &ran_func, + &finished, FALSE); if (!meta_key && !func_key && s_or_t && kbinput == NANO_UNJUSTIFY_KEY) { @@ -3385,7 +3386,7 @@ void terminal_init(void) } int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool - *finished, bool allow_funcs) + *ran_func, bool *finished, bool allow_funcs) { int input; /* The character we read in. */ @@ -3401,6 +3402,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool #endif *s_or_t = FALSE; + *ran_func = FALSE; *finished = FALSE; /* Read in a character. */ @@ -3492,8 +3494,9 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool break; #endif /* Handle the normal edit window shortcuts, setting - * finished to TRUE to indicate that we're done after - * running or trying to run their associated + * ran_func to TRUE if we try to run their associated + * functions and setting finished to TRUE to indicate + * that we're done after trying to run their associated * functions. */ default: /* Blow away the text in the cutbuffer if we aren't @@ -3502,6 +3505,7 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool cutbuffer_reset(); if (s->func != NULL) { + *ran_func = TRUE; if (ISSET(VIEW_MODE) && !s->viewok) print_view_warning(); else @@ -4219,15 +4223,7 @@ int main(int argc, char **argv) edit_refresh(); while (TRUE) { - bool meta_key; - /* Whether we got a meta key sequence. */ - bool func_key; - /* Whether we got a function key. */ - bool s_or_t; - /* Whether we got a shortcut or toggle. */ - bool ran_s_or_t; - /* Whether we ran a function associated with a - * shortcut. */ + bool meta_key, func_key, s_or_t, ran_func, finished; /* Make sure the cursor is in the edit window. */ reset_cursor(); @@ -4240,7 +4236,8 @@ int main(int argc, char **argv) currshortcut = main_list; /* Read in and interpret characters. */ - do_input(&meta_key, &func_key, &s_or_t, &ran_s_or_t, TRUE); + do_input(&meta_key, &func_key, &s_or_t, &ran_func, &finished, + TRUE); } assert(FALSE); } diff --git a/src/proto.h b/src/proto.h index 5c8e560a..7dc6ce79 100644 --- a/src/proto.h +++ b/src/proto.h @@ -392,7 +392,7 @@ void disable_flow_control(void); void enable_flow_control(void); void terminal_init(void); int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool - *finished, bool allow_funcs); + *ran_func, bool *finished, bool allow_funcs); #ifndef DISABLE_MOUSE bool do_mouse(void); #endif @@ -578,7 +578,7 @@ const shortcut *get_shortcut(const shortcut *s_list, int *kbinput, bool const toggle *get_toggle(int kbinput, bool meta_key); #endif int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t, - bool *finished, bool allow_funcs); + bool *ran_func, bool *finished, bool allow_funcs); #ifndef DISABLE_MOUSE bool do_statusbar_mouse(void); #endif diff --git a/src/winio.c b/src/winio.c index 0ac50dee..cb2df9af 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1724,7 +1724,7 @@ const toggle *get_toggle(int kbinput, bool meta_key) #endif /* !NANO_SMALL */ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t, - bool *finished, bool allow_funcs) + bool *ran_func, bool *finished, bool allow_funcs) { int input; /* The character we read in. */ @@ -1736,6 +1736,7 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t, bool have_shortcut; *s_or_t = FALSE; + *ran_func = FALSE; *finished = FALSE; /* Read in a character. */ @@ -1865,14 +1866,14 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *s_or_t, break; } /* Handle the normal statusbar prompt shortcuts, setting - * finished to TRUE to indicate that we're done after - * running or trying to run their associated + * ran_func to TRUE if we try to run their associated + * functions and setting finished to TRUE to indicate + * that we're done after trying to run their associated * functions. */ default: if (s->func != NULL) { - if (ISSET(VIEW_MODE) && !s->viewok) - print_view_warning(); - else + *ran_func = TRUE; + if (!ISSET(VIEW_MODE) || s->viewok) s->func(); } *finished = TRUE; @@ -2422,7 +2423,7 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *def, ) { int kbinput; - bool meta_key, func_key, s_or_t, finished; + bool meta_key, func_key, s_or_t, ran_func, finished; bool tabbed = FALSE; /* used by input_tab() */ @@ -2474,11 +2475,12 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *def, * disable all keys that would change the text if the filename isn't * blank and we're at the "Write File" prompt. */ while ((kbinput = do_statusbar_input(&meta_key, &func_key, - &s_or_t, &finished, TRUE)) != NANO_CANCEL_KEY && + &s_or_t, &ran_func, &finished, TRUE)) != NANO_CANCEL_KEY && kbinput != NANO_ENTER_KEY) { /* If we have a shortcut with an associated function, break out - * if we're finished after running the function. */ + * if we're finished after running or trying to run the + * function. */ if (finished) break; @@ -2617,8 +2619,10 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *def, wrefresh(bottomwin); } - /* We finished putting in an answer, so reset statusbar_x. */ - if (kbinput == NANO_CANCEL_KEY || kbinput == NANO_ENTER_KEY) + /* We finished putting in an answer or ran a normal shortcut's + * associated function, so reset statusbar_x. */ + if (kbinput == NANO_CANCEL_KEY || kbinput == NANO_ENTER_KEY || + ran_func) statusbar_x = (size_t)-1; return kbinput;