Further fixes, also fix some page/up down issues where we go way off course.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4428 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2009-11-16 04:28:40 +00:00
parent fc48347fb8
commit 8c1edd17e3
4 changed files with 39 additions and 18 deletions

View File

@ -66,6 +66,8 @@ WINDOW *bottomwin;
* messages, the statusbar prompt, and a list of shortcuts. */ * messages, the statusbar prompt, and a list of shortcuts. */
int editwinrows = 0; int editwinrows = 0;
/* How many rows does the edit window take up? */ /* How many rows does the edit window take up? */
int maxrows = 0;
/* How many usable lines are there (due to soft wrapping) */
filestruct *cutbuffer = NULL; filestruct *cutbuffer = NULL;
/* The buffer where we store cut text. */ /* The buffer where we store cut text. */

View File

@ -29,7 +29,7 @@
/* Move to the first line of the file. */ /* Move to the first line of the file. */
void do_first_line(void) void do_first_line(void)
{ {
openfile->current = openfile->fileage; openfile->current = openfile->edittop = openfile->fileage;
openfile->current_x = 0; openfile->current_x = 0;
openfile->placewewant = 0; openfile->placewewant = 0;
@ -90,7 +90,7 @@ void do_page_down(void)
/* If there's less than a page of text left on the screen, put the /* 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 * cursor at the beginning of the last line of the file, and then
* update the edit window. */ * update the edit window. */
if (openfile->current->lineno + editwinrows - 2 >= if (openfile->current->lineno + maxrows - 2 >=
openfile->filebot->lineno) { openfile->filebot->lineno) {
do_last_line(); do_last_line();
return; return;
@ -107,15 +107,24 @@ void do_page_down(void)
} }
#endif #endif
for (i = editwinrows - 2; i > 0 && openfile->current != #ifdef DEBUG
openfile->filebot; i--) fprintf(stderr, "do_page_down: maxrows = %d\n", maxrows);
#endif
for (i = maxrows - 2; i > 0 && openfile->current !=
openfile->filebot; i--) {
openfile->current = openfile->current->next; openfile->current = openfile->current->next;
#ifdef DEBUG
fprintf(stderr, "do_page_down: moving to line %d\n", openfile->current->lineno);
#endif
}
openfile->current_x = actual_x(openfile->current->data, openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant); openfile->placewewant);
/* Scroll the edit window down a page. */ /* Scroll the edit window down a page. */
edit_scroll(DOWN_DIR, editwinrows - 2); edit_scroll(DOWN_DIR, maxrows - 2);
} }
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY

View File

@ -46,6 +46,7 @@ extern WINDOW *topwin;
extern WINDOW *edit; extern WINDOW *edit;
extern WINDOW *bottomwin; extern WINDOW *bottomwin;
extern int editwinrows; extern int editwinrows;
extern int maxrows;
extern filestruct *cutbuffer; extern filestruct *cutbuffer;
extern filestruct *cutbottom; extern filestruct *cutbottom;

View File

@ -41,9 +41,6 @@ static bool disable_cursorpos = FALSE;
/* Should we temporarily disable constant cursor position /* Should we temporarily disable constant cursor position
* display? */ * display? */
static int maxrows = 0;
/* With soft wrapping, how many lines really fit on the curent page */
/* Control character compatibility: /* Control character compatibility:
* *
* - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI, * - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI,
@ -2945,16 +2942,23 @@ void compute_maxrows(void)
int n; int n;
filestruct *foo = openfile->edittop; filestruct *foo = openfile->edittop;
if (!ISSET(SOFTWRAP)) {
maxrows = editwinrows;
return;
}
maxrows = 0; maxrows = 0;
for (n = 0; n < editwinrows && foo; n++) { for (n = 0; n < editwinrows && foo; n++) {
maxrows += 1 - strlenpt(foo->data) / COLS; maxrows += 1 - strlenpt(foo->data) / COLS;
foo = foo->next; foo = foo->next;
} }
if (n < editwinrows)
maxrows += editwinrows - n;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "compute_maxrows(): maxrows = %ld\n", maxrows); fprintf(stderr, "compute_maxrows(): maxrows = %ld\n", maxrows);
#endif #endif
} }
/* Scroll the edit window in the given direction and the given number /* Scroll the edit window in the given direction and the given number
@ -3035,6 +3039,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
} }
} }
compute_maxrows();
/* Limit nlines to the number of lines we could scroll. */ /* Limit nlines to the number of lines we could scroll. */
nlines -= i; nlines -= i;
@ -3173,8 +3178,6 @@ void edit_redraw(filestruct *old_current, size_t pww_save)
else else
edit_scroll(DOWN_DIR, nlines); edit_scroll(DOWN_DIR, nlines);
compute_maxrows();
#ifndef NANO_TINY #ifndef NANO_TINY
/* If the mark is on, update all the lines between the old first /* If the mark is on, update all the lines between the old first
* line or old last line of the edit window (depending on * line or old last line of the edit window (depending on
@ -3224,12 +3227,16 @@ void edit_refresh(void)
int nlines; int nlines;
/* Figure out what maxrows should really be */ /* Figure out what maxrows should really be */
if (openfile->current->lineno > openfile->edittop->lineno) compute_maxrows();
compute_maxrows();
if (openfile->current->lineno < openfile->edittop->lineno || if (openfile->current->lineno < openfile->edittop->lineno ||
openfile->current->lineno >= openfile->edittop->lineno + openfile->current->lineno >= openfile->edittop->lineno +
maxrows) maxrows) {
#ifdef DEBUG
fprintf(stderr, "edit_refresh(): line = %d, edittop %d + maxrows %d\n", openfile->current->lineno, openfile->edittop->lineno, maxrows);
#endif
/* Put the top line of the edit window in range of the current /* Put the top line of the edit window in range of the current
* line. */ * line. */
edit_update( edit_update(
@ -3237,6 +3244,7 @@ void edit_refresh(void)
ISSET(SMOOTH_SCROLL) ? NONE : ISSET(SMOOTH_SCROLL) ? NONE :
#endif #endif
CENTER); CENTER);
}
foo = openfile->edittop; foo = openfile->edittop;
@ -3275,21 +3283,22 @@ void edit_update(update_type location)
* screen as before, or at the top or bottom of the screen if * screen as before, or at the top or bottom of the screen if
* edittop is beyond either. */ * edittop is beyond either. */
if (location == CENTER) if (location == CENTER)
goal = editwinrows / 2; goal = maxrows / 2;
else { else {
goal = openfile->current_y; goal = openfile->current_y;
/* Limit goal to (editwinrows - 1) lines maximum. */ /* Limit goal to (editwinrows - 1) lines maximum. */
if (goal > editwinrows - 1) if (goal > maxrows - 1)
goal = editwinrows - 1; goal = maxrows - 1;
} }
for (; goal > 0 && foo->prev != NULL; goal--) { for (; goal > 0 && foo->prev != NULL; goal--) {
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
goal -= strlenpt(foo->data) / COLS; goal -= 1 + strlenpt(foo->data) / COLS;
foo = foo->prev; foo = foo->prev;
} }
openfile->edittop = foo; openfile->edittop = foo;
compute_maxrows();
} }
/* Unconditionally redraw the entire screen. */ /* Unconditionally redraw the entire screen. */