tweaks: use a while loop when the end point is not known in advance
It is easier to see the order of steps and what the terminating condition is.master
parent
3f8e30efb1
commit
30591c5e01
13
src/nano.c
13
src/nano.c
|
@ -1763,20 +1763,21 @@ int do_mouse(void)
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (ISSET(SOFTWRAP)) {
|
if (ISSET(SOFTWRAP)) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (openfile->current = openfile->edittop;
|
|
||||||
openfile->current->next && i < mouse_y;
|
openfile->current = openfile->edittop;
|
||||||
openfile->current = openfile->current->next, i++) {
|
|
||||||
|
while (openfile->current->next != NULL && i < mouse_y) {
|
||||||
openfile->current_y = i;
|
openfile->current_y = i;
|
||||||
i += strlenpt(openfile->current->data) / editwincols;
|
i += strlenpt(openfile->current->data) / editwincols + 1;
|
||||||
|
openfile->current = openfile->current->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > mouse_y) {
|
if (i > mouse_y) {
|
||||||
openfile->current = openfile->current->prev;
|
openfile->current = openfile->current->prev;
|
||||||
openfile->current_x = actual_x(openfile->current->data,
|
openfile->current_x = actual_x(openfile->current->data,
|
||||||
mouse_x + (mouse_y - openfile->current_y) * editwincols);
|
mouse_x + (mouse_y - openfile->current_y) * editwincols);
|
||||||
} else {
|
} else
|
||||||
openfile->current_x = actual_x(openfile->current->data, mouse_x);
|
openfile->current_x = actual_x(openfile->current->data, mouse_x);
|
||||||
}
|
|
||||||
} else
|
} else
|
||||||
#endif /* NANO_TINY */
|
#endif /* NANO_TINY */
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue