From 8e779b6e858d8ac8263cf7b0bb760d422f1cf979 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey <pooka109@gmail.com> Date: Sun, 13 Aug 2017 04:30:10 -0500 Subject: [PATCH] softwrap: properly update the viewport when adding text at firstcolumn Adding text plus whitespace while the cursor is at or near the topleft corner of the edit window can cause a change in the preceding chunk, throwing firstcolumn out of alignment. Catch this special case. This fixes http://savannah.gnu.org/bugs/?51743. --- src/nano.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/nano.c b/src/nano.c index 150fc6d1..7307925f 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1855,6 +1855,15 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) if (openfile->mark_set && openfile->current == openfile->mark_begin && openfile->current_x < openfile->mark_begin_x) openfile->mark_begin_x += char_len; + + /* When the cursor is on the top row and not on the first chunk + * of a line, adding text there might change the preceding chunk + * and thus require an adjustment of firstcolumn. */ + if (openfile->current == openfile->edittop && + openfile->firstcolumn > 0) { + ensure_firstcolumn_is_aligned(); + refresh_needed = TRUE; + } #endif openfile->current_x += char_len; -- GitLab