/* Generic pointer for data regardless of what type it is */
struct undo *next;
ssize_t lineno;
+ int xflags;
} undo;
#endif /* NANO_TINY */
#define TOGGLE_BACKWARDS_KEY NANO_META_B
#define TOGGLE_DOS_KEY NANO_META_D
#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 */
#define VIEW TRUE
strcpy(&data[u->begin + strlen(u->strdata)], &f->data[u->begin]);
free(f->data);
f->data = data;
- openfile->current_x += strlen(u->strdata);
+ if (u->xflags == UNDO_DEL_BACKSPACE)
+ openfile->current_x += strlen(u->strdata);
break;
case SPLIT:
action = _("line split");
unlink_node(tmp);
delete_node(tmp);
}
- renumber(openfile->current->prev);
+ renumber(f);
break;
case UNSPLIT:
action = _("line join");
free(f->data);
f->data = data;
splice_node(f, t, f->next);
- renumber(openfile->current->prev);
+ renumber(f);
break;
default:
action = _("wtf?");
free(f->data);
f->data = data;
splice_node(f, t, f->next);
- renumber(openfile->current->prev);
+ renumber(f);
break;
case UNSPLIT:
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);
- f->data = mallocstrcpy(NULL, u->strdata);
+ f->data = data;
if (f->next != NULL) {
filestruct *tmp = f->next;
unlink_node(tmp);
delete_node(tmp);
}
- renumber(openfile->current->prev);
+ renumber(f);
break;
default:
action = _("wtf?");
u->lineno = fs->current->lineno;
u->begin = fs->current_x;
u->fs = fs->current;
+ u->xflags = 0;
u->next = fs->undotop;
fs->undotop = u;
fs->current_undo = u;
assert(fs->undotop != NULL);
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);
return;
}
assert(len > 2);
if (fs->current_x == u->begin) {
/* 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);
strcpy(data, u->strdata);
data[len-2] = fs->current->data[fs->current_x];;
u->strdata = data;
} else if (fs->current_x == u->begin - 1) {
/* 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[0] = fs->current->data[fs->current_x];
strcpy(&data[1], u->strdata);
return;
}
#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
break;
case SPLIT: