Differentiating between undoing a Delete and undoing a Backspace -- the

cursor should be in a slightly but significantly different position.
Patch by Mark Majeres.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4944 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2014-06-08 19:02:12 +00:00
parent 5dfab51576
commit 64896ba2ff
3 changed files with 30 additions and 11 deletions

View File

@ -1,3 +1,8 @@
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> 2014-06-04 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (shortcut_init), src/files.c (do_insertfile): Rename * src/global.c (shortcut_init), src/files.c (do_insertfile): Rename
'ext_cmd_void' to 'flip_execute_void' to better match what it does. 'ext_cmd_void' to 'flip_execute_void' to better match what it does.

View File

@ -187,7 +187,7 @@ typedef enum {
} function_type; } function_type;
typedef enum { 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; } undo_type;
typedef struct color_pair { typedef struct color_pair {

View File

@ -64,7 +64,7 @@ void do_mark(void)
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
/* Delete the character under the cursor. */ /* Delete the character under the cursor. */
void do_delete(void) void do_deletion(undo_type action)
{ {
size_t orig_lenpt = 0; size_t orig_lenpt = 0;
@ -81,7 +81,7 @@ void do_delete(void)
assert(openfile->current_x < strlen(openfile->current->data)); assert(openfile->current_x < strlen(openfile->current->data));
#ifndef NANO_TINY #ifndef NANO_TINY
update_undo(DEL); update_undo(action);
#endif #endif
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
orig_lenpt = strlenpt(openfile->current->data); orig_lenpt = strlenpt(openfile->current->data);
@ -106,7 +106,7 @@ void do_delete(void)
assert(openfile->current_x == strlen(openfile->current->data)); assert(openfile->current_x == strlen(openfile->current->data));
#ifndef NANO_TINY #ifndef NANO_TINY
add_undo(DEL); add_undo(action);
#endif #endif
/* If we're deleting at the end of a line, we need to call /* If we're deleting at the end of a line, we need to call
* edit_refresh(). */ * edit_refresh(). */
@ -150,6 +150,11 @@ void do_delete(void)
update_line(openfile->current, openfile->current_x); 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 /* Backspace over one character. That is, move the cursor left one
* character, and then delete the character under the cursor. */ * character, and then delete the character under the cursor. */
void do_backspace(void) void do_backspace(void)
@ -157,7 +162,7 @@ void do_backspace(void)
if (openfile->current != openfile->fileage || if (openfile->current != openfile->fileage ||
openfile->current_x > 0) { openfile->current_x > 0) {
do_left(); do_left();
do_delete(); do_deletion(BACK);
} }
} }
@ -459,6 +464,7 @@ void do_undo(void)
f->data = data; f->data = data;
goto_line_posx(u->lineno, u->begin); goto_line_posx(u->lineno, u->begin);
break; break;
case BACK:
case DEL: case DEL:
undidmsg = _("text delete"); undidmsg = _("text delete");
len = strlen(f->data) + strlen(u->strdata) + 1; len = strlen(f->data) + strlen(u->strdata) + 1;
@ -490,8 +496,8 @@ void do_undo(void)
undidmsg = _("line join"); undidmsg = _("line join");
t = make_new_node(f); t = make_new_node(f);
t->data = mallocstrcpy(NULL, u->strdata); t->data = mallocstrcpy(NULL, u->strdata);
data = mallocstrncpy(NULL, f->data, u->begin + 1); data = mallocstrncpy(NULL, f->data, u->mark_begin_x + 1);
data[u->begin] = '\0'; data[u->mark_begin_x] = '\0';
free(f->data); free(f->data);
f->data = data; f->data = data;
splice_node(f, t, f->next); splice_node(f, t, f->next);
@ -597,6 +603,7 @@ void do_redo(void)
f->data = data; f->data = data;
goto_line_posx(u->mark_begin_lineno, u->mark_begin_x); goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
break; break;
case BACK:
case DEL: case DEL:
undidmsg = _("text delete"); undidmsg = _("text delete");
len = strlen(f->data) + strlen(u->strdata) + 1; len = strlen(f->data) + strlen(u->strdata) + 1;
@ -635,7 +642,7 @@ void do_redo(void)
delete_node(tmp); delete_node(tmp);
} }
renumber(f); renumber(f);
goto_line_posx(u->lineno, u->begin); goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
break; break;
case CUT_EOF: case CUT_EOF:
case CUT: case CUT:
@ -891,22 +898,28 @@ void add_undo(undo_type current_action)
* or we won't be able to restore it later. */ * or we won't be able to restore it later. */
case ADD: case ADD:
break; break;
case BACK:
case DEL: case DEL:
if (u->begin != strlen(fs->current->data)) { if (u->begin != strlen(fs->current->data)) {
char *char_buf = charalloc(mb_cur_max() + 1); char *char_buf = charalloc(mb_cur_max() + 1);
int char_buf_len = parse_mbchar(&fs->current->data[u->begin], char_buf, NULL); int char_buf_len = parse_mbchar(&fs->current->data[u->begin], char_buf, NULL);
null_at(&char_buf, char_buf_len); null_at(&char_buf, char_buf_len);
u->strdata = char_buf; u->strdata = char_buf;
u->mark_begin_x += char_buf_len; if (u->type == BACK)
u->mark_begin_x += char_buf_len;
break; break;
} }
/* Else purposely fall into unsplit code. */ /* Else purposely fall into unsplit code. */
current_action = u->type = UNSPLIT;
case UNSPLIT: case UNSPLIT:
if (fs->current->next) { if (fs->current->next) {
if (u->type == BACK) {
u->lineno = fs->current->next->lineno;
u->begin = 0;
}
data = mallocstrcpy(NULL, fs->current->next->data); data = mallocstrcpy(NULL, fs->current->next->data);
u->strdata = data; u->strdata = data;
} }
current_action = u->type = UNSPLIT;
break; break;
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
case SPLIT: case SPLIT:
@ -1019,6 +1032,7 @@ void update_undo(undo_type action)
u->mark_begin_x = fs->current_x; u->mark_begin_x = fs->current_x;
break; break;
} }
case BACK:
case DEL: { case DEL: {
char *char_buf = charalloc(mb_cur_max()); char *char_buf = charalloc(mb_cur_max());
size_t char_buf_len = parse_mbchar(&fs->current->data[fs->current_x], char_buf, NULL); size_t char_buf_len = parse_mbchar(&fs->current->data[fs->current_x], char_buf, NULL);
@ -1033,7 +1047,7 @@ void update_undo(undo_type action)
} else { } else {
/* They deleted something else on the line. */ /* They deleted something else on the line. */
free(char_buf); free(char_buf);
add_undo(DEL); add_undo(u->type);
return; return;
} }
#ifdef DEBUG #ifdef DEBUG