Index: src/cut.c =================================================================== --- src/cut.c (revision 4962) +++ src/cut.c (working copy) @@ -280,6 +280,11 @@ update_undo(PASTE); #endif +#ifndef DISABLE_WRAPPING + if (!ISSET(NO_WRAP)) + do_wrap(openfile->current); +#endif + /* Set the current place we want to where the text from the * cutbuffer ends. */ openfile->placewewant = xplustabs(); Index: src/text.c =================================================================== --- src/text.c (revision 4962) +++ src/text.c (working copy) @@ -439,7 +439,7 @@ undo *u = openfile->current_undo; filestruct *t = 0; size_t len = 0; - char *undidmsg, *data; + char *undidmsg=NULL, *data; filestruct *oldcutbuffer = cutbuffer, *oldcutbottom = cutbottom; if (!u) { @@ -483,7 +483,6 @@ break; #ifndef DISABLE_WRAPPING case SPLIT_END: - undidmsg = _("line wrap"); goto_line_posx(u->lineno, u->begin); openfile->current_undo = openfile->current_undo->next; openfile->last_action = OTHER; @@ -491,6 +490,7 @@ do_undo(); u = openfile->current_undo; f = openfile->current; + case SPLIT_BEGIN: break; #endif /* !DISABLE_WRAPPING */ case UNSPLIT: @@ -557,6 +557,7 @@ renumber(f); if (gotolinecolumn) do_gotolinecolumn(u->lineno, u->begin, FALSE, FALSE, FALSE, TRUE); + if(undidmsg) statusbar(_("Undid action (%s)"), undidmsg); openfile->current_undo = openfile->current_undo->next; openfile->last_action = OTHER; @@ -569,7 +570,7 @@ bool gotolinecolumn = FALSE; undo *u = openfile->undotop; size_t len = 0; - char *undidmsg, *data; + char *undidmsg=NULL, *data; for (; u != NULL && u->next != openfile->current_undo; u = u->next) ; @@ -624,7 +625,6 @@ break; #ifndef DISABLE_WRAPPING case SPLIT_BEGIN: - undidmsg = _("line wrap"); goto_line_posx(u->lineno, u->begin); openfile->current_undo = u; openfile->last_action = OTHER; @@ -632,6 +632,7 @@ do_redo(); u = openfile->current_undo; goto_line_posx(u->lineno, u->begin); + case SPLIT_END: break; #endif /* !DISABLE_WRAPPING */ case UNSPLIT: @@ -675,6 +676,7 @@ if (gotolinecolumn) do_gotolinecolumn(u->lineno, u->begin, FALSE, FALSE, FALSE, TRUE); + if(undidmsg) statusbar(_("Redid action (%s)"), undidmsg); openfile->current_undo = u; @@ -1126,6 +1128,30 @@ prepend_wrap = FALSE; } +ssize_t get_wrap_index(filestruct *line, size_t line_len) +{ + /* Find the last blank where we can break the line. */ + ssize_t wrap_loc = break_line(line->data, fill +#ifndef DISABLE_HELP + , FALSE +#endif + ); + + /* If we couldn't break the line, or we've reached the end of it, we + * don't wrap. */ + if (wrap_loc == -1 || wrap_loc >= line_len) + return 0; + + /* Otherwise, move forward to the character just after the blank. */ + wrap_loc += move_mbright(line->data + wrap_loc, 0); + + /* After the move, check again. If we've reached the end of the line, we don't wrap. */ + if (wrap_loc >= line_len) + return 0; + + return wrap_loc; +} + /* Try wrapping the given line. Return TRUE if wrapped, FALSE otherwise. */ bool do_wrap(filestruct *line) { @@ -1133,12 +1159,6 @@ /* The length of the line we wrap. */ ssize_t wrap_loc; /* The index of line->data where we wrap. */ -#ifndef NANO_TINY - const char *indent_string = NULL; - /* Indentation to prepend to the new line. */ - size_t indent_len = 0; - /* The length of indent_string. */ -#endif const char *after_break; /* The text after the wrap point. */ size_t after_break_len; @@ -1167,36 +1187,11 @@ line_len = strlen(line->data); /* Find the last blank where we can break the line. */ - wrap_loc = break_line(line->data, fill -#ifndef DISABLE_HELP - , FALSE -#endif - ); - - /* If we couldn't break the line, or we've reached the end of it, we - * don't wrap. */ - if (wrap_loc == -1 || line->data[wrap_loc] == '\0') + wrap_loc = get_wrap_index(line, line_len); + if (!wrap_loc) return FALSE; - /* Otherwise, move forward to the character just after the blank. */ - wrap_loc += move_mbright(line->data + wrap_loc, 0); - - /* If we've reached the end of the line, we don't wrap. */ - if (line->data[wrap_loc] == '\0') - return FALSE; - #ifndef NANO_TINY - /* If autoindent is turned on, and we're on the character just after - * the indentation, we don't wrap. */ - if (ISSET(AUTOINDENT)) { - /* Get the indentation of this line. */ - indent_string = line->data; - indent_len = indent_length(indent_string); - - if (wrap_loc == indent_len) - return FALSE; - } - add_undo(SPLIT_BEGIN); #endif @@ -1254,19 +1249,33 @@ } } + if (old_x < wrap_loc) + prepend_wrap = TRUE; + else + prepend_wrap = FALSE; + + while(wrap_loc){ /* Go to the wrap location and split the line there. */ openfile->current_x = wrap_loc; do_enter(FALSE); - if (old_x < wrap_loc) { - openfile->current_x = old_x; - openfile->current = oldLine; + line = openfile->current; + assert(line != NULL && line->data != NULL); + + if(!prepend_wrap) + old_x = openfile->current_x + old_x - wrap_loc; + /* Find the last blank where we can break the line. */ + wrap_loc = get_wrap_index(line, strlen(line->data)); + + if (!prepend_wrap && old_x < wrap_loc){ prepend_wrap = TRUE; - } else { - openfile->current_x += (old_x - wrap_loc); - prepend_wrap = FALSE; + oldLine = openfile->current; } + } + if (prepend_wrap) + openfile->current = oldLine; + openfile->current_x = old_x; openfile->placewewant = xplustabs(); #ifndef NANO_TINY