From: David Lawrence Ramsey Date: Sat, 16 Jul 2005 22:47:12 +0000 (+0000) Subject: really fix color breakage by decoupling edit_update() and X-Git-Tag: v1.3.9~171 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=5b44f373fd66e8620a6839450f77292d4186ccf5;p=nano.git really fix color breakage by decoupling edit_update() and edit_refresh(); edit_update() is only called without edit_refresh() in do_gotolinecolumn() if allow_update is FALSE, and in edit_refresh() itself if edittop is out of range of current git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2875 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 53d8900d..d7e591b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -91,6 +91,8 @@ CVS code - - nano.h: - Since we only use vsnprintf() now, remove the #ifdef block for HAVE_SNPRINTF. (DLR) + - Remove TOP from the topmidnone enum, and rename it centernone. + (DLR) - rcfile.c: nregcomp() - Return TRUE when the compilation succeeds and FALSE otherwise, @@ -109,7 +111,8 @@ CVS code - - Remove unnecessary renumber(). (DLR) do_gotolinecolumn() - Add parameter allow_update to control whether the screen is - updated after moving. (DLR) + updated after moving. If it's TRUE, call edit_refresh() after + edit_update(). (DLR) do_gotopos() - Only include this function when DISABLE_SPELLER isn't defined, as the alternate spell checking code is now the only place @@ -117,6 +120,9 @@ CVS code - - winio.c: edit_scroll(), edit_redraw(), edit_refresh() - Clean up and simplify. (DLR) + edit_update() + - Since we no longer use TOP, remove references to it. Also, + don't call edit_refresh() anymore: it will call us. (DLR) do_statusbar_next_word() - Rework to be more like do_statusbar_prev_word(), to avoid a potential problem if we start at the end of a line. (DLR) diff --git a/src/color.c b/src/color.c index b1085822..c54a7bf8 100644 --- a/src/color.c +++ b/src/color.c @@ -161,8 +161,6 @@ void color_update(void) REG_EXTENDED | (tmpcolor->icase ? REG_ICASE : 0)); } } - - color_init(); } #endif /* ENABLE_COLOR */ diff --git a/src/files.c b/src/files.c index d4bba67f..2f2b7341 100644 --- a/src/files.c +++ b/src/files.c @@ -1586,8 +1586,10 @@ int write_file(const char *name, FILE *f_open, bool tmp, int append, realname); #ifdef ENABLE_COLOR /* We might have changed the filename, so update the colors - * to account for it. */ + * to account for it, and then make sure we're using + * them. */ color_update(); + color_init(); /* If color syntaxes are available and turned on, we need to * call edit_refresh(). */ diff --git a/src/move.c b/src/move.c index ac0f79e7..d12bbb59 100644 --- a/src/move.c +++ b/src/move.c @@ -40,7 +40,7 @@ void do_first_line(void) if (openfile->edittop != openfile->fileage || need_vertical_update(pww_save)) - edit_update(TOP); + edit_update(CENTER); } void do_last_line(void) diff --git a/src/nano.h b/src/nano.h index bf0e5b5f..e39df7f8 100644 --- a/src/nano.h +++ b/src/nano.h @@ -149,8 +149,8 @@ typedef enum { } updown; typedef enum { - TOP, CENTER, NONE -} topmidnone; + CENTER, NONE +} centernone; /* Structure types. */ typedef struct filestruct { diff --git a/src/proto.h b/src/proto.h index a69101f7..f79d5cbb 100644 --- a/src/proto.h +++ b/src/proto.h @@ -671,7 +671,7 @@ int need_vertical_update(size_t old_pww); void edit_scroll(updown direction, int nlines); void edit_redraw(const filestruct *old_current, size_t old_pww); void edit_refresh(void); -void edit_update(topmidnone location); +void edit_update(centernone location); int do_yesno(bool all, const char *msg); void total_redraw(void); void total_refresh(void); diff --git a/src/search.c b/src/search.c index fccf7b21..0fc9e8cf 100644 --- a/src/search.c +++ b/src/search.c @@ -1026,10 +1026,14 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer, openfile->current_x = actual_x(openfile->current->data, column - 1); openfile->placewewant = column - 1; - /* If allow_update is TRUE, update the edit window. If save_pos is - * TRUE, don't change the cursor position when doing it. */ + /* Put the top line of the edit window in range of the current line. + * If save_pos is TRUE, don't change the cursor position when doing + * it. */ + edit_update(save_pos ? NONE : CENTER); + + /* If allow_update is TRUE, update the screen. */ if (allow_update) - edit_update(save_pos ? NONE : CENTER); + edit_refresh(); display_main_list(); } diff --git a/src/winio.c b/src/winio.c index ff37fc11..dffbeab9 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3607,73 +3607,71 @@ void edit_redraw(const filestruct *old_current, size_t old_pww) /* Refresh the screen without changing the position of lines. */ void edit_refresh(void) { + int nlines = 0; + const filestruct *foo = openfile->edittop; + if (openfile->current->lineno < openfile->edittop->lineno || openfile->current->lineno >= openfile->edittop->lineno + editwinrows) - /* Note that edit_update() changes edittop so that it's in range - * of current. Thus, when it then calls edit_refresh(), there - * is no danger of getting an infinite loop. */ + /* Put the top line of the edit window in the range of the + * current line. */ edit_update( #ifndef NANO_SMALL ISSET(SMOOTH_SCROLL) ? NONE : #endif CENTER); - else { - int nlines = 0; - const filestruct *foo = openfile->edittop; #ifdef DEBUG - fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", (long)openfile->edittop->lineno); + fprintf(stderr, "edit_refresh(): edittop->lineno = %ld\n", (long)openfile->edittop->lineno); #endif - while (nlines < editwinrows && foo != NULL) { - update_line(foo, (foo == openfile->current) ? + while (nlines < editwinrows && foo != NULL) { + update_line(foo, (foo == openfile->current) ? openfile->current_x : 0); - foo = foo->next; - nlines++; - } - while (nlines < editwinrows) { - blank_line(edit, nlines, 0, COLS); - nlines++; - } - reset_cursor(); - wrefresh(edit); + foo = foo->next; + nlines++; + } + + while (nlines < editwinrows) { + blank_line(edit, nlines, 0, COLS); + nlines++; } + + reset_cursor(); + wrefresh(edit); } -/* A nice generic routine to update the edit buffer. We keep current in - * the same place and move edittop to put it in range of current. */ -void edit_update(topmidnone location) +/* Move edittop to put it in range of current, keeping current in the + * same place. location determines how we move it: if it's CENTER, we + * center current, and if it's NONE, we put current current_y lines + * below edittop. */ +void edit_update(centernone location) { filestruct *foo = openfile->current; + int goal; + + /* If location is CENTER, we move edittop up (editwinrows / 2) + * lines. This puts current at the center of the screen. If + * location is NONE, we move edittop up current_y lines if current_y + * is in range of the screen, 0 lines if current_y is less than 0, + * or (editwinrows - 1) lines if current_y is greater than + * (editwinrows - 1). This puts current at the same place on the + * screen as before, or at the top or bottom of the screen if + * edittop is beyond either. */ + if (location == CENTER) + goal = editwinrows / 2; + else { + goal = openfile->current_y; - if (location != TOP) { - /* If location is CENTER, we move edittop up (editwinrows / 2) - * lines. This puts current at the center of the screen. If - * location is NONE, we move edittop up current_y lines if - * current_y is in range of the screen, 0 lines if current_y is - * less than 0, or (editwinrows - 1) lines if current_y is - * greater than (editwinrows - 1). This puts current at the - * same place on the screen as before, or at the top or bottom - * of the screen if edittop is beyond either. */ - int goal; - - if (location == CENTER) - goal = editwinrows / 2; - else { - goal = openfile->current_y; - - /* Limit goal to (editwinrows - 1) lines maximum. */ - if (goal > editwinrows - 1) - goal = editwinrows - 1; - } - - for (; goal > 0 && foo->prev != NULL; goal--) - foo = foo->prev; + /* Limit goal to (editwinrows - 1) lines maximum. */ + if (goal > editwinrows - 1) + goal = editwinrows - 1; } + for (; goal > 0 && foo->prev != NULL; goal--) + foo = foo->prev; + openfile->edittop = foo; - edit_refresh(); } /* Ask a simple yes/no question, specified in msg, on the statusbar.