nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 4c6ec6377fcbb55de368190c8494ba0a10d0527e
parent c545438a5f09f489c555d6132a2cfce7efd339f0
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 25 Sep 2018 18:01:57 +0200

undo: move some special checking code to the one place that needs it

Only for BACK and DEL was the first call to update_undo() -- all other
types of action would call add_undo() first, so for them the action in
update_undo() would never be different, but the line number might have
changed (like for ENTER and INSERT), so for them exceptions needed to
be made, which was wasteful.

This addresses https://savannah.gnu.org/bugs/?54728.

Diffstat:
Msrc/text.c | 18+++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -99,7 +99,13 @@ void do_deletion(undo_type action) openfile->current_x); #ifndef NANO_TINY - update_undo(action); + /* If the type of action changed or the cursor moved to a different + * line, create a new undo item, otherwise update the existing item. */ + if (action != openfile->last_action || + openfile->current->lineno != openfile->current_undo->lineno) + add_undo(action); + else + update_undo(action); if (ISSET(SOFTWRAP)) old_amount = number_of_chunks_in(openfile->current); @@ -1481,16 +1487,6 @@ void update_undo(undo_type action) char *char_buf; int char_len; - /* If the action is different or the position changed, don't update the - * current record but add a new one instead. */ - if (action != openfile->last_action || - (action != ENTER && action != CUT && action != INSERT && - action != COUPLE_END && - openfile->current->lineno != openfile->current_undo->lineno)) { - add_undo(action); - return; - } - u->newsize = openfile->totsize; switch (u->type) {