-2009-12-07 David Lawrence Ramsey <pooka109@gmail.com>
+2009-12-12 Chris Allegretta <chrisa@asty.org>
+ * text.c (do_delete), nano.c (do_output): Add check for length of current line
+ before and after adding/deleting text, and do full refresh if it is now
+ a different multiple of COLS. Also get rid of superfluous do_refresh
+ vars now that we have edit_refresh_needed.
+
+2009-12-09 David Lawrence Ramsey <pooka109@gmail.com>
* global.c (shortcut_init), browser.c (do_browser): Fix M-W not being bound to
research in either main menu or browser.
* TRUE. */
void do_output(char *output, size_t output_len, bool allow_cntrls)
{
- size_t current_len, i = 0;
- bool do_refresh = FALSE;
- /* Do we have to call edit_refresh(), or can we get away with
- * just update_line()? */
-
+ size_t current_len, orig_lenpt, i = 0;
char *char_buf = charalloc(mb_cur_max());
int char_buf_len;
assert(openfile->current != NULL && openfile->current->data != NULL);
current_len = strlen(openfile->current->data);
+ if (ISSET(SOFTWRAP))
+ orig_lenpt = strlenpt(openfile->current->data);
while (i < output_len) {
/* If allow_cntrls is TRUE, convert nulls and newlines
#ifndef DISABLE_WRAPPING
/* If we're wrapping text, we need to call edit_refresh(). */
- if (!ISSET(NO_WRAP)) {
- bool do_refresh_save = do_refresh;
-
- do_refresh = do_wrap(openfile->current, FALSE);
-
- /* If we needed to call edit_refresh() before this, we'll
- * still need to after this. */
- if (do_refresh_save)
- do_refresh = TRUE;
- }
+ if (!ISSET(NO_WRAP))
+ if (do_wrap(openfile->current, FALSE))
+ edit_refresh_needed = TRUE;
#endif
#ifdef ENABLE_COLOR
/* If color syntaxes are available and turned on, we need to
* call edit_refresh(). */
if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX))
- do_refresh = TRUE;
+ edit_refresh_needed = TRUE;
#endif
}
+ /* Well we might also need a full refresh if we've changed the
+ line length to be a new multiple of COLS */
+ if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE)
+ if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS)
+ edit_refresh_needed = TRUE;
+
free(char_buf);
openfile->placewewant = xplustabs();
#ifdef ENABLE_COLOR
reset_multis(openfile->current, FALSE);
#endif
- if (do_refresh) {
+ if (edit_refresh_needed == TRUE) {
edit_refresh();
edit_refresh_needed = FALSE;
} else
/* Delete the character under the cursor. */
void do_delete(void)
{
- bool do_refresh = FALSE;
- /* Do we have to call edit_refresh(), or can we get away with
- * just update_line()? */
+ size_t orig_lenpt = 0;
#ifndef NANO_TINY
update_undo(DEL);
assert(openfile->current_x < strlen(openfile->current->data));
+ if (ISSET(SOFTWRAP))
+ orig_lenpt = strlenpt(openfile->current->data);
+
/* Let's get dangerous. */
charmove(&openfile->current->data[openfile->current_x],
&openfile->current->data[openfile->current_x +
/* If we're deleting at the end of a line, we need to call
* edit_refresh(). */
if (openfile->current->data[openfile->current_x] == '\0')
- do_refresh = TRUE;
+ edit_refresh_needed = TRUE;
openfile->current->data = charealloc(openfile->current->data,
openfile->current_x + strlen(foo->data) + 1);
} else
return;
+ if (ISSET(SOFTWRAP) && edit_refresh_needed == FALSE)
+ if (strlenpt(openfile->current->data) / COLS != orig_lenpt / COLS)
+ edit_refresh_needed = TRUE;
+
set_modified();
- if (do_refresh)
- edit_refresh_needed = TRUE;
- else
+ if (edit_refresh_needed == FALSE)
update_line(openfile->current, openfile->current_x);
}