tweaks: reshuffle some movement code, to reduce the number of conditions
Also, rename a parameter and invert its logic.master
parent
0e30177db7
commit
8656f160d7
39
src/move.c
39
src/move.c
|
@ -483,24 +483,15 @@ void do_end(void)
|
||||||
|
|
||||||
/* Move the cursor to the preceding line or chunk. If scroll_only is TRUE,
|
/* Move the cursor to the preceding line or chunk. If scroll_only is TRUE,
|
||||||
* also scroll the screen one row, so the cursor stays in the same spot. */
|
* also scroll the screen one row, so the cursor stays in the same spot. */
|
||||||
void do_up(bool scroll_only)
|
void do_up(bool really_move)
|
||||||
{
|
{
|
||||||
filestruct *was_current = openfile->current;
|
filestruct *was_current = openfile->current;
|
||||||
size_t leftedge, target_column;
|
size_t leftedge, target_column;
|
||||||
|
|
||||||
/* When just scrolling and the top of the file is onscreen, get out. */
|
|
||||||
if (scroll_only && openfile->edittop == openfile->fileage &&
|
|
||||||
openfile->firstcolumn == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (scroll_only)
|
|
||||||
edit_scroll(BACKWARD);
|
|
||||||
|
|
||||||
get_edge_and_target(&leftedge, &target_column);
|
get_edge_and_target(&leftedge, &target_column);
|
||||||
|
|
||||||
/* If we can't move up one line or chunk, we're at top of file. */
|
/* If we can't move up one line or chunk, we're at top of file. */
|
||||||
if ((!scroll_only || openfile->current_y == editwinrows - 1) &&
|
if (really_move && go_back_chunks(1, &openfile->current, &leftedge) > 0)
|
||||||
go_back_chunks(1, &openfile->current, &leftedge) > 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
set_proper_index_and_pww(&leftedge, target_column, FALSE);
|
set_proper_index_and_pww(&leftedge, target_column, FALSE);
|
||||||
|
@ -513,20 +504,15 @@ void do_up(bool scroll_only)
|
||||||
|
|
||||||
/* Move the cursor to next line or chunk. If scroll_only is TRUE, also
|
/* Move the cursor to next line or chunk. If scroll_only is TRUE, also
|
||||||
* scroll the screen one row, so the cursor stays in the same spot. */
|
* scroll the screen one row, so the cursor stays in the same spot. */
|
||||||
void do_down(bool scroll_only)
|
void do_down(bool really_move)
|
||||||
{
|
{
|
||||||
filestruct *was_current = openfile->current;
|
filestruct *was_current = openfile->current;
|
||||||
size_t leftedge, target_column;
|
size_t leftedge, target_column;
|
||||||
|
|
||||||
if (scroll_only && (openfile->current_y > 0 ||
|
|
||||||
openfile->current != openfile->filebot))
|
|
||||||
edit_scroll(FORWARD);
|
|
||||||
|
|
||||||
get_edge_and_target(&leftedge, &target_column);
|
get_edge_and_target(&leftedge, &target_column);
|
||||||
|
|
||||||
/* If we can't move down one line or chunk, we're at bottom of file. */
|
/* If we can't move down one line or chunk, we're at bottom of file. */
|
||||||
if ((!scroll_only || openfile->current_y == 0) &&
|
if (really_move && go_forward_chunks(1, &openfile->current, &leftedge) > 0)
|
||||||
go_forward_chunks(1, &openfile->current, &leftedge) > 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
set_proper_index_and_pww(&leftedge, target_column, TRUE);
|
set_proper_index_and_pww(&leftedge, target_column, TRUE);
|
||||||
|
@ -540,26 +526,35 @@ void do_down(bool scroll_only)
|
||||||
/* Move up one line or chunk. */
|
/* Move up one line or chunk. */
|
||||||
void do_up_void(void)
|
void do_up_void(void)
|
||||||
{
|
{
|
||||||
do_up(FALSE);
|
do_up(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move down one line or chunk. */
|
/* Move down one line or chunk. */
|
||||||
void do_down_void(void)
|
void do_down_void(void)
|
||||||
{
|
{
|
||||||
do_down(FALSE);
|
do_down(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* Scroll up one line or chunk without scrolling the cursor. */
|
/* Scroll up one line or chunk without scrolling the cursor. */
|
||||||
void do_scroll_up(void)
|
void do_scroll_up(void)
|
||||||
{
|
{
|
||||||
do_up(TRUE);
|
/* When the top of the file is onscreen, we can't scroll. */
|
||||||
|
if (openfile->edittop->prev == NULL && openfile->firstcolumn == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
edit_scroll(BACKWARD);
|
||||||
|
|
||||||
|
do_up(openfile->current_y == editwinrows - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Scroll down one line or chunk without scrolling the cursor. */
|
/* Scroll down one line or chunk without scrolling the cursor. */
|
||||||
void do_scroll_down(void)
|
void do_scroll_down(void)
|
||||||
{
|
{
|
||||||
do_down(TRUE);
|
if (openfile->current->next != NULL || openfile->current_y > 0)
|
||||||
|
edit_scroll(FORWARD);
|
||||||
|
|
||||||
|
do_down(openfile->current_y == 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -386,8 +386,8 @@ void do_prev_word_void(void);
|
||||||
void do_next_word_void(void);
|
void do_next_word_void(void);
|
||||||
void do_home(void);
|
void do_home(void);
|
||||||
void do_end(void);
|
void do_end(void);
|
||||||
void do_up(bool scroll_only);
|
void do_up(bool really_move);
|
||||||
void do_down(bool scroll_only);
|
void do_down(bool really_move);
|
||||||
void do_up_void(void);
|
void do_up_void(void);
|
||||||
void do_down_void(void);
|
void do_down_void(void);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
|
Loading…
Reference in New Issue