From: David Lawrence Ramsey Date: Thu, 6 Jul 2006 22:17:47 +0000 (+0000) Subject: consolidate do_scroll_(up|down)() into do_(up|down)(), as they have a X-Git-Tag: v1.9.99pre1~98 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=2c36e2eb009a7ca9071225f9a4fc8375b8591baa;p=nano.git consolidate do_scroll_(up|down)() into do_(up|down)(), as they have a lot of common code git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3763 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index dfd4bec1..986101cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,11 @@ CVS code - do_indent_marked_void() (renamed do_indent_void()), and do_unindent_marked_void() (renamed do_unindent()). (DLR, suggested by John M. Gabriele) + - Consolidate do_scroll_(up|down)() into do_(up|down)(), as + they have a lot of common code. New functions do_up_void() + and do_down_void(); changes to shortcut_init(), do_up(), + do_scroll_up(), do_down(), do_scroll_down(), do_left(), and + do_right(). (DLR) - browser.c: do_browser() - Refactor the mouse support, modeling it after do_mouse() for diff --git a/src/global.c b/src/global.c index 3af86a92..9745013e 100644 --- a/src/global.c +++ b/src/global.c @@ -616,11 +616,11 @@ void shortcut_init(bool unjustify) sc_init_one(&main_list, NANO_PREVLINE_KEY, N_("Prev Line"), IFHELP(nano_prevline_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY, - NANO_NO_KEY, VIEW, do_up); + NANO_NO_KEY, VIEW, do_up_void); sc_init_one(&main_list, NANO_NEXTLINE_KEY, N_("Next Line"), IFHELP(nano_nextline_msg, TRUE), NANO_NO_KEY, NANO_NO_KEY, - NANO_NO_KEY, VIEW, do_down); + NANO_NO_KEY, VIEW, do_down_void); sc_init_one(&main_list, NANO_HOME_KEY, N_("Home"), IFHELP(nano_home_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY, diff --git a/src/move.c b/src/move.c index f7f770b6..3e44adb9 100644 --- a/src/move.c +++ b/src/move.c @@ -471,11 +471,23 @@ void do_end(void) update_line(openfile->current, openfile->current_x); } -/* Move up one line. */ -void do_up(void) +/* If scroll_only is FALSE, move up one line. If scroll_only is TRUE, + * scroll up one line without scrolling the cursor. */ +void do_up( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ) { - /* If we're at the top of the file, get out. */ - if (openfile->current == openfile->fileage) + /* If we're at the top of the file, or if scroll_only is TRUE and + * the top of the file is onscreen, get out. */ + if (openfile->current == openfile->fileage +#ifndef NANO_TINY + || (scroll_only && openfile->edittop == openfile->fileage) +#endif + ) return; assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); @@ -485,58 +497,60 @@ void do_up(void) openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); - /* If we're on the first line of the edit window, scroll the edit - * window up one line if we're in smooth scrolling mode, or up half - * a page if we're not. */ - if (openfile->current_y == 0) + /* If scroll_only is FALSE and if we're on the first line of the + * edit window, scroll the edit window up one line if we're in + * smooth scrolling mode, or up half a page if we're not. If + * scroll_only is TRUE, scroll the edit window up one line + * unconditionally. */ + if (openfile->current_y == 0 +#ifndef NANO_TINY + || scroll_only +#endif + ) edit_scroll(UP, #ifndef NANO_TINY - ISSET(SMOOTH_SCROLL) ? 1 : + (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 : #endif editwinrows / 2); - /* If we're not on the first line of the edit window, update the + + /* If we're below the first line of the edit window, update the * line we were on before and the line we're on now. The former * needs to be redrawn if we're not on the first page, and the * latter needs to be drawn unconditionally. */ - else { + if (openfile->current_y > 0) { if (need_vertical_update(0)) update_line(openfile->current->next, 0); update_line(openfile->current, openfile->current_x); } } +/* Move up one line. */ +void do_up_void(void) +{ + do_up( +#ifndef NANO_TINY + FALSE +#endif + ); +} + #ifndef NANO_TINY /* Scroll up one line without scrolling the cursor. */ void do_scroll_up(void) { - /* If the top of the file is onscreen, get out. */ - if (openfile->edittop == openfile->fileage) - return; - - assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); - - /* Move the current line of the edit window up. */ - openfile->current = openfile->current->prev; - openfile->current_x = actual_x(openfile->current->data, - openfile->placewewant); - - /* Scroll the edit window up one line. */ - edit_scroll(UP, 1); - - /* If we're not on the first line of the edit window, update the - * line we were on before and the line we're on now. The former - * needs to be redrawn if we're not on the first page, and the - * latter needs to be drawn unconditionally. */ - if (openfile->current_y > 0) { - if (need_vertical_update(0)) - update_line(openfile->current->next, 0); - update_line(openfile->current, openfile->current_x); - } + do_up(TRUE); } -#endif /* !NANO_TINY */ +#endif -/* Move down one line. */ -void do_down(void) +/* If scroll_only is FALSE, move down one line. If scroll_only is TRUE, + * scroll down one line without scrolling the cursor. */ +void do_down( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ) { /* If we're at the bottom of the file, get out. */ if (openfile->current == openfile->filebot) @@ -549,55 +563,50 @@ void do_down(void) openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); - /* If we're on the last line of the edit window, scroll the edit - * window down one line if we're in smooth scrolling mode, or down - * half a page if we're not. */ - if (openfile->current_y == editwinrows - 1) + /* If scroll_only is FALSE and if we're on the first line of the + * edit window, scroll the edit window down one line if we're in + * smooth scrolling mode, or down half a page if we're not. If + * scroll_only is TRUE, scroll the edit window down one line + * unconditionally. */ + if (openfile->current_y == editwinrows - 1 +#ifndef NANO_TINY + || scroll_only +#endif + ) edit_scroll(DOWN, #ifndef NANO_TINY - ISSET(SMOOTH_SCROLL) ? 1 : + (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 : #endif editwinrows / 2); - /* If we're not on the last line of the edit window, update the line + + /* If we're above the last line of the edit window, update the line * we were on before and the line we're on now. The former needs to * be redrawn if we're not on the first page, and the latter needs * to be drawn unconditionally. */ - else { + if (openfile->current_y < editwinrows - 1) { if (need_vertical_update(0)) update_line(openfile->current->prev, 0); update_line(openfile->current, openfile->current_x); } } +/* Move down one line. */ +void do_down_void(void) +{ + do_down( +#ifndef NANO_TINY + FALSE +#endif + ); +} + #ifndef NANO_TINY /* Scroll down one line without scrolling the cursor. */ void do_scroll_down(void) { - /* If we're at the bottom of the file, get out. */ - if (openfile->current == openfile->filebot) - return; - - assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); - - /* Move the current line of the edit window down. */ - openfile->current = openfile->current->next; - openfile->current_x = actual_x(openfile->current->data, - openfile->placewewant); - - /* Scroll the edit window down one line. */ - edit_scroll(DOWN, 1); - - /* If we're not on the last line of the edit window, update the line - * we were on before and the line we're on now. The former needs to - * be redrawn if we're not on the first page, and the latter needs - * to be drawn unconditionally. */ - if (openfile->current_y < editwinrows - 1) { - if (need_vertical_update(0)) - update_line(openfile->current->prev, 0); - update_line(openfile->current, openfile->current_x); - } + do_down(TRUE); } -#endif /* !NANO_TINY */ +#endif /* Move left one character. */ void do_left(void) @@ -608,7 +617,7 @@ void do_left(void) openfile->current_x = move_mbleft(openfile->current->data, openfile->current_x); else if (openfile->current != openfile->fileage) { - do_up(); + do_up_void(); openfile->current_x = strlen(openfile->current->data); } @@ -629,7 +638,7 @@ void do_right(void) openfile->current_x = move_mbright(openfile->current->data, openfile->current_x); else if (openfile->current != openfile->filebot) { - do_down(); + do_down_void(); openfile->current_x = 0; } diff --git a/src/proto.h b/src/proto.h index e1abf4d5..b7242362 100644 --- a/src/proto.h +++ b/src/proto.h @@ -389,11 +389,25 @@ void do_prev_word_void(void); #endif void do_home(void); void do_end(void); -void do_up(void); +void do_up( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ); +void do_up_void(void); #ifndef NANO_TINY void do_scroll_up(void); #endif -void do_down(void); +void do_down( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ); +void do_down_void(void); #ifndef NANO_TINY void do_scroll_down(void); #endif