softwrap: ensure the current line is fully visible when moving in it

This fixes https://savannah.gnu.org/bugs/?49099,
and fixes the unreported corresponding bugs for
<End> and <Del> and typing extra characters.
master
Benno Schulenberg 2016-10-18 13:03:01 +02:00
parent d66ea08473
commit 43f35fc7a9
4 changed files with 22 additions and 0 deletions

View File

@ -362,6 +362,19 @@ void do_next_word_void(void)
do_next_word(ISSET(WORD_BOUNDS), TRUE); do_next_word(ISSET(WORD_BOUNDS), TRUE);
} }
/* Make sure that the current line, when it is partially scrolled off the
* screen in softwrap mode, is scrolled fully into view. */
void ensure_line_is_visible(void)
{
#ifndef NANO_TINY
if (ISSET(SOFTWRAP) && strlenpt(openfile->current->data) / COLS +
openfile->current_y >= editwinrows) {
edit_update(ISSET(SMOOTH_SCROLL) ? FLOWING : CENTERING);
refresh_needed = TRUE;
}
#endif
}
/* Move to the beginning of the current line. If the SMART_HOME flag is /* Move to the beginning of the current line. If the SMART_HOME flag is
* set, move to the first non-whitespace character of the current line * set, move to the first non-whitespace character of the current line
* if we aren't already there, or to the beginning of the current line * if we aren't already there, or to the beginning of the current line
@ -399,6 +412,8 @@ void do_end(void)
if (need_horizontal_scroll(was_column, openfile->placewewant)) if (need_horizontal_scroll(was_column, openfile->placewewant))
update_line(openfile->current, openfile->current_x); update_line(openfile->current, openfile->current_x);
ensure_line_is_visible();
} }
/* If scroll_only is FALSE, move up one line. If scroll_only is TRUE, /* If scroll_only is FALSE, move up one line. If scroll_only is TRUE,
@ -597,4 +612,6 @@ void do_right(void)
if (openfile->current_x == 0) if (openfile->current_x == 0)
do_down_void(); do_down_void();
else
ensure_line_is_visible();
} }

View File

@ -1926,6 +1926,8 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
} }
#ifndef NANO_TINY #ifndef NANO_TINY
ensure_line_is_visible();
/* Well, we might also need a full refresh if we've changed the /* Well, we might also need a full refresh if we've changed the
* line length to be a new multiple of COLS. */ * line length to be a new multiple of COLS. */
if (ISSET(SOFTWRAP) && refresh_needed == FALSE) if (ISSET(SOFTWRAP) && refresh_needed == FALSE)

View File

@ -409,6 +409,7 @@ void do_prev_word(bool allow_punct, bool allow_update);
void do_prev_word_void(void); void do_prev_word_void(void);
bool do_next_word(bool allow_punct, bool allow_update); bool do_next_word(bool allow_punct, bool allow_update);
void do_next_word_void(void); void do_next_word_void(void);
void ensure_line_is_visible(void);
void do_home(void); void do_home(void);
void do_end(void); void do_end(void);
void do_up(bool scroll_only); void do_up(bool scroll_only);

View File

@ -171,6 +171,8 @@ void do_deletion(undo_type action)
return; return;
#ifndef NANO_TINY #ifndef NANO_TINY
ensure_line_is_visible();
if (ISSET(SOFTWRAP) && refresh_needed == FALSE) if (ISSET(SOFTWRAP) && refresh_needed == FALSE)
if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS) if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS)
refresh_needed = TRUE; refresh_needed = TRUE;