Commit 2c36e2eb authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

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
Showing with 102 additions and 74 deletions
+102 -74
...@@ -22,6 +22,11 @@ CVS code - ...@@ -22,6 +22,11 @@ CVS code -
do_indent_marked_void() (renamed do_indent_void()), and do_indent_marked_void() (renamed do_indent_void()), and
do_unindent_marked_void() (renamed do_unindent()). (DLR, do_unindent_marked_void() (renamed do_unindent()). (DLR,
suggested by John M. Gabriele) 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: - browser.c:
do_browser() do_browser()
- Refactor the mouse support, modeling it after do_mouse() for - Refactor the mouse support, modeling it after do_mouse() for
......
...@@ -616,11 +616,11 @@ void shortcut_init(bool unjustify) ...@@ -616,11 +616,11 @@ void shortcut_init(bool unjustify)
sc_init_one(&main_list, NANO_PREVLINE_KEY, N_("Prev Line"), sc_init_one(&main_list, NANO_PREVLINE_KEY, N_("Prev Line"),
IFHELP(nano_prevline_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY, 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"), sc_init_one(&main_list, NANO_NEXTLINE_KEY, N_("Next Line"),
IFHELP(nano_nextline_msg, TRUE), NANO_NO_KEY, NANO_NO_KEY, 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"), sc_init_one(&main_list, NANO_HOME_KEY, N_("Home"),
IFHELP(nano_home_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY, IFHELP(nano_home_msg, FALSE), NANO_NO_KEY, NANO_NO_KEY,
......
...@@ -471,11 +471,23 @@ void do_end(void) ...@@ -471,11 +471,23 @@ void do_end(void)
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);
} }
/* Move up one line. */ /* If scroll_only is FALSE, move up one line. If scroll_only is TRUE,
void do_up(void) * 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 we're at the top of the file, or if scroll_only is TRUE and
if (openfile->current == openfile->fileage) * 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; return;
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
...@@ -485,58 +497,60 @@ void do_up(void) ...@@ -485,58 +497,60 @@ void do_up(void)
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant); openfile->placewewant);
/* If we're on the first line of the edit window, scroll the edit /* If scroll_only is FALSE and if we're on the first line of the
* window up one line if we're in smooth scrolling mode, or up half * edit window, scroll the edit window up one line if we're in
* a page if we're not. */ * smooth scrolling mode, or up half a page if we're not. If
if (openfile->current_y == 0) * 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, edit_scroll(UP,
#ifndef NANO_TINY #ifndef NANO_TINY
ISSET(SMOOTH_SCROLL) ? 1 : (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
#endif #endif
editwinrows / 2); 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 * 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 * needs to be redrawn if we're not on the first page, and the
* latter needs to be drawn unconditionally. */ * latter needs to be drawn unconditionally. */
else { if (openfile->current_y > 0) {
if (need_vertical_update(0)) if (need_vertical_update(0))
update_line(openfile->current->next, 0); update_line(openfile->current->next, 0);
update_line(openfile->current, openfile->current_x); 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 #ifndef NANO_TINY
/* Scroll up one line without scrolling the cursor. */ /* Scroll up one line without scrolling the cursor. */
void do_scroll_up(void) void do_scroll_up(void)
{ {
/* If the top of the file is onscreen, get out. */ do_up(TRUE);
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);
}
} }
#endif /* !NANO_TINY */ #endif
/* Move down one line. */ /* If scroll_only is FALSE, move down one line. If scroll_only is TRUE,
void do_down(void) * 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 we're at the bottom of the file, get out. */
if (openfile->current == openfile->filebot) if (openfile->current == openfile->filebot)
...@@ -549,55 +563,50 @@ void do_down(void) ...@@ -549,55 +563,50 @@ void do_down(void)
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant); openfile->placewewant);
/* If we're on the last line of the edit window, scroll the edit /* If scroll_only is FALSE and if we're on the first line of the
* window down one line if we're in smooth scrolling mode, or down * edit window, scroll the edit window down one line if we're in
* half a page if we're not. */ * smooth scrolling mode, or down half a page if we're not. If
if (openfile->current_y == editwinrows - 1) * 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, edit_scroll(DOWN,
#ifndef NANO_TINY #ifndef NANO_TINY
ISSET(SMOOTH_SCROLL) ? 1 : (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 :
#endif #endif
editwinrows / 2); 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 * 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 * be redrawn if we're not on the first page, and the latter needs
* to be drawn unconditionally. */ * to be drawn unconditionally. */
else { if (openfile->current_y < editwinrows - 1) {
if (need_vertical_update(0)) if (need_vertical_update(0))
update_line(openfile->current->prev, 0); update_line(openfile->current->prev, 0);
update_line(openfile->current, openfile->current_x); 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 #ifndef NANO_TINY
/* Scroll down one line without scrolling the cursor. */ /* Scroll down one line without scrolling the cursor. */
void do_scroll_down(void) void do_scroll_down(void)
{ {
/* If we're at the bottom of the file, get out. */ do_down(TRUE);
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);
}
} }
#endif /* !NANO_TINY */ #endif
/* Move left one character. */ /* Move left one character. */
void do_left(void) void do_left(void)
...@@ -608,7 +617,7 @@ void do_left(void) ...@@ -608,7 +617,7 @@ void do_left(void)
openfile->current_x = move_mbleft(openfile->current->data, openfile->current_x = move_mbleft(openfile->current->data,
openfile->current_x); openfile->current_x);
else if (openfile->current != openfile->fileage) { else if (openfile->current != openfile->fileage) {
do_up(); do_up_void();
openfile->current_x = strlen(openfile->current->data); openfile->current_x = strlen(openfile->current->data);
} }
...@@ -629,7 +638,7 @@ void do_right(void) ...@@ -629,7 +638,7 @@ void do_right(void)
openfile->current_x = move_mbright(openfile->current->data, openfile->current_x = move_mbright(openfile->current->data,
openfile->current_x); openfile->current_x);
else if (openfile->current != openfile->filebot) { else if (openfile->current != openfile->filebot) {
do_down(); do_down_void();
openfile->current_x = 0; openfile->current_x = 0;
} }
......
...@@ -389,11 +389,25 @@ void do_prev_word_void(void); ...@@ -389,11 +389,25 @@ void do_prev_word_void(void);
#endif #endif
void do_home(void); void do_home(void);
void do_end(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 #ifndef NANO_TINY
void do_scroll_up(void); void do_scroll_up(void);
#endif #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 #ifndef NANO_TINY
void do_scroll_down(void); void do_scroll_down(void);
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment