Commit b1b9770c authored by David Lawrence Ramsey's avatar David Lawrence Ramsey Committed by Benno Schulenberg
Browse files

tweaks: rename a variable and adjust some types in edit_scroll()

Scrolling works on rows, not on lines.  Accordingly, rename the nlines
variable to nrows.  And rows should be of the type int, not ssize_t.
parent 78037831
Showing with 35 additions and 41 deletions
+35 -41
...@@ -747,7 +747,7 @@ void edit_draw(filestruct *fileptr, const char *converted, ...@@ -747,7 +747,7 @@ void edit_draw(filestruct *fileptr, const char *converted,
int line, size_t from_col); int line, size_t from_col);
int update_line(filestruct *fileptr, size_t index); int update_line(filestruct *fileptr, size_t index);
bool need_horizontal_scroll(const size_t old_column, const size_t new_column); bool need_horizontal_scroll(const size_t old_column, const size_t new_column);
void edit_scroll(scroll_dir direction, ssize_t nlines); void edit_scroll(scroll_dir direction, int nrows);
void edit_redraw(filestruct *old_current); void edit_redraw(filestruct *old_current);
void edit_refresh(void); void edit_refresh(void);
void adjust_viewport(update_type location); void adjust_viewport(update_type location);
......
...@@ -2772,24 +2772,21 @@ void compute_maxlines(void) ...@@ -2772,24 +2772,21 @@ void compute_maxlines(void)
maxlines = editwinrows; maxlines = editwinrows;
} }
/* Scroll the edit window in the given direction and the given number /* Scroll the edit window in the given direction and the given number of rows,
* of lines, and draw new lines on the blank lines left after the * and draw new lines on the blank lines left after the scrolling. We change
* scrolling. direction is the direction to scroll, either UPWARD or * edittop, and assume that current and current_x are up to date. */
* DOWNWARD, and nlines is the number of lines to scroll. We change void edit_scroll(scroll_dir direction, int nrows)
* edittop, and assume that current and current_x are up to date. We
* also assume that scrollok(edit) is FALSE. */
void edit_scroll(scroll_dir direction, ssize_t nlines)
{ {
ssize_t i; int i;
filestruct *line; filestruct *line;
/* Part 1: nlines is the number of lines we're going to scroll the /* Part 1: nrows is the number of rows we're going to scroll the text of
* text of the edit window. */ * the edit window. */
/* Move the top line of the edit window up or down (depending on the /* Move the top line of the edit window up or down (depending on the value
* value of direction) nlines lines, or as many lines as we can if * of direction) nrows rows, or as many rows as we can if there are fewer
* there are fewer than nlines lines available. */ * than nrows rows available. */
for (i = nlines; i > 0; i--) { for (i = nrows; i > 0; i--) {
if (direction == UPWARD) { if (direction == UPWARD) {
if (openfile->edittop == openfile->fileage) if (openfile->edittop == openfile->fileage)
break; break;
...@@ -2811,53 +2808,50 @@ void edit_scroll(scroll_dir direction, ssize_t nlines) ...@@ -2811,53 +2808,50 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
#endif #endif
} }
/* Limit nlines to the number of lines we could scroll. */ /* Limit nrows to the number of rows we could scroll. */
nlines -= i; nrows -= i;
/* Don't bother scrolling zero lines, nor more than the window can hold. */ /* Don't bother scrolling zero rows, nor more than the window can hold. */
if (nlines == 0) if (nrows == 0)
return; return;
if (nlines >= editwinrows) if (nrows >= editwinrows)
refresh_needed = TRUE; refresh_needed = TRUE;
if (refresh_needed == TRUE) if (refresh_needed == TRUE)
return; return;
/* Scroll the text of the edit window up or down nlines lines, /* Scroll the text of the edit window a number of rows up or down. */
* depending on the value of direction. */
scrollok(edit, TRUE); scrollok(edit, TRUE);
wscrl(edit, (direction == UPWARD) ? -nlines : nlines); wscrl(edit, (direction == UPWARD) ? -nrows : nrows);
scrollok(edit, FALSE); scrollok(edit, FALSE);
/* Part 2: nlines is the number of lines in the scrolled region of /* Part 2: nrows is now the number of rows in the scrolled region of the
* the edit window that we need to draw. */ * edit window that we need to draw. */
/* If the scrolled region contains only one line, and the line /* If the scrolled region contains only one row, and the row before it is
* before it is visible in the edit window, we need to draw it too. * visible in the edit window, we need to draw it too. If the scrolled
* If the scrolled region contains more than one line, and the lines * region is more than one row, and the rows before and after it are
* before and after the scrolled region are visible in the edit * visible in the edit window, we need to draw them too. */
* window, we need to draw them too. */ nrows += (nrows == 1) ? 1 : 2;
nlines += (nlines == 1) ? 1 : 2;
if (nlines > editwinrows) if (nrows > editwinrows)
nlines = editwinrows; nrows = editwinrows;
/* If we scrolled up, we're on the line before the scrolled region. */ /* If we scrolled up, we're on the line before the scrolled region. */
line = openfile->edittop; line = openfile->edittop;
/* If we scrolled down, move down to the line before the scrolled region. */ /* If we scrolled down, move down to the line before the scrolled region. */
if (direction == DOWNWARD) { if (direction == DOWNWARD) {
for (i = editwinrows - nlines; i > 0 && line != NULL; i--) for (i = editwinrows - nrows; i > 0 && line != NULL; i--)
line = line->next; line = line->next;
} }
/* Draw new lines on any blank lines before or inside the scrolled /* Draw new lines on any blank rows before or inside the scrolled region.
* region. If we scrolled down and we're on the top line, or if we * If we scrolled down and we're on the top row, or if we scrolled up and
* scrolled up and we're on the bottom line, the line won't be * we're on the bottom row, the row won't be blank, so we don't need to
* blank, so we don't need to draw it unless the mark is on or we're * draw it unless the mark is on or we're not on the first "page". */
* not on the first page. */ for (i = nrows; i > 0 && line != NULL; i--) {
for (i = nlines; i > 0 && line != NULL; i--) { if ((i == nrows && direction == DOWNWARD) ||
if ((i == nlines && direction == DOWNWARD) ||
(i == 1 && direction == UPWARD)) { (i == 1 && direction == UPWARD)) {
if (need_horizontal_scroll(openfile->placewewant, 0)) if (need_horizontal_scroll(openfile->placewewant, 0))
update_line(line, (line == openfile->current) ? update_line(line, (line == openfile->current) ?
......
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