display: revamp how screen updates are done in the movement code

When the screen is narrower than a tab is wide, the cursor does not need
to be on the first/last line of the window before an <Up>/<Down> could
need to scroll the screen.

This fixes http://savannah.gnu.org/bugs/?51776.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>
master
David Lawrence Ramsey 2017-08-18 18:59:38 -05:00 committed by Benno Schulenberg
parent 243380c4a2
commit 5e10528759
1 changed files with 16 additions and 86 deletions

View File

@ -463,7 +463,6 @@ void do_up(bool scroll_only)
{ {
filestruct *was_current = openfile->current; filestruct *was_current = openfile->current;
size_t was_x = openfile->current_x; size_t was_x = openfile->current_x;
size_t was_column = xplustabs();
size_t leftedge, target_column; size_t leftedge, target_column;
/* When just scrolling and the top of the file is onscreen, get out. */ /* When just scrolling and the top of the file is onscreen, get out. */
@ -477,38 +476,25 @@ void do_up(bool scroll_only)
if (go_back_chunks(1, &openfile->current, &leftedge) > 0) if (go_back_chunks(1, &openfile->current, &leftedge) > 0)
return; return;
openfile->placewewant = leftedge + target_column;
openfile->current_x = proper_x(openfile->current->data, leftedge, openfile->current_x = proper_x(openfile->current->data, leftedge,
actual_last_column(leftedge, target_column)); actual_last_column(leftedge, target_column));
if (openfile->current == was_current && openfile->current_x == was_x) if (openfile->current == was_current && openfile->current_x == was_x)
openfile->current_x--; openfile->current_x--;
/* When the cursor was on the first line of the edit window (or when just if (scroll_only)
* scrolling without moving the cursor), scroll the edit window up -- one edit_scroll(UPWARD, 1);
* line if we're in smooth scrolling mode, and half a page otherwise. */
if (openfile->current_y == 0 || scroll_only) edit_redraw(openfile->current, FLOWING);
edit_scroll(UPWARD, (ISSET(SMOOTH_SCROLL) || scroll_only) ?
1 : editwinrows / 2 + 1); /* <Up> should not change placewewant, so restore it. */
openfile->placewewant = leftedge + target_column;
if (openfile->current_y > 0) {
/* Redraw the prior line if it's not offscreen, and it's not the same
* line as the current one, and the line was horizontally scrolled. */
if ((!scroll_only || openfile->current_y < editwinrows - 1) &&
openfile->current != was_current &&
line_needs_update(was_column, 0))
update_line(openfile->current->next, 0);
/* Redraw the current line if it needs to be horizontally scrolled. */
if (line_needs_update(0, xplustabs()))
update_line(openfile->current, openfile->current_x);
}
} }
/* Move the cursor to next line or chunk. If scroll_only is TRUE, also /* Move the cursor to next line or chunk. If scroll_only is TRUE, also
* scroll the screen one row, so the cursor stays in the same spot. */ * scroll the screen one row, so the cursor stays in the same spot. */
void do_down(bool scroll_only) void do_down(bool scroll_only)
{ {
filestruct *was_current = openfile->current;
size_t was_column = xplustabs();
size_t leftedge, target_column; size_t leftedge, target_column;
get_edge_and_target(&leftedge, &target_column); get_edge_and_target(&leftedge, &target_column);
@ -517,28 +503,16 @@ void do_down(bool scroll_only)
if (go_forward_chunks(1, &openfile->current, &leftedge) > 0) if (go_forward_chunks(1, &openfile->current, &leftedge) > 0)
return; return;
openfile->placewewant = leftedge + target_column;
openfile->current_x = proper_x(openfile->current->data, leftedge, openfile->current_x = proper_x(openfile->current->data, leftedge,
actual_last_column(leftedge, target_column)); actual_last_column(leftedge, target_column));
/* When the cursor was on the last line of the edit window (or when just if (scroll_only)
* scrolling without moving the cursor), scroll the edit window down -- one edit_scroll(DOWNWARD, 1);
* line if we're in smooth scrolling mode, and half a page otherwise. */
if (openfile->current_y == editwinrows - 1 || scroll_only)
edit_scroll(DOWNWARD, (ISSET(SMOOTH_SCROLL) || scroll_only) ?
1 : editwinrows / 2 + 1);
if (openfile->current_y < editwinrows - 1) { edit_redraw(openfile->current, FLOWING);
/* Redraw the prior line if it's not offscreen, and it's not the same
* line as the current one, and the line was horizontally scrolled. */ /* <Down> should not change placewewant, so restore it. */
if ((!scroll_only || openfile->current_y > 0) && openfile->placewewant = leftedge + target_column;
openfile->current != was_current &&
line_needs_update(was_column, 0))
update_line(openfile->current->prev, 0);
/* Redraw the current line if it needs to be horizontally scrolled. */
if (line_needs_update(0, xplustabs()))
update_line(openfile->current, openfile->current_x);
}
} }
/* Move up one line or chunk. */ /* Move up one line or chunk. */
@ -570,12 +544,6 @@ void do_scroll_down(void)
/* Move left one character. */ /* Move left one character. */
void do_left(void) void do_left(void)
{ {
size_t was_column = xplustabs();
#ifndef NANO_TINY
filestruct *was_current = openfile->current;
size_t was_chunk = chunk_for(was_column, was_current);
#endif
if (openfile->current_x > 0) if (openfile->current_x > 0)
openfile->current_x = move_mbleft(openfile->current->data, openfile->current_x = move_mbleft(openfile->current->data,
openfile->current_x); openfile->current_x);
@ -587,34 +555,12 @@ void do_left(void)
return; return;
} }
openfile->placewewant = xplustabs(); edit_redraw(openfile->current, FLOWING);
#ifndef NANO_TINY
/* If we were on the first line of the edit window, and we changed chunk,
* we're now above the first line of the edit window, so scroll up. */
if (ISSET(SOFTWRAP) && openfile->current_y == 0 &&
openfile->current == was_current &&
chunk_for(openfile->placewewant,
openfile->current) != was_chunk) {
edit_scroll(UPWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
return;
}
#endif
/* Update current if the mark is on or it has changed "page". */
if (line_needs_update(was_column, openfile->placewewant))
update_line(openfile->current, openfile->current_x);
} }
/* Move right one character. */ /* Move right one character. */
void do_right(void) void do_right(void)
{ {
size_t was_column = xplustabs();
#ifndef NANO_TINY
filestruct *was_current = openfile->current;
size_t was_chunk = chunk_for(was_column, was_current);
#endif
if (openfile->current->data[openfile->current_x] != '\0') if (openfile->current->data[openfile->current_x] != '\0')
openfile->current_x = move_mbright(openfile->current->data, openfile->current_x = move_mbright(openfile->current->data,
openfile->current_x); openfile->current_x);
@ -622,25 +568,9 @@ void do_right(void)
openfile->current = openfile->current->next; openfile->current = openfile->current->next;
openfile->current_x = 0; openfile->current_x = 0;
edit_redraw(openfile->current->next, FLOWING); edit_redraw(openfile->current->prev, FLOWING);
return; return;
} }
openfile->placewewant = xplustabs(); edit_redraw(openfile->current, FLOWING);
#ifndef NANO_TINY
/* If we were on the last line of the edit window, and we changed chunk,
* we're now below the first line of the edit window, so scroll down. */
if (ISSET(SOFTWRAP) && openfile->current_y == editwinrows - 1 &&
openfile->current == was_current &&
chunk_for(openfile->placewewant,
openfile->current) != was_chunk) {
edit_scroll(DOWNWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
return;
}
#endif
/* Update current if the mark is on or it has changed "page". */
if (line_needs_update(was_column, openfile->placewewant))
update_line(openfile->current, openfile->current_x);
} }