mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-22 12:51:23 +03:00
properly overhaul edit_scroll() to update the screen on its own this
time, convert the vertical movement functions to use the new version of it, and simplify them where possible git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2876 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
5b44f373fd
commit
4d46437f87
18
ChangeLog
18
ChangeLog
@ -34,6 +34,16 @@ CVS code -
|
||||
(DLR)
|
||||
- Consistently make the flags global and any variables used to
|
||||
hold it longs. (DLR)
|
||||
- Make edit_scroll() sophisticated enough to keep track of
|
||||
current and current_x and update the lines before and after
|
||||
the scrolled region, and change the movement functions that
|
||||
use edit_scroll() to (a) set current and current_x before
|
||||
calling it, and (b) no longer call edit_redraw() afterward,
|
||||
since it's now unnecessary. These changes eliminate
|
||||
redundant screen updates when the mark is on, since the mark
|
||||
display depends on current and current_x. Changes to
|
||||
edit_scroll(), do_page_up(), do_page_down(), do_up(), and
|
||||
do_down(). (DLR)
|
||||
- Consistently make the fg and bg colortype struct entries and
|
||||
any variables used to hold them shorts. Changes to
|
||||
do_colorinit() (renamed color_init()), color_to_int() (renamed
|
||||
@ -59,6 +69,12 @@ CVS code -
|
||||
- global.c:
|
||||
shortcut_init()
|
||||
- Simplify wording of nano_gotoline_msg. (Jordi and Ken Tyler)
|
||||
- move.c:
|
||||
do_first_line(), do_last_line()
|
||||
- Simplify by only using edit_redraw(). (DLR)
|
||||
do_page_up(), do_page_down()
|
||||
- If there's less than a page of text onscreen, just call
|
||||
do_(first|last)_line(). (DLR)
|
||||
- nano.c:
|
||||
usage()
|
||||
- Properly mention the support for "[+LINE,COLUMN]" on the
|
||||
@ -118,7 +134,7 @@ CVS code -
|
||||
as the alternate spell checking code is now the only place
|
||||
where it's used. (DLR)
|
||||
- winio.c:
|
||||
edit_scroll(), edit_redraw(), edit_refresh()
|
||||
edit_redraw(), edit_refresh()
|
||||
- Clean up and simplify. (DLR)
|
||||
edit_update()
|
||||
- Since we no longer use TOP, remove references to it. Also,
|
||||
|
137
src/move.c
137
src/move.c
@ -32,28 +32,27 @@
|
||||
|
||||
void do_first_line(void)
|
||||
{
|
||||
const filestruct *current_save = openfile->current;
|
||||
size_t pww_save = openfile->placewewant;
|
||||
|
||||
openfile->current = openfile->fileage;
|
||||
openfile->current_x = 0;
|
||||
openfile->placewewant = 0;
|
||||
|
||||
if (openfile->edittop != openfile->fileage ||
|
||||
need_vertical_update(pww_save))
|
||||
edit_update(CENTER);
|
||||
edit_redraw(current_save, pww_save);
|
||||
}
|
||||
|
||||
void do_last_line(void)
|
||||
{
|
||||
const filestruct *current_save = openfile->current;
|
||||
size_t pww_save = openfile->placewewant;
|
||||
|
||||
openfile->current = openfile->filebot;
|
||||
openfile->current_x = 0;
|
||||
openfile->placewewant = 0;
|
||||
openfile->current_y = editwinrows - 1;
|
||||
|
||||
if (openfile->edittop->lineno + (editwinrows / 2) !=
|
||||
openfile->filebot->lineno || need_vertical_update(pww_save))
|
||||
edit_update(CENTER);
|
||||
edit_redraw(current_save, pww_save);
|
||||
}
|
||||
|
||||
void do_home(void)
|
||||
@ -100,104 +99,82 @@ void do_end(void)
|
||||
|
||||
void do_page_up(void)
|
||||
{
|
||||
const filestruct *current_save = openfile->current;
|
||||
size_t pww_save = openfile->placewewant;
|
||||
|
||||
#ifndef DISABLE_WRAPPING
|
||||
wrap_reset();
|
||||
#endif
|
||||
|
||||
/* If the first line of the file is onscreen, move current up there
|
||||
* and put the cursor at the beginning of the line. */
|
||||
if (openfile->edittop == openfile->fileage) {
|
||||
openfile->current = openfile->fileage;
|
||||
openfile->placewewant = 0;
|
||||
} else {
|
||||
/* Scroll the edit window up a page. */
|
||||
edit_scroll(UP, editwinrows - 2);
|
||||
/* If there's less than a page of text left on the screen, put the
|
||||
* cursor at the beginning of the first line of the file, and then
|
||||
* update the edit window. */
|
||||
if (openfile->current->lineno <= editwinrows - 2)
|
||||
do_first_line();
|
||||
else {
|
||||
int i;
|
||||
|
||||
/* If we're not in smooth scrolling mode, put the cursor at the
|
||||
* beginning of the top line of the edit window, as Pico
|
||||
* does. */
|
||||
#ifndef NANO_SMALL
|
||||
/* 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
|
||||
* up a page. */
|
||||
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno >
|
||||
editwinrows - 2) {
|
||||
int i = 0;
|
||||
|
||||
for (; i < editwinrows - 2; i++)
|
||||
openfile->current = openfile->current->prev;
|
||||
}
|
||||
/* 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
|
||||
* top line of the edit window, as Pico does. */
|
||||
else {
|
||||
if (!ISSET(SMOOTH_SCROLL)) {
|
||||
#endif
|
||||
openfile->current = openfile->edittop;
|
||||
openfile->placewewant = 0;
|
||||
#ifndef NANO_SMALL
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = editwinrows - 2; i > 0 && openfile->current->prev !=
|
||||
NULL; i--)
|
||||
openfile->current = openfile->current->prev;
|
||||
|
||||
openfile->current_x = actual_x(openfile->current->data,
|
||||
openfile->placewewant);
|
||||
|
||||
/* Scroll the edit window up a page. */
|
||||
edit_scroll(UP, editwinrows - 2);
|
||||
}
|
||||
|
||||
/* Get the equivalent x-coordinate of the current line. */
|
||||
openfile->current_x = actual_x(openfile->current->data,
|
||||
openfile->placewewant);
|
||||
|
||||
/* Update the screen. */
|
||||
edit_redraw(current_save, pww_save);
|
||||
|
||||
check_statusblank();
|
||||
}
|
||||
|
||||
void do_page_down(void)
|
||||
{
|
||||
const filestruct *current_save = openfile->current;
|
||||
size_t pww_save = openfile->placewewant;
|
||||
|
||||
#ifndef DISABLE_WRAPPING
|
||||
wrap_reset();
|
||||
#endif
|
||||
|
||||
/* If the last line of the file is onscreen, move current down
|
||||
* there and put the cursor at the beginning of the line. */
|
||||
if (openfile->edittop->lineno + editwinrows >
|
||||
openfile->filebot->lineno) {
|
||||
openfile->current = openfile->filebot;
|
||||
openfile->placewewant = 0;
|
||||
} else {
|
||||
/* Scroll the edit window down a page. */
|
||||
edit_scroll(DOWN, editwinrows - 2);
|
||||
/* If there's less than a page of text left on the screen, put the
|
||||
* cursor at the beginning of the last line of the file, and then
|
||||
* update the edit window. */
|
||||
if (openfile->current->lineno + editwinrows - 2 >=
|
||||
openfile->filebot->lineno)
|
||||
do_last_line();
|
||||
else {
|
||||
/* If we're not in smooth scrolling mode, put the cursor at the
|
||||
* beginning of the top line of the edit window, as Pico
|
||||
* does. */
|
||||
int i;
|
||||
|
||||
#ifndef NANO_SMALL
|
||||
/* 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
|
||||
* down a page. */
|
||||
if (ISSET(SMOOTH_SCROLL) && openfile->current->lineno +
|
||||
editwinrows - 2 <= openfile->filebot->lineno) {
|
||||
int i = 0;
|
||||
|
||||
for (; i < editwinrows - 2; i++)
|
||||
openfile->current = openfile->current->next;
|
||||
}
|
||||
/* 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
|
||||
* top line of the edit window, as Pico does. */
|
||||
else {
|
||||
if (!ISSET(SMOOTH_SCROLL)) {
|
||||
#endif
|
||||
openfile->current = openfile->edittop;
|
||||
openfile->placewewant = 0;
|
||||
#ifndef NANO_SMALL
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = editwinrows - 2; i > 0 && openfile->current->next !=
|
||||
NULL; i--)
|
||||
openfile->current = openfile->current->next;
|
||||
|
||||
openfile->current_x = actual_x(openfile->current->data,
|
||||
openfile->placewewant);
|
||||
|
||||
/* Scroll the edit window down a page. */
|
||||
edit_scroll(DOWN, editwinrows - 2);
|
||||
}
|
||||
|
||||
/* Get the equivalent x-coordinate of the current line. */
|
||||
openfile->current_x = actual_x(openfile->current->data,
|
||||
openfile->placewewant);
|
||||
|
||||
/* Update the screen. */
|
||||
edit_redraw(current_save, pww_save);
|
||||
|
||||
check_statusblank();
|
||||
}
|
||||
|
||||
@ -228,13 +205,14 @@ void do_up(void)
|
||||
ISSET(SMOOTH_SCROLL) ? 1 :
|
||||
#endif
|
||||
editwinrows / 2);
|
||||
|
||||
/* 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 (need_vertical_update(0))
|
||||
update_line(openfile->current->next, 0);
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
else {
|
||||
if (need_vertical_update(0))
|
||||
update_line(openfile->current->next, 0);
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
}
|
||||
}
|
||||
|
||||
void do_down(void)
|
||||
@ -264,13 +242,14 @@ void do_down(void)
|
||||
ISSET(SMOOTH_SCROLL) ? 1 :
|
||||
#endif
|
||||
editwinrows / 2);
|
||||
|
||||
/* 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 (need_vertical_update(0))
|
||||
update_line(openfile->current->prev, 0);
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
else {
|
||||
if (need_vertical_update(0))
|
||||
update_line(openfile->current->prev, 0);
|
||||
update_line(openfile->current, openfile->current_x);
|
||||
}
|
||||
}
|
||||
|
||||
void do_left(bool allow_update)
|
||||
|
45
src/winio.c
45
src/winio.c
@ -3503,17 +3503,12 @@ int need_vertical_update(size_t old_pww)
|
||||
/* Scroll the edit window in the given direction and the given number
|
||||
* of lines, and draw new lines on the blank lines left after the
|
||||
* scrolling. direction is the direction to scroll, either UP or DOWN,
|
||||
* and nlines is the number of lines to scroll.
|
||||
*
|
||||
* We assume that the topmost and bottommost lines of the scrolled
|
||||
* region are where the current line was before and will be after
|
||||
* scrolling, and hence don't draw them, since we can't know which is
|
||||
* which. edit_redraw() should be used to draw these lines, and to
|
||||
* redraw marked lines, if applicable. */
|
||||
* and nlines is the number of lines to scroll. We change edittop, and
|
||||
* assume that current and current_x are up to date. */
|
||||
void edit_scroll(updown direction, int nlines)
|
||||
{
|
||||
const filestruct *foo;
|
||||
int i, scroll_rows = 0;
|
||||
int i;
|
||||
|
||||
/* Scrolling less than one line or more than editwinrows lines is
|
||||
* redundant, so don't allow it. */
|
||||
@ -3521,10 +3516,8 @@ void edit_scroll(updown direction, int nlines)
|
||||
return;
|
||||
|
||||
/* Move the top line of the edit window up or down (depending on the
|
||||
* value of direction) nlines lines. If there are fewer lines of
|
||||
* text than that left, move it to the top or bottom line of the
|
||||
* file (depending on the value of direction). Keep track of
|
||||
* how many lines we moved in scroll_rows. */
|
||||
* value of direction) nlines lines, or as many lines as we can if
|
||||
* there are fewer than nlines lines available. */
|
||||
for (i = nlines; i > 0; i--) {
|
||||
if (direction == UP) {
|
||||
if (openfile->edittop->prev == NULL)
|
||||
@ -3535,28 +3528,34 @@ void edit_scroll(updown direction, int nlines)
|
||||
break;
|
||||
openfile->edittop = openfile->edittop->next;
|
||||
}
|
||||
|
||||
scroll_rows++;
|
||||
}
|
||||
|
||||
/* Scroll the text on the screen up or down scroll_rows lines,
|
||||
* depending on the value of direction. */
|
||||
/* Scroll the text on the screen up or down nlines lines, depending
|
||||
* on the value of direction. */
|
||||
scrollok(edit, TRUE);
|
||||
wscrl(edit, (direction == UP) ? -scroll_rows : scroll_rows);
|
||||
wscrl(edit, (direction == UP) ? -nlines : nlines);
|
||||
scrollok(edit, FALSE);
|
||||
|
||||
/* Add two to nlines, to account for the lines before and after the
|
||||
* scrolled region. */
|
||||
nlines += 2;
|
||||
|
||||
/* If we scrolled up, we're on the line before the scrolled
|
||||
* region. */
|
||||
foo = openfile->edittop;
|
||||
|
||||
/* If we scrolled down, move down to the line before the scrolled
|
||||
* region. */
|
||||
if (direction == DOWN) {
|
||||
for (i = editwinrows - scroll_rows; i > 0 && foo != NULL; i--)
|
||||
for (i = editwinrows - nlines; i > 0 && foo != NULL; i--)
|
||||
foo = foo->next;
|
||||
}
|
||||
|
||||
/* Draw new lines on the blank top or bottom lines of the edit
|
||||
* window, depending on the value of direction, and skipping the
|
||||
* topmost and bottommost lines. */
|
||||
for (; scroll_rows > 0 && foo != NULL; scroll_rows--) {
|
||||
update_line(foo, 0);
|
||||
/* Draw new lines on the blank lines before, inside, and after the
|
||||
* scrolled region. */
|
||||
for (; nlines > 0 && foo != NULL; nlines--) {
|
||||
update_line(foo, (foo == openfile->current) ?
|
||||
openfile->current_x : 0);
|
||||
foo = foo->next;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user