+2014-06-08 Mark Majeres <mark@engine12.com>
+ * src/text.c (do_delete, do_deletion, do_undo, do_redo, update_undo):
+ Differentiate between undoing a Delete and undoing a Backspace -- the
+ cursor should be in a slightly but significantly different position.
+
2014-06-04 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (shortcut_init), src/files.c (do_insertfile): Rename
'ext_cmd_void' to 'flip_execute_void' to better match what it does.
} function_type;
typedef enum {
- ADD, DEL, REPLACE, SPLIT, UNSPLIT, CUT, CUT_EOF, PASTE, ENTER, INSERT, OTHER
+ ADD, DEL, BACK, REPLACE, SPLIT, UNSPLIT, CUT, CUT_EOF, PASTE, ENTER, INSERT, OTHER
} undo_type;
typedef struct color_pair {
#endif /* !NANO_TINY */
/* Delete the character under the cursor. */
-void do_delete(void)
+void do_deletion(undo_type action)
{
size_t orig_lenpt = 0;
assert(openfile->current_x < strlen(openfile->current->data));
#ifndef NANO_TINY
- update_undo(DEL);
+ update_undo(action);
#endif
if (ISSET(SOFTWRAP))
orig_lenpt = strlenpt(openfile->current->data);
assert(openfile->current_x == strlen(openfile->current->data));
#ifndef NANO_TINY
- add_undo(DEL);
+ add_undo(action);
#endif
/* If we're deleting at the end of a line, we need to call
* edit_refresh(). */
update_line(openfile->current, openfile->current_x);
}
+void do_delete(void)
+{
+ do_deletion(DEL);
+}
+
/* Backspace over one character. That is, move the cursor left one
* character, and then delete the character under the cursor. */
void do_backspace(void)
if (openfile->current != openfile->fileage ||
openfile->current_x > 0) {
do_left();
- do_delete();
+ do_deletion(BACK);
}
}
f->data = data;
goto_line_posx(u->lineno, u->begin);
break;
+ case BACK:
case DEL:
undidmsg = _("text delete");
len = strlen(f->data) + strlen(u->strdata) + 1;
undidmsg = _("line join");
t = make_new_node(f);
t->data = mallocstrcpy(NULL, u->strdata);
- data = mallocstrncpy(NULL, f->data, u->begin + 1);
- data[u->begin] = '\0';
+ data = mallocstrncpy(NULL, f->data, u->mark_begin_x + 1);
+ data[u->mark_begin_x] = '\0';
free(f->data);
f->data = data;
splice_node(f, t, f->next);
f->data = data;
goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
break;
+ case BACK:
case DEL:
undidmsg = _("text delete");
len = strlen(f->data) + strlen(u->strdata) + 1;
delete_node(tmp);
}
renumber(f);
- goto_line_posx(u->lineno, u->begin);
+ goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
break;
case CUT_EOF:
case CUT:
* or we won't be able to restore it later. */
case ADD:
break;
+ case BACK:
case DEL:
if (u->begin != strlen(fs->current->data)) {
char *char_buf = charalloc(mb_cur_max() + 1);
int char_buf_len = parse_mbchar(&fs->current->data[u->begin], char_buf, NULL);
null_at(&char_buf, char_buf_len);
u->strdata = char_buf;
- u->mark_begin_x += char_buf_len;
+ if (u->type == BACK)
+ u->mark_begin_x += char_buf_len;
break;
}
/* Else purposely fall into unsplit code. */
- current_action = u->type = UNSPLIT;
case UNSPLIT:
if (fs->current->next) {
+ if (u->type == BACK) {
+ u->lineno = fs->current->next->lineno;
+ u->begin = 0;
+ }
data = mallocstrcpy(NULL, fs->current->next->data);
u->strdata = data;
}
+ current_action = u->type = UNSPLIT;
break;
#ifndef DISABLE_WRAPPING
case SPLIT:
u->mark_begin_x = fs->current_x;
break;
}
+ case BACK:
case DEL: {
char *char_buf = charalloc(mb_cur_max());
size_t char_buf_len = parse_mbchar(&fs->current->data[fs->current_x], char_buf, NULL);
} else {
/* They deleted something else on the line. */
free(char_buf);
- add_undo(DEL);
+ add_undo(u->type);
return;
}
#ifdef DEBUG