tweaks: elide an intermediate copy of an added character
In theory this would allow injecting more than one character at a time into the edit buffer. But the creation and updating of an undo item for the addition or the deletion of a character are a bit strange. For all other operations and add_undo() is called before the operation, and an update_undo() afterward. But for an ADD, the add_undo() is called after the operation, and for a DEL/BACK, the update_undo() is called before the operation. There is some logic to that, but things would be easier to understand if all operations were handled the same: an add_undo() beforehand (when needed), and an update_undo() afterward.master
parent
819066c5d5
commit
d13b6d6896
13
src/text.c
13
src/text.c
|
@ -1290,8 +1290,8 @@ void update_multiline_undo(ssize_t lineno, char *indentation)
|
|||
void update_undo(undo_type action)
|
||||
{
|
||||
undostruct *u = openfile->undotop;
|
||||
char *char_buf, *textposition;
|
||||
size_t datalen;
|
||||
size_t datalen, newlen;
|
||||
char *textposition;
|
||||
int charlen;
|
||||
|
||||
if (u->type != action)
|
||||
|
@ -1301,11 +1301,10 @@ void update_undo(undo_type action)
|
|||
|
||||
switch (u->type) {
|
||||
case ADD:
|
||||
char_buf = charalloc(MAXCHARLEN);
|
||||
charlen = collect_char(&openfile->current->data[u->mark_begin_x],
|
||||
char_buf);
|
||||
u->strdata = addstrings(u->strdata, u->strdata ? strlen(u->strdata) : 0,
|
||||
char_buf, charlen);
|
||||
newlen = openfile->current_x - u->begin;
|
||||
u->strdata = charealloc(u->strdata, newlen + 1);
|
||||
strncpy(u->strdata, openfile->current->data + u->begin, newlen);
|
||||
u->strdata[newlen] = '\0';
|
||||
u->mark_begin_lineno = openfile->current->lineno;
|
||||
u->mark_begin_x = openfile->current_x;
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue