tweaks: frob some comments, elide a variable, and use 'while' loops
Этот коммит содержится в:
родитель
d7fbc70a72
Коммит
13176792f0
36
src/nano.c
36
src/nano.c
@ -1732,15 +1732,14 @@ int do_mouse(void)
|
|||||||
int mouse_x, mouse_y;
|
int mouse_x, mouse_y;
|
||||||
int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
int retval = get_mouseinput(&mouse_x, &mouse_y, TRUE);
|
||||||
|
|
||||||
|
/* If the click is wrong or already handled, we're done. */
|
||||||
if (retval != 0)
|
if (retval != 0)
|
||||||
/* The click is wrong or already handled. */
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/* We can click on the edit window to move the cursor. */
|
/* If the click was in the edit window, put the cursor in that spot. */
|
||||||
if (wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
|
if (wmouse_trafo(edit, &mouse_y, &mouse_x, FALSE)) {
|
||||||
bool sameline = (mouse_y == openfile->current_y);
|
bool sameline = (mouse_y == openfile->current_y);
|
||||||
/* Did they click on the line with the cursor? If they
|
/* Whether the click was on the line where the cursor is. */
|
||||||
* clicked on the cursor, we set the mark. */
|
|
||||||
filestruct *current_save = openfile->current;
|
filestruct *current_save = openfile->current;
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
size_t current_x_save = openfile->current_x;
|
size_t current_x_save = openfile->current_x;
|
||||||
@ -1752,20 +1751,20 @@ int do_mouse(void)
|
|||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (ISSET(SOFTWRAP)) {
|
if (ISSET(SOFTWRAP)) {
|
||||||
ssize_t i = 0, current_row = 0;
|
ssize_t current_row = 0;
|
||||||
|
|
||||||
openfile->current = openfile->edittop;
|
openfile->current = openfile->edittop;
|
||||||
|
|
||||||
while (openfile->current->next != NULL && i < mouse_y) {
|
while (openfile->current->next != NULL && current_row < mouse_y) {
|
||||||
current_row = i;
|
current_row += strlenpt(openfile->current->data) / editwincols + 1;
|
||||||
i += strlenpt(openfile->current->data) / editwincols + 1;
|
|
||||||
openfile->current = openfile->current->next;
|
openfile->current = openfile->current->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > mouse_y) {
|
if (current_row > mouse_y) {
|
||||||
openfile->current = openfile->current->prev;
|
openfile->current = openfile->current->prev;
|
||||||
|
current_row -= strlenpt(openfile->current->data) / editwincols + 1;
|
||||||
openfile->current_x = actual_x(openfile->current->data,
|
openfile->current_x = actual_x(openfile->current->data,
|
||||||
((mouse_y - current_row) * editwincols) + mouse_x);
|
((mouse_y - current_row) * editwincols) + mouse_x);
|
||||||
} else
|
} else
|
||||||
openfile->current_x = actual_x(openfile->current->data, mouse_x);
|
openfile->current_x = actual_x(openfile->current->data, mouse_x);
|
||||||
} else
|
} else
|
||||||
@ -1774,21 +1773,22 @@ int do_mouse(void)
|
|||||||
ssize_t current_row = openfile->current_y;
|
ssize_t current_row = openfile->current_y;
|
||||||
|
|
||||||
/* Move to where the click occurred. */
|
/* Move to where the click occurred. */
|
||||||
for (; current_row < mouse_y && openfile->current !=
|
while (current_row < mouse_y && openfile->current->next != NULL) {
|
||||||
openfile->filebot; current_row++)
|
|
||||||
openfile->current = openfile->current->next;
|
openfile->current = openfile->current->next;
|
||||||
for (; current_row > mouse_y && openfile->current !=
|
current_row++;
|
||||||
openfile->fileage; current_row--)
|
}
|
||||||
|
while (current_row > mouse_y && openfile->current->prev != NULL) {
|
||||||
openfile->current = openfile->current->prev;
|
openfile->current = openfile->current->prev;
|
||||||
|
current_row--;
|
||||||
|
}
|
||||||
|
|
||||||
openfile->current_x = actual_x(openfile->current->data,
|
openfile->current_x = actual_x(openfile->current->data,
|
||||||
get_page_start(xplustabs()) + mouse_x);
|
get_page_start(xplustabs()) + mouse_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* Clicking where the cursor is toggles the mark, as does
|
/* Clicking where the cursor is toggles the mark, as does clicking
|
||||||
* clicking beyond the line length with the cursor at the end of
|
* beyond the line length with the cursor at the end of the line. */
|
||||||
* the line. */
|
|
||||||
if (sameline && openfile->current_x == current_x_save)
|
if (sameline && openfile->current_x == current_x_save)
|
||||||
do_mark();
|
do_mark();
|
||||||
else
|
else
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user