2009-11-13 Chris Allegretta <chrisa@asty.org>

* winio.c: Add new static maxsize to be able to easier calculation with
          softwrap.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4421 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2009-11-13 13:48:56 +00:00
parent 6f08332741
commit 99c8d40db1
2 changed files with 37 additions and 4 deletions

View File

@ -1,3 +1,7 @@
2009-11-13 Chris Allegretta <chrisa@asty.org>
* winio.c: Add new static maxsize to be able to easier calculation with
softwrap.
2009-11-11 Chris Allegretta <chrisa@asty.org> 2009-11-11 Chris Allegretta <chrisa@asty.org>
* winio.c: Large tweaking of cursor and text display based on COLS not COLS - 1, * winio.c: Large tweaking of cursor and text display based on COLS not COLS - 1,
due to finally understanding that display_string wasn't being called properly due to finally understanding that display_string wasn't being called properly

View File

@ -41,6 +41,9 @@ 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,
@ -2934,6 +2937,26 @@ bool need_vertical_update(size_t pww_save)
get_page_start(openfile->placewewant); get_page_start(openfile->placewewant);
} }
/* When edittop changes, try and figure out how many lines
* we really have to work with (i.e. set maxrows)
*/
void compute_maxrows(void)
{
int n;
filestruct *foo = openfile->edittop;
maxrows = 0;
for (n = 0; n < editwinrows && foo; n++) {
maxrows += 1 - strlenpt(foo->data) / COLS;
foo = foo->next;
}
#ifdef DEBUG
fprintf(stderr, "compute_maxrows(): maxrows = %ld\n", maxrows);
#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
* of lines, and draw new lines on the blank lines left after the * of lines, and draw new lines on the blank lines left after the
* scrolling. direction is the direction to scroll, either UP_DIR or * scrolling. direction is the direction to scroll, either UP_DIR or
@ -3092,9 +3115,9 @@ void edit_redraw(filestruct *old_current, size_t pww_save)
* window until it's onscreen and get out. */ * window until it's onscreen and get out. */
if (old_current->lineno < openfile->edittop->lineno || if (old_current->lineno < openfile->edittop->lineno ||
old_current->lineno >= openfile->edittop->lineno + old_current->lineno >= openfile->edittop->lineno +
editwinrows || openfile->current->lineno < maxrows || openfile->current->lineno <
openfile->edittop->lineno || openfile->current->lineno >= openfile->edittop->lineno || openfile->current->lineno >=
openfile->edittop->lineno + editwinrows) { openfile->edittop->lineno + maxrows) {
filestruct *old_edittop = openfile->edittop; filestruct *old_edittop = openfile->edittop;
ssize_t nlines; ssize_t nlines;
@ -3109,7 +3132,7 @@ void edit_redraw(filestruct *old_current, size_t pww_save)
if (old_edittop->lineno < openfile->edittop->lineno) if (old_edittop->lineno < openfile->edittop->lineno)
old_lineno = old_edittop->lineno; old_lineno = old_edittop->lineno;
else else
old_lineno = (old_edittop->lineno + editwinrows <= old_lineno = (old_edittop->lineno + maxrows <=
openfile->filebot->lineno) ? openfile->filebot->lineno) ?
old_edittop->lineno + editwinrows : old_edittop->lineno + editwinrows :
openfile->filebot->lineno; openfile->filebot->lineno;
@ -3150,6 +3173,8 @@ 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
@ -3198,9 +3223,13 @@ void edit_refresh(void)
filestruct *foo; filestruct *foo;
int nlines; int nlines;
/* Figure out what maxrows should really be */
if (ISSET(SOFTWRAP) && openfile->current->lineno > openfile->edittop->lineno)
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 +
editwinrows) maxrows)
/* 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(