From b843a51b790c8000a802a766b8bb3e1e60eb6e69 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Tue, 21 Apr 2009 05:34:08 +0000 Subject: [PATCH] Add undo for line break via enter, separate from line wrap Change message for line split to line wrap, since split ~= break git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4391 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- src/nano.h | 2 +- src/text.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/nano.h b/src/nano.h index 5fc5ce7c..1eb2a1fc 100644 --- a/src/nano.h +++ b/src/nano.h @@ -180,7 +180,7 @@ typedef enum { } function_type; typedef enum { - ADD, DEL, REPLACE, SPLIT, UNSPLIT, CUT, UNCUT, INSERT, OTHER + ADD, DEL, REPLACE, SPLIT, UNSPLIT, CUT, UNCUT, ENTER, INSERT, OTHER } undo_type; #ifdef ENABLE_COLOR diff --git a/src/text.c b/src/text.c index 3b7f9a26..1c809203 100644 --- a/src/text.c +++ b/src/text.c @@ -474,7 +474,7 @@ void do_undo(void) openfile->current_x += strlen(u->strdata); break; case SPLIT: - undidmsg = _("line split"); + undidmsg = _("line wrap"); f->data = nrealloc(f->data, strlen(f->data) + strlen(u->strdata) + 1); strcpy(&f->data[strlen(f->data) - 1], u->strdata); if (u->xflags & UNDO_SPLIT_MADENEW) { @@ -505,6 +505,16 @@ void do_undo(void) undidmsg = _("text uncut"); redo_cut(u); break; + case ENTER: + undidmsg = _("line break"); + if (f->next) { + f->data = nrealloc(f->data, strlen(f->data) + strlen(f->next->data) + 1); + strcat(f->data, f->next->data); + filestruct *foo = f->next; + unlink_node(foo); + delete_node(foo); + } + break; case INSERT: undidmsg = _("text insert"); cutbuffer = NULL; @@ -529,11 +539,13 @@ void do_undo(void) u->strdata = f->data; f->data = data; break; + default: undidmsg = _("Internal error: unknown type. Please save your work"); break; } + renumber(f); do_gotolinecolumn(u->lineno, u->begin, FALSE, FALSE, FALSE, TRUE); statusbar(_("Undid action (%s)"), undidmsg); openfile->current_undo = openfile->current_undo->next; @@ -593,8 +605,13 @@ void do_redo(void) free(f->data); f->data = data; break; + case ENTER: + undidmsg = _("line break"); + do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE); + do_enter(); + break; case SPLIT: - undidmsg = _("line split"); + undidmsg = _("line wrap"); t = make_new_node(f); t->data = mallocstrcpy(NULL, &u->strdata[u->begin]); data = mallocstrncpy(NULL, f->data, u->begin); @@ -662,7 +679,7 @@ void do_enter(void) assert(openfile->current != NULL && openfile->current->data != NULL); #ifndef NANO_TINY - update_undo(SPLIT); + update_undo(ENTER); /* Do auto-indenting, like the neolithic Turbo Pascal editor. */ @@ -909,6 +926,8 @@ void add_undo(undo_type current_action) u->cutbottom = last_cutu->cutbottom; } break; + case ENTER: + break; case OTHER: statusbar(_("Internal error: unknown type. Please save your work.")); break; -- 2.39.5