Commit 0b499d46 authored by Chris Allegretta's avatar Chris Allegretta
Browse files

Add xflags to undo struct so we can add extra info to the undo process (e.g. backspace vs delete)

Fix redo of a line join.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4282 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 32 additions and 8 deletions
+32 -8
...@@ -261,6 +261,7 @@ typedef struct undo { ...@@ -261,6 +261,7 @@ typedef struct undo {
/* Generic pointer for data regardless of what type it is */ /* Generic pointer for data regardless of what type it is */
struct undo *next; struct undo *next;
ssize_t lineno; ssize_t lineno;
int xflags;
} undo; } undo;
#endif /* NANO_TINY */ #endif /* NANO_TINY */
...@@ -672,6 +673,11 @@ typedef struct subnfunc { ...@@ -672,6 +673,11 @@ typedef struct subnfunc {
#define TOGGLE_BACKWARDS_KEY NANO_META_B #define TOGGLE_BACKWARDS_KEY NANO_META_B
#define TOGGLE_DOS_KEY NANO_META_D #define TOGGLE_DOS_KEY NANO_META_D
#define TOGGLE_MAC_KEY NANO_META_M #define TOGGLE_MAC_KEY NANO_META_M
/* Extra bits for the undo function */
#define UNDO_DEL_DEL (1<<0)
#define UNDO_DEL_BACKSPACE (1<<1)
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
#define VIEW TRUE #define VIEW TRUE
......
...@@ -414,7 +414,8 @@ void do_undo(void) ...@@ -414,7 +414,8 @@ void do_undo(void)
strcpy(&data[u->begin + strlen(u->strdata)], &f->data[u->begin]); strcpy(&data[u->begin + strlen(u->strdata)], &f->data[u->begin]);
free(f->data); free(f->data);
f->data = data; f->data = data;
openfile->current_x += strlen(u->strdata); if (u->xflags == UNDO_DEL_BACKSPACE)
openfile->current_x += strlen(u->strdata);
break; break;
case SPLIT: case SPLIT:
action = _("line split"); action = _("line split");
...@@ -425,7 +426,7 @@ void do_undo(void) ...@@ -425,7 +426,7 @@ void do_undo(void)
unlink_node(tmp); unlink_node(tmp);
delete_node(tmp); delete_node(tmp);
} }
renumber(openfile->current->prev); renumber(f);
break; break;
case UNSPLIT: case UNSPLIT:
action = _("line join"); action = _("line join");
...@@ -436,7 +437,7 @@ void do_undo(void) ...@@ -436,7 +437,7 @@ void do_undo(void)
free(f->data); free(f->data);
f->data = data; f->data = data;
splice_node(f, t, f->next); splice_node(f, t, f->next);
renumber(openfile->current->prev); renumber(f);
break; break;
default: default:
action = _("wtf?"); action = _("wtf?");
...@@ -511,18 +512,22 @@ void do_redo(void) ...@@ -511,18 +512,22 @@ void do_redo(void)
free(f->data); free(f->data);
f->data = data; f->data = data;
splice_node(f, t, f->next); splice_node(f, t, f->next);
renumber(openfile->current->prev); renumber(f);
break; break;
case UNSPLIT: case UNSPLIT:
action = _("line join"); action = _("line join");
len = strlen(f->data) + strlen(u->strdata + 1);
data = charalloc(len);
strcpy(data, f->data);
strcat(data, u->strdata);
free(f->data); free(f->data);
f->data = mallocstrcpy(NULL, u->strdata); f->data = data;
if (f->next != NULL) { if (f->next != NULL) {
filestruct *tmp = f->next; filestruct *tmp = f->next;
unlink_node(tmp); unlink_node(tmp);
delete_node(tmp); delete_node(tmp);
} }
renumber(openfile->current->prev); renumber(f);
break; break;
default: default:
action = _("wtf?"); action = _("wtf?");
...@@ -709,6 +714,7 @@ void add_undo(undo_type current_action, openfilestruct *fs) ...@@ -709,6 +714,7 @@ void add_undo(undo_type current_action, openfilestruct *fs)
u->lineno = fs->current->lineno; u->lineno = fs->current->lineno;
u->begin = fs->current_x; u->begin = fs->current_x;
u->fs = fs->current; u->fs = fs->current;
u->xflags = 0;
u->next = fs->undotop; u->next = fs->undotop;
fs->undotop = u; fs->undotop = u;
fs->current_undo = u; fs->current_undo = u;
...@@ -768,7 +774,7 @@ void update_undo(undo_type action, openfilestruct *fs) ...@@ -768,7 +774,7 @@ void update_undo(undo_type action, openfilestruct *fs)
assert(fs->undotop != NULL); assert(fs->undotop != NULL);
u = fs->undotop; u = fs->undotop;
if (u->fs->data != openfile->current->data) { if (u->fs->data != openfile->current->data || u->lineno != openfile->current->lineno) {
add_undo(action, fs); add_undo(action, fs);
return; return;
} }
...@@ -795,6 +801,12 @@ void update_undo(undo_type action, openfilestruct *fs) ...@@ -795,6 +801,12 @@ void update_undo(undo_type action, openfilestruct *fs)
assert(len > 2); assert(len > 2);
if (fs->current_x == u->begin) { if (fs->current_x == u->begin) {
/* They're deleting */ /* They're deleting */
if (!u->xflags)
u->xflags = UNDO_DEL_DEL;
else if (u->xflags != UNDO_DEL_DEL) {
add_undo(action, fs);
return;
}
data = charalloc(len); data = charalloc(len);
strcpy(data, u->strdata); strcpy(data, u->strdata);
data[len-2] = fs->current->data[fs->current_x];; data[len-2] = fs->current->data[fs->current_x];;
...@@ -803,6 +815,12 @@ void update_undo(undo_type action, openfilestruct *fs) ...@@ -803,6 +815,12 @@ void update_undo(undo_type action, openfilestruct *fs)
u->strdata = data; u->strdata = data;
} else if (fs->current_x == u->begin - 1) { } else if (fs->current_x == u->begin - 1) {
/* They're backspacing */ /* They're backspacing */
if (!u->xflags)
u->xflags = UNDO_DEL_BACKSPACE;
else if (u->xflags != UNDO_DEL_BACKSPACE) {
add_undo(action, fs);
return;
}
data = charalloc(len); data = charalloc(len);
data[0] = fs->current->data[fs->current_x]; data[0] = fs->current->data[fs->current_x];
strcpy(&data[1], u->strdata); strcpy(&data[1], u->strdata);
...@@ -815,7 +833,7 @@ void update_undo(undo_type action, openfilestruct *fs) ...@@ -815,7 +833,7 @@ void update_undo(undo_type action, openfilestruct *fs)
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "current undo data now \"%s\"\n", u->strdata); fprintf(stderr, "current undo data now \"%s\"\nu->begin = %d\n", u->strdata, u->begin);
#endif #endif
break; break;
case SPLIT: case SPLIT:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment