softwrap: adjust firstcolumn when the window width changes
If the number of columns in the edit window changes (which currently only happens in two places: in regenerate_screen(), called when the window is resized; and in main(), when line numbering mode is toggled), the display will break if we're in softwrap mode and firstcolumn is nonzero. This is because the column width of softwrapped chunks has changed, and firstcolumn is no longer the starting column of a chunk, an assumption that all code using firstcolumn relies on. To fix this problem, add a new function, ensure_firstcolumn_is_aligned(), to adjust firstcolumn to the starting column of the chunk it's on, and use it when the number of columns in the edit window changes. (Note that this function uses the simplest possible fix, and could probably be made more sophisticated.)
Этот коммит содержится в:
родитель
c1f70185ba
Коммит
0389a1d939
@ -1332,6 +1332,9 @@ void regenerate_screen(void)
|
|||||||
#endif
|
#endif
|
||||||
editwincols = COLS - margin;
|
editwincols = COLS - margin;
|
||||||
|
|
||||||
|
/* Ensure that firstcolumn is the starting column of its chunk. */
|
||||||
|
ensure_firstcolumn_is_aligned();
|
||||||
|
|
||||||
#ifdef USE_SLANG
|
#ifdef USE_SLANG
|
||||||
/* Slang curses emulation brain damage, part 1: If we just do what
|
/* Slang curses emulation brain damage, part 1: If we just do what
|
||||||
* curses does here, it'll only work properly if the resize made the
|
* curses does here, it'll only work properly if the resize made the
|
||||||
@ -2643,6 +2646,10 @@ int main(int argc, char **argv)
|
|||||||
if (needed_margin != margin) {
|
if (needed_margin != margin) {
|
||||||
margin = needed_margin;
|
margin = needed_margin;
|
||||||
editwincols = COLS - margin;
|
editwincols = COLS - margin;
|
||||||
|
|
||||||
|
/* Ensure that firstcolumn is the starting column of its chunk. */
|
||||||
|
ensure_firstcolumn_is_aligned();
|
||||||
|
|
||||||
/* The margin has changed -- schedule a full refresh. */
|
/* The margin has changed -- schedule a full refresh. */
|
||||||
refresh_needed = TRUE;
|
refresh_needed = TRUE;
|
||||||
}
|
}
|
||||||
|
@ -714,6 +714,7 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge);
|
|||||||
int go_forward_chunks(int nrows, filestruct **line, size_t *leftedge);
|
int go_forward_chunks(int nrows, filestruct **line, size_t *leftedge);
|
||||||
bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge);
|
bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge);
|
||||||
void edit_scroll(scroll_dir direction, int nrows);
|
void edit_scroll(scroll_dir direction, int nrows);
|
||||||
|
void ensure_firstcolumn_is_aligned(void);
|
||||||
bool current_is_above_screen(void);
|
bool current_is_above_screen(void);
|
||||||
bool current_is_below_screen(void);
|
bool current_is_below_screen(void);
|
||||||
bool current_is_offscreen(void);
|
bool current_is_offscreen(void);
|
||||||
|
11
src/winio.c
11
src/winio.c
@ -2930,6 +2930,17 @@ void edit_scroll(scroll_dir direction, int nrows)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ensure that firstcolumn is at the startting column of the softwrapped chunk
|
||||||
|
* it's on. We need to do this when the number of columns of the edit window
|
||||||
|
* has changed, because then the width of softwrapped chunks has changed. */
|
||||||
|
void ensure_firstcolumn_is_aligned(void)
|
||||||
|
{
|
||||||
|
#ifndef NANO_TINY
|
||||||
|
if (openfile->firstcolumn % editwincols != 0)
|
||||||
|
openfile->firstcolumn -= (openfile->firstcolumn % editwincols);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* Return TRUE if current[current_x] is above the top of the screen, and FALSE
|
/* Return TRUE if current[current_x] is above the top of the screen, and FALSE
|
||||||
* otherwise. */
|
* otherwise. */
|
||||||
bool current_is_above_screen(void)
|
bool current_is_above_screen(void)
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user