nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit d7fbc70a72a074464276f0aa5658b5859d03be2a
parent 1dd01eb4e1cd984f58fe4b8962595df529af8cfe
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date:   Mon,  2 Jan 2017 13:41:27 -0600

tweaks: avoid an unnecessary fiddling with current_y in do_mouse()

Since do_mouse() uses edit_redraw(), openfile->current_y will be
immediately recalculated, so there's no point in changing it now.
Use a temporary variable instead.

Diffstat:
Msrc/nano.c | 16+++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -1752,12 +1752,12 @@ int do_mouse(void) #ifndef NANO_TINY if (ISSET(SOFTWRAP)) { - ssize_t i = 0; + ssize_t i = 0, current_row = 0; openfile->current = openfile->edittop; while (openfile->current->next != NULL && i < mouse_y) { - openfile->current_y = i; + current_row = i; i += strlenpt(openfile->current->data) / editwincols + 1; openfile->current = openfile->current->next; } @@ -1765,18 +1765,20 @@ int do_mouse(void) if (i > mouse_y) { openfile->current = openfile->current->prev; openfile->current_x = actual_x(openfile->current->data, - ((mouse_y - openfile->current_y) * editwincols) + mouse_x); + ((mouse_y - current_row) * editwincols) + mouse_x); } else openfile->current_x = actual_x(openfile->current->data, mouse_x); } else #endif /* NANO_TINY */ { + ssize_t current_row = openfile->current_y; + /* Move to where the click occurred. */ - for (; openfile->current_y < mouse_y && openfile->current != - openfile->filebot; openfile->current_y++) + for (; current_row < mouse_y && openfile->current != + openfile->filebot; current_row++) openfile->current = openfile->current->next; - for (; openfile->current_y > mouse_y && openfile->current != - openfile->fileage; openfile->current_y--) + for (; current_row > mouse_y && openfile->current != + openfile->fileage; current_row--) openfile->current = openfile->current->prev; openfile->current_x = actual_x(openfile->current->data,