#endif
)
{
+ bool onlastline = FALSE;
+
/* If we're at the bottom of the file, get out. */
if (openfile->current == openfile->filebot)
return;
- assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
+
+ assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
/* Move the current line of the edit window down. */
openfile->current = openfile->current->next;
openfile->current_x = actual_x(openfile->current->data,
openfile->placewewant);
+ if (ISSET(SOFTWRAP)) {
+ filestruct *foo;
+ ssize_t extracuzsoft = 0;
+
+ for (foo = openfile->edittop; foo
+ && foo->lineno - openfile->edittop->lineno + extracuzsoft < editwinrows;
+ foo = foo->next) {
+ extracuzsoft += strlenpt(foo->data) / (COLS - 1);
+ if (foo == openfile->current)
+ break;
+ }
+ if (foo && foo->lineno - openfile->edittop->lineno + extracuzsoft >= editwinrows)
+ onlastline = TRUE;
+ }
+
/* If scroll_only is FALSE and if we're on the first line of the
* edit window, scroll the edit window down one line if we're in
* smooth scrolling mode, or down half a page if we're not. If
* scroll_only is TRUE, scroll the edit window down one line
* unconditionally. */
- if (openfile->current_y == editwinrows - 1
+ if (onlastline || openfile->current_y == editwinrows - 1
#ifndef NANO_TINY
|| scroll_only
#endif
* 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 (openfile->current_y < editwinrows - 1) {
+ if (ISSET(SOFTWRAP) || openfile->current_y < editwinrows - 1) {
if (need_vertical_update(0))
update_line(openfile->current->prev, 0);
update_line(openfile->current, openfile->current_x);
if (ISSET(SOFTWRAP)) {
openfile->current_y = 0;
filestruct *tmp;
- for (tmp = openfile->edittop; tmp != openfile->current; tmp = tmp->next)
+ for (tmp = openfile->edittop; tmp && tmp != openfile->current; tmp = tmp->next)
openfile->current_y += 1 + strlenpt(tmp->data) / (COLS - 1);
openfile->current_y += xplustabs() / (COLS - 1);
assert(fileptr != NULL);
if (ISSET(SOFTWRAP)) {
- for (tmp = openfile->edittop; tmp != fileptr; tmp = tmp->next) {
+ for (tmp = openfile->edittop; tmp && tmp != fileptr; tmp = tmp->next) {
line += 1 + (strlenpt(tmp->data) / COLS);
-#ifdef DEBUG
- fprintf(stderr, "update_line(): inside loop, line = %d\n", line);
-#endif
}
} else
line = fileptr->lineno - openfile->edittop->lineno;
-#ifdef DEBUG
- fprintf(stderr, "update_line(): line = %d\n", line);
-#endif
-
if (line < 0 || line >= editwinrows)
return;
* also assume that scrollok(edit) is FALSE. */
void edit_scroll(scroll_dir direction, ssize_t nlines)
{
- bool do_redraw = need_vertical_update(0);
filestruct *foo;
- ssize_t i;
+ ssize_t i, extracuzsoft = 0;
+ bool do_redraw = FALSE;
/* Don't bother scrolling less than one line. */
if (nlines < 1)
return;
+ if (need_vertical_update(0) || ISSET(SOFTWRAP) && strlen(openfile->edittop->data) / (COLS - 1) > 1)
+ do_redraw = TRUE;
+
+
+ /* If using soft wrapping, we want to scroll down enough to display the entire next
+ line, if possible... */
+ if (ISSET(SOFTWRAP)) {
+#ifdef DEBUG
+ fprintf(stderr, "Softwrap: Entering check for extracuzsoft\n");
+#endif
+ for (i = editwinrows, foo = openfile->edittop; foo && i > 0; i--, foo = foo->next)
+ i -= strlenpt(foo->data) / (COLS - 1);
+ if (foo) {
+ extracuzsoft += strlenpt(foo->data) / (COLS - 1);
+#ifdef DEBUG
+ fprintf(stderr, "Setting extracuzsoft to %zd due to strlen %zd of line %zd\n", extracuzsoft,
+ strlenpt(foo->data), foo->lineno);
+#endif
+ /* Now account for whether the edittop line itself is >COLS, if scrolling down */
+ for (foo = openfile->edittop; direction != UP_DIR && foo && extracuzsoft > 0; nlines++) {
+ extracuzsoft -= strlenpt(foo->data) / (COLS - 1) + 1;
+#ifdef DEBUG
+ fprintf(stderr, "Edittop adjustment, setting nlines to %zd\n", nlines);
+#endif
+ if (foo == openfile->filebot)
+ break;
+ foo = foo->next;
+ }
+ }
+ }
+
+
/* Part 1: nlines is the number of lines we're going to scroll the
* text of the edit window. */
/* Don't bother scrolling zero lines or more than the number of
* lines in the edit window minus one; in both cases, get out, and
* call edit_refresh() beforehand if we need to. */
- if (nlines == 0 || nlines >= editwinrows) {
+ if (nlines == 0 || do_redraw || nlines >= editwinrows) {
if (do_redraw || nlines >= editwinrows)
edit_refresh();
return;
bool do_redraw = need_vertical_update(0) ||
need_vertical_update(pww_save);
filestruct *foo = NULL;
+ ssize_t i = 0, extracuzsoft = 0;
/* If either old_current or current is offscreen, scroll the edit
* window until it's onscreen and get out. */
editwinrows || openfile->current->lineno <
openfile->edittop->lineno || openfile->current->lineno >=
openfile->edittop->lineno + editwinrows) {
+
filestruct *old_edittop = openfile->edittop;
ssize_t nlines;