diff --git a/src/files.c b/src/files.c index cfe43ab3..c57c4363 100644 --- a/src/files.c +++ b/src/files.c @@ -130,6 +130,7 @@ void initialize_buffer_text(void) openfile->edittop = openfile->fileage; openfile->current = openfile->fileage; + openfile->firstcolumn = 0; openfile->current_x = 0; openfile->totsize = 0; } @@ -627,6 +628,14 @@ void switch_to_prevnext_buffer(bool to_next) fprintf(stderr, "filename is %s\n", openfile->filename); #endif +#ifndef NANO_TINY + /* When not in softwrap mode, make sure firstcolumn is zero. It might + * be nonzero if we had softwrap mode on while in this buffer, and then + * turned softwrap mode off while in a different buffer. */ + if (!ISSET(SOFTWRAP)) + openfile->firstcolumn = 0; +#endif + /* Update the screen to account for the current buffer. */ display_buffer(); diff --git a/src/nano.c b/src/nano.c index 2155d8ea..8bf3ca80 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1398,12 +1398,16 @@ void do_toggle(int flag) case SUSPEND: signal_init(); break; + case SOFTWRAP: + if (!ISSET(SOFTWRAP)) + openfile->firstcolumn = 0; + refresh_needed = TRUE; + break; case WHITESPACE_DISPLAY: titlebar(NULL); /* Fall through. */ #ifndef DISABLE_COLOR case NO_COLOR_SYNTAX: #endif - case SOFTWRAP: refresh_needed = TRUE; break; } diff --git a/src/nano.h b/src/nano.h index 60fc8c6b..478fbd8c 100644 --- a/src/nano.h +++ b/src/nano.h @@ -353,6 +353,9 @@ typedef struct openfilestruct { /* The current line for this file. */ size_t totsize; /* The file's total number of characters. */ + size_t firstcolumn; + /* The starting column of the top line of the edit window. + * When not in softwrap mode, it's always zero. */ size_t current_x; /* The file's x-coordinate position. */ size_t placewewant;