From cdc9a29598f6aa6361666fd8e85ccedcff6efbf5 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sat, 27 Jan 2018 19:33:03 +0100 Subject: [PATCH] tweaks: move two functions to their proper place, orderingwise --- src/nano.c | 108 +++++++++++++++++++++++++-------------------------- src/prompt.c | 50 ++++++++++++------------ src/proto.h | 6 --- 3 files changed, 78 insertions(+), 86 deletions(-) diff --git a/src/nano.c b/src/nano.c index a3c333f9..e015423b 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1560,6 +1560,60 @@ void unbound_key(int code) statusline(ALERT, _("Unbound key: %c"), code); } +#ifdef ENABLE_MOUSE +/* Handle a mouse click on the edit window or the shortcut list. */ +int do_mouse(void) +{ + int mouse_col, mouse_row; + int retval = get_mouseinput(&mouse_col, &mouse_row, TRUE); + + /* If the click is wrong or already handled, we're done. */ + if (retval != 0) + return retval; + + /* If the click was in the edit window, put the cursor in that spot. */ + if (wmouse_trafo(edit, &mouse_row, &mouse_col, FALSE)) { + filestruct *current_save = openfile->current; + ssize_t row_count = mouse_row - openfile->current_y; + size_t leftedge; +#ifndef NANO_TINY + size_t current_x_save = openfile->current_x; + bool sameline = (mouse_row == openfile->current_y); + /* Whether the click was on the row where the cursor is. */ + + if (ISSET(SOFTWRAP)) + leftedge = leftedge_for(xplustabs(), openfile->current); + else +#endif + leftedge = get_page_start(xplustabs()); + + /* Move current up or down to the row corresponding to mouse_row. */ + if (row_count < 0) + go_back_chunks(-row_count, &openfile->current, &leftedge); + else + go_forward_chunks(row_count, &openfile->current, &leftedge); + + openfile->current_x = actual_x(openfile->current->data, + actual_last_column(leftedge, mouse_col)); + +#ifndef NANO_TINY + /* Clicking where the cursor is toggles the mark, as does clicking + * beyond the line length with the cursor at the end of the line. */ + if (sameline && openfile->current_x == current_x_save) + do_mark(); + else +#endif + /* The cursor moved; clean the cutbuffer on the next cut. */ + cutbuffer_reset(); + + edit_redraw(current_save, CENTERING); + } + + /* No more handling is needed. */ + return 2; +} +#endif /* ENABLE_MOUSE */ + /* 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 * do anything with the keystroke -- just return it. */ @@ -1735,60 +1789,6 @@ int do_input(bool allow_funcs) return input; } -#ifdef ENABLE_MOUSE -/* Handle a mouse click on the edit window or the shortcut list. */ -int do_mouse(void) -{ - int mouse_col, mouse_row; - int retval = get_mouseinput(&mouse_col, &mouse_row, TRUE); - - /* If the click is wrong or already handled, we're done. */ - if (retval != 0) - return retval; - - /* If the click was in the edit window, put the cursor in that spot. */ - if (wmouse_trafo(edit, &mouse_row, &mouse_col, FALSE)) { - filestruct *current_save = openfile->current; - ssize_t row_count = mouse_row - openfile->current_y; - size_t leftedge; -#ifndef NANO_TINY - size_t current_x_save = openfile->current_x; - bool sameline = (mouse_row == openfile->current_y); - /* Whether the click was on the row where the cursor is. */ - - if (ISSET(SOFTWRAP)) - leftedge = leftedge_for(xplustabs(), openfile->current); - else -#endif - leftedge = get_page_start(xplustabs()); - - /* Move current up or down to the row corresponding to mouse_row. */ - if (row_count < 0) - go_back_chunks(-row_count, &openfile->current, &leftedge); - else - go_forward_chunks(row_count, &openfile->current, &leftedge); - - openfile->current_x = actual_x(openfile->current->data, - actual_last_column(leftedge, mouse_col)); - -#ifndef NANO_TINY - /* Clicking where the cursor is toggles the mark, as does clicking - * beyond the line length with the cursor at the end of the line. */ - if (sameline && openfile->current_x == current_x_save) - do_mark(); - else -#endif - /* The cursor moved; clean the cutbuffer on the next cut. */ - cutbuffer_reset(); - - edit_redraw(current_save, CENTERING); - } - - /* No more handling is needed. */ - return 2; -} -#endif /* ENABLE_MOUSE */ - /* The user typed output_len multibyte characters. Add them to the edit * buffer, filtering out all ASCII control characters if allow_cntrls is * TRUE. */ diff --git a/src/prompt.c b/src/prompt.c index c6b97b42..278ce0af 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -28,6 +28,30 @@ static char *prompt = NULL; static size_t statusbar_x = HIGHEST_POSITIVE; /* The cursor position in answer. */ +#ifdef ENABLE_MOUSE +/* Handle a mouse click on the statusbar prompt or the shortcut list. */ +int do_statusbar_mouse(void) +{ + int mouse_x, mouse_y; + int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE); + + /* We can click on the statusbar window text to move the cursor. */ + if (retval == 0 && wmouse_trafo(bottomwin, &mouse_y, &mouse_x, FALSE)) { + size_t start_col = strlenpt(prompt) + 2; + + /* Move to where the click occurred. */ + if (mouse_x >= start_col && mouse_y == 0) { + statusbar_x = actual_x(answer, + get_statusbar_page_start(start_col, start_col + + statusbar_xplustabs()) + mouse_x - start_col); + update_the_statusbar(); + } + } + + return retval; +} +#endif + /* Read in a keystroke, interpret it if it is a shortcut or toggle, and * return it. Set ran_func to TRUE if we ran a function associated with * a shortcut key, and set finished to TRUE if we're done after running @@ -165,32 +189,6 @@ int do_statusbar_input(bool *ran_func, bool *finished) return input; } -#ifdef ENABLE_MOUSE -/* Handle a mouse click on the statusbar prompt or the shortcut list. */ -int do_statusbar_mouse(void) -{ - int mouse_x, mouse_y; - int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE); - - /* We can click on the statusbar window text to move the cursor. */ - if (retval == 0 && wmouse_trafo(bottomwin, &mouse_y, &mouse_x, FALSE)) { - size_t start_col; - - start_col = strlenpt(prompt) + 2; - - /* Move to where the click occurred. */ - if (mouse_x >= start_col && mouse_y == 0) { - statusbar_x = actual_x(answer, - get_statusbar_page_start(start_col, start_col + - statusbar_xplustabs()) + mouse_x - start_col); - update_the_statusbar(); - } - } - - return retval; -} -#endif - /* The user typed input_len multibyte characters. Add them to the answer, * filtering out ASCII control characters if filtering is TRUE. */ void do_statusbar_output(int *the_input, size_t input_len, diff --git a/src/proto.h b/src/proto.h index aa84ecd9..a2cba42d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -442,15 +442,9 @@ void enable_flow_control(void); void terminal_init(void); void unbound_key(int code); int do_input(bool allow_funcs); -#ifdef ENABLE_MOUSE -int do_mouse(void); -#endif void do_output(char *output, size_t output_len, bool allow_cntrls); /* Most functions in prompt.c. */ -#ifdef ENABLE_MOUSE -int do_statusbar_mouse(void); -#endif void do_statusbar_output(int *the_input, size_t input_len, bool filtering); void do_statusbar_home(void); void do_statusbar_end(void);