Commit f00c9612 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

make the movement code simpler by tweaking edit_scroll() to redraw all

necessary lines instead of calling it and then calling edit_redraw()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2856 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 74 additions and 52 deletions
+74 -52
...@@ -34,6 +34,10 @@ CVS code - ...@@ -34,6 +34,10 @@ CVS code -
(DLR) (DLR)
- Consistently make the flags global and any variables used to - Consistently make the flags global and any variables used to
hold it longs. (DLR) hold it longs. (DLR)
- Tweak the movement routines to redraw all necessary lines
instead of relying on edit_redraw(). Changes to
do_page_up(), do_page_down(), do_up(), do_down(), and
edit_scroll(). (DLR)
- Consistently make the fg and bg colortype struct entries and - Consistently make the fg and bg colortype struct entries and
any variables used to hold them shorts. Changes to any variables used to hold them shorts. Changes to
do_colorinit() (renamed color_init()), color_to_int() (renamed do_colorinit() (renamed color_init()), color_to_int() (renamed
......
...@@ -33,9 +33,11 @@ ...@@ -33,9 +33,11 @@
void do_first_line(void) void do_first_line(void)
{ {
size_t pww_save = openfile->placewewant; size_t pww_save = openfile->placewewant;
openfile->current = openfile->fileage; openfile->current = openfile->fileage;
openfile->placewewant = 0;
openfile->current_x = 0; openfile->current_x = 0;
openfile->placewewant = 0;
if (openfile->edittop != openfile->fileage || if (openfile->edittop != openfile->fileage ||
need_vertical_update(pww_save)) need_vertical_update(pww_save))
edit_update(TOP); edit_update(TOP);
...@@ -44,9 +46,11 @@ void do_first_line(void) ...@@ -44,9 +46,11 @@ void do_first_line(void)
void do_last_line(void) void do_last_line(void)
{ {
size_t pww_save = openfile->placewewant; size_t pww_save = openfile->placewewant;
openfile->current = openfile->filebot; openfile->current = openfile->filebot;
openfile->placewewant = 0;
openfile->current_x = 0; openfile->current_x = 0;
openfile->placewewant = 0;
if (openfile->edittop->lineno + (editwinrows / 2) != if (openfile->edittop->lineno + (editwinrows / 2) !=
openfile->filebot->lineno || need_vertical_update(pww_save)) openfile->filebot->lineno || need_vertical_update(pww_save))
edit_update(CENTER); edit_update(CENTER);
...@@ -55,6 +59,7 @@ void do_last_line(void) ...@@ -55,6 +59,7 @@ void do_last_line(void)
void do_home(void) void do_home(void)
{ {
size_t pww_save = openfile->placewewant; size_t pww_save = openfile->placewewant;
#ifndef NANO_SMALL #ifndef NANO_SMALL
if (ISSET(SMART_HOME)) { if (ISSET(SMART_HOME)) {
size_t current_x_save = openfile->current_x; size_t current_x_save = openfile->current_x;
...@@ -73,7 +78,9 @@ void do_home(void) ...@@ -73,7 +78,9 @@ void do_home(void)
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
#endif #endif
check_statusblank(); check_statusblank();
if (need_horizontal_update(pww_save)) if (need_horizontal_update(pww_save))
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);
} }
...@@ -81,17 +88,18 @@ void do_home(void) ...@@ -81,17 +88,18 @@ void do_home(void)
void do_end(void) void do_end(void)
{ {
size_t pww_save = openfile->placewewant; size_t pww_save = openfile->placewewant;
openfile->current_x = strlen(openfile->current->data); openfile->current_x = strlen(openfile->current->data);
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
check_statusblank(); check_statusblank();
if (need_horizontal_update(pww_save)) if (need_horizontal_update(pww_save))
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);
} }
void do_page_up(void) void do_page_up(void)
{ {
size_t pww_save = openfile->placewewant;
const filestruct *current_save = openfile->current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
wrap_reset(); wrap_reset();
#endif #endif
...@@ -100,19 +108,22 @@ void do_page_up(void) ...@@ -100,19 +108,22 @@ void do_page_up(void)
* and put the cursor at the beginning of the line. */ * and put the cursor at the beginning of the line. */
if (openfile->edittop == openfile->fileage) { if (openfile->edittop == openfile->fileage) {
openfile->current = openfile->fileage; openfile->current = openfile->fileage;
openfile->current_x = 0;
openfile->placewewant = 0; openfile->placewewant = 0;
} else { } else {
edit_scroll(UP, editwinrows - 2);
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* If we're in smooth scrolling mode and there's at least one /* If we're in smooth scrolling mode and there's at least one
* page of text left, move the current line of the edit window * page of text left, move the current line of the edit window
* up a page. */ * up a page. */
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno > if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno >
editwinrows - 2) { editwinrows - 2) {
int i; int i = 0;
for (i = 0; i < editwinrows - 2; i++) for (; i < editwinrows - 2; i++)
openfile->current = openfile->current->prev; openfile->current = openfile->current->prev;
/* Get the equivalent x-coordinate of the new line. */
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
} }
/* If we're not in smooth scrolling mode or there isn't at least /* If we're not in smooth scrolling mode or there isn't at least
* one page of text left, put the cursor at the beginning of the * one page of text left, put the cursor at the beginning of the
...@@ -120,26 +131,20 @@ void do_page_up(void) ...@@ -120,26 +131,20 @@ void do_page_up(void)
else { else {
#endif #endif
openfile->current = openfile->edittop; openfile->current = openfile->edittop;
openfile->current_x = 0;
openfile->placewewant = 0; openfile->placewewant = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
#endif #endif
}
/* Get the equivalent x-coordinate of the new line. */
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
/* Update all the lines that need to be updated. */ edit_scroll(UP, editwinrows - 2);
edit_redraw(current_save, pww_save); }
check_statusblank(); check_statusblank();
} }
void do_page_down(void) void do_page_down(void)
{ {
size_t pww_save = openfile->placewewant;
const filestruct *current_save = openfile->current;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
wrap_reset(); wrap_reset();
#endif #endif
...@@ -149,19 +154,22 @@ void do_page_down(void) ...@@ -149,19 +154,22 @@ void do_page_down(void)
if (openfile->edittop->lineno + editwinrows > if (openfile->edittop->lineno + editwinrows >
openfile->filebot->lineno) { openfile->filebot->lineno) {
openfile->current = openfile->filebot; openfile->current = openfile->filebot;
openfile->current_x = 0;
openfile->placewewant = 0; openfile->placewewant = 0;
} else { } else {
edit_scroll(DOWN, editwinrows - 2);
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* If we're in smooth scrolling mode and there's at least one /* If we're in smooth scrolling mode and there's at least one
* page of text left, move the current line of the edit window * page of text left, move the current line of the edit window
* down a page. */ * down a page. */
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno + if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno +
editwinrows - 2 <= openfile->filebot->lineno) { editwinrows - 2 <= openfile->filebot->lineno) {
int i; int i = 0;
for (i = 0; i < editwinrows - 2; i++) for (; i < editwinrows - 2; i++)
openfile->current = openfile->current->next; openfile->current = openfile->current->next;
/* Get the equivalent x-coordinate of the new line. */
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
} }
/* If we're not in smooth scrolling mode or there isn't at least /* If we're not in smooth scrolling mode or there isn't at least
* one page of text left, put the cursor at the beginning of the * one page of text left, put the cursor at the beginning of the
...@@ -169,18 +177,14 @@ void do_page_down(void) ...@@ -169,18 +177,14 @@ void do_page_down(void)
else { else {
#endif #endif
openfile->current = openfile->edittop; openfile->current = openfile->edittop;
openfile->current_x = 0;
openfile->placewewant = 0; openfile->placewewant = 0;
#ifndef NANO_SMALL #ifndef NANO_SMALL
} }
#endif #endif
}
/* Get the equivalent x-coordinate of the new line. */ edit_scroll(DOWN, editwinrows - 2);
openfile->current_x = actual_x(openfile->current->data, }
openfile->placewewant);
/* Update all the lines that need to be updated. */
edit_redraw(current_save, pww_save);
check_statusblank(); check_statusblank();
} }
...@@ -192,6 +196,7 @@ void do_up(void) ...@@ -192,6 +196,7 @@ void do_up(void)
#endif #endif
check_statusblank(); check_statusblank();
/* If we're at the top of the file, get out. */
if (openfile->current->prev == NULL) if (openfile->current->prev == NULL)
return; return;
...@@ -210,14 +215,14 @@ void do_up(void) ...@@ -210,14 +215,14 @@ void do_up(void)
ISSET(SMOOTH_SCROLL) ? 1 : ISSET(SMOOTH_SCROLL) ? 1 :
#endif #endif
editwinrows / 2); editwinrows / 2);
/* Otherwise, update the line we were on before and the line we're
/* Update the lines left alone by edit_scroll(): the line we were on * on now. The former needs to be redrawn if we're not on the first
* before and the line we're on now. The former needs to be redrawn * page, and the latter needs to be redrawn unconditionally. */
* if we're not on the first page, and the latter needs to be else {
* drawn. */ 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); }
} }
void do_down(void) void do_down(void)
...@@ -227,6 +232,7 @@ void do_down(void) ...@@ -227,6 +232,7 @@ void do_down(void)
#endif #endif
check_statusblank(); check_statusblank();
/* If we're at the bottom of the file, get out. */
if (openfile->current->next == NULL) if (openfile->current->next == NULL)
return; return;
...@@ -245,14 +251,14 @@ void do_down(void) ...@@ -245,14 +251,14 @@ void do_down(void)
ISSET(SMOOTH_SCROLL) ? 1 : ISSET(SMOOTH_SCROLL) ? 1 :
#endif #endif
editwinrows / 2); editwinrows / 2);
/* Otherwise, update the line we were on before and the line we're
/* Update the lines left alone by edit_scroll(): the line we were on * on now. The former needs to be redrawn if we're not on the first
* before and the line we're on now. The former needs to be redrawn * page, and the latter needs to be redrawn unconditionally. */
* if we're not on the first page, and the latter needs to be else {
* drawn. */ 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); }
} }
void do_left(bool allow_update) void do_left(bool allow_update)
...@@ -266,8 +272,11 @@ void do_left(bool allow_update) ...@@ -266,8 +272,11 @@ void do_left(bool allow_update)
do_up(); do_up();
openfile->current_x = strlen(openfile->current->data); openfile->current_x = strlen(openfile->current->data);
} }
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
check_statusblank(); check_statusblank();
if (allow_update && need_horizontal_update(pww_save)) if (allow_update && need_horizontal_update(pww_save))
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);
} }
...@@ -280,6 +289,7 @@ void do_left_void(void) ...@@ -280,6 +289,7 @@ void do_left_void(void)
void do_right(bool allow_update) void do_right(bool allow_update)
{ {
size_t pww_save = openfile->placewewant; size_t pww_save = openfile->placewewant;
assert(openfile->current_x <= strlen(openfile->current->data)); assert(openfile->current_x <= strlen(openfile->current->data));
if (openfile->current->data[openfile->current_x] != '\0') if (openfile->current->data[openfile->current_x] != '\0')
...@@ -289,8 +299,11 @@ void do_right(bool allow_update) ...@@ -289,8 +299,11 @@ void do_right(bool allow_update)
do_down(); do_down();
openfile->current_x = 0; openfile->current_x = 0;
} }
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
check_statusblank(); check_statusblank();
if (allow_update && need_horizontal_update(pww_save)) if (allow_update && need_horizontal_update(pww_save))
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);
} }
......
...@@ -3545,23 +3545,26 @@ void edit_scroll(updown direction, int nlines) ...@@ -3545,23 +3545,26 @@ void edit_scroll(updown direction, int nlines)
foo = openfile->edittop; foo = openfile->edittop;
if (direction != UP) { if (direction != UP) {
int slines = editwinrows - nlines; int slines = editwinrows - nlines - 1;
for (; slines > 0 && foo != NULL; slines--) for (; slines > 0 && foo != NULL; slines--)
foo = foo->next; foo = foo->next;
} }
/* And draw new lines on the blank top or bottom lines of the edit /* And draw new lines on the blank top or bottom lines of the edit
* window, depending on the value of direction. Don't draw the new * window, depending on the value of direction. */
* topmost or new bottommost line. */ while (foo != NULL && scroll_rows != 0) {
while (scroll_rows != 0 && foo != NULL) { update_line(foo, (foo == openfile->current) ?
if (foo->next != NULL) openfile->current_x : 0);
update_line(foo, 0); foo = foo->next;
if (direction == UP) if (direction == UP)
scroll_rows++; scroll_rows++;
else else
scroll_rows--; scroll_rows--;
foo = foo->next;
} }
update_line(foo, (foo == openfile->current) ?
openfile->current_x : 0);
} }
/* Update any lines between old_current and current that need to be /* Update any lines between old_current and current that need to be
...@@ -3587,6 +3590,7 @@ void edit_redraw(const filestruct *old_current, size_t old_pww) ...@@ -3587,6 +3590,7 @@ void edit_redraw(const filestruct *old_current, size_t old_pww)
* and/or we're not on the same page as before. If the mark is on, * and/or we're not on the same page as before. If the mark is on,
* update all the lines between old_current and current too. */ * update all the lines between old_current and current too. */
foo = old_current; foo = old_current;
while (foo != openfile->current) { while (foo != openfile->current) {
if (do_refresh) if (do_refresh)
update_line(foo, 0); update_line(foo, 0);
...@@ -3601,6 +3605,7 @@ void edit_redraw(const filestruct *old_current, size_t old_pww) ...@@ -3601,6 +3605,7 @@ void edit_redraw(const filestruct *old_current, size_t old_pww)
foo = foo->next; foo = foo->next;
#endif #endif
} }
if (do_refresh) if (do_refresh)
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);
} }
...@@ -3628,7 +3633,7 @@ void edit_refresh(void) ...@@ -3628,7 +3633,7 @@ void edit_refresh(void)
#endif #endif
while (nlines < editwinrows) { while (nlines < editwinrows) {
update_line(foo, foo == openfile->current ? update_line(foo, (foo == openfile->current) ?
openfile->current_x : 0); openfile->current_x : 0);
nlines++; nlines++;
if (foo->next == NULL) if (foo->next == NULL)
......
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