tweaks: factor out the check for 'viewok' into its own function
And also prevent a theoretical crash for restricted prompt functions.master
parent
b830a7dd38
commit
8b8c6bb818
18
src/nano.c
18
src/nano.c
|
@ -1636,6 +1636,14 @@ bool wanted_to_move(void (*func)(void))
|
||||||
func == to_first_line || func == to_last_line;
|
func == to_first_line || func == to_last_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return TRUE when the given shortcut is valid in view mode. */
|
||||||
|
bool okay_for_view(const sc *shortcut)
|
||||||
|
{
|
||||||
|
const subnfunc *func = sctofunc(shortcut);
|
||||||
|
|
||||||
|
return (func && func->viewok);
|
||||||
|
}
|
||||||
|
|
||||||
/* Read in a keystroke. Act on the keystroke if it is a shortcut or a toggle;
|
/* Read in a keystroke. Act on the keystroke if it is a shortcut or a toggle;
|
||||||
* otherwise, insert it into the edit buffer. If allow_funcs is FALSE, don't
|
* otherwise, insert it into the edit buffer. If allow_funcs is FALSE, don't
|
||||||
* do anything with the keystroke -- just return it. */
|
* do anything with the keystroke -- just return it. */
|
||||||
|
@ -1727,13 +1735,10 @@ int do_input(bool allow_funcs)
|
||||||
if (shortcut == NULL)
|
if (shortcut == NULL)
|
||||||
pletion_line = NULL;
|
pletion_line = NULL;
|
||||||
else {
|
else {
|
||||||
if (ISSET(VIEW_MODE)) {
|
if (ISSET(VIEW_MODE) && !okay_for_view(shortcut)) {
|
||||||
const subnfunc *f = sctofunc(shortcut);
|
|
||||||
if (f && !f->viewok) {
|
|
||||||
print_view_warning();
|
print_view_warning();
|
||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* If the function associated with this shortcut is
|
/* If the function associated with this shortcut is
|
||||||
* cutting or copying text, remember this. */
|
* cutting or copying text, remember this. */
|
||||||
|
@ -1804,11 +1809,8 @@ int do_input(bool allow_funcs)
|
||||||
wrap_reset();
|
wrap_reset();
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
if (!refresh_needed) {
|
if (!refresh_needed && !okay_for_view(shortcut))
|
||||||
const subnfunc *f = sctofunc(shortcut);
|
|
||||||
if (f && !f->viewok)
|
|
||||||
check_the_multis(openfile->current);
|
check_the_multis(openfile->current);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (!refresh_needed && (shortcut->func == do_delete ||
|
if (!refresh_needed && (shortcut->func == do_delete ||
|
||||||
shortcut->func == do_backspace))
|
shortcut->func == do_backspace))
|
||||||
|
|
|
@ -171,7 +171,7 @@ int do_statusbar_input(bool *finished)
|
||||||
/* Handle any other shortcut in the current menu, setting finished
|
/* Handle any other shortcut in the current menu, setting finished
|
||||||
* to TRUE to indicate that we're done after running or trying to
|
* to TRUE to indicate that we're done after running or trying to
|
||||||
* run its associated function. */
|
* run its associated function. */
|
||||||
if (!ISSET(VIEW_MODE) || sctofunc(shortcut)->viewok)
|
if (!ISSET(VIEW_MODE) || okay_for_view(shortcut))
|
||||||
shortcut->func();
|
shortcut->func();
|
||||||
*finished = TRUE;
|
*finished = TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -439,6 +439,7 @@ void disable_flow_control(void);
|
||||||
void enable_flow_control(void);
|
void enable_flow_control(void);
|
||||||
void terminal_init(void);
|
void terminal_init(void);
|
||||||
void unbound_key(int code);
|
void unbound_key(int code);
|
||||||
|
bool okay_for_view(const sc *shortcut);
|
||||||
int do_input(bool allow_funcs);
|
int do_input(bool allow_funcs);
|
||||||
void do_output(char *output, size_t output_len, bool allow_cntrls);
|
void do_output(char *output, size_t output_len, bool allow_cntrls);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue