nano

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

commit 132ed5c8f053eaa8cc70a170bca1fbbe2575477c
parent bd88b8b5a6206110856f0bcf0be3e9af4e8636ff
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Fri, 28 Feb 2020 15:21:36 +0100

tweaks: instead of swapping the end points later, assign them correctly

(This also makes it clear that the naming of 'head' and 'tail'
is the wrong way around for CUT too.)

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

diff --git a/src/text.c b/src/text.c @@ -1179,9 +1179,17 @@ void add_undo(undo_type action, const char *message) case ZAP: case CUT: if (openfile->mark) { - u->tail_lineno = openfile->mark->lineno; - u->tail_x = openfile->mark_x; u->xflags |= MARK_WAS_SET; + if (openfile->mark->lineno < openfile->current->lineno || + (openfile->mark == openfile->current && + openfile->mark_x < openfile->current_x)) { + u->tail_lineno = openfile->mark->lineno; + u->tail_x = openfile->mark_x; + u->xflags |= WAS_MARKED_FORWARD; + } else { + u->head_lineno = openfile->mark->lineno; + u->head_x = openfile->mark_x; + } if (openfile->current == openfile->filebot || openfile->mark == openfile->filebot) u->xflags |= WAS_FINAL_LINE; @@ -1323,22 +1331,7 @@ void update_undo(undo_type action) free_lines(u->cutbuffer); u->cutbuffer = copy_buffer(cutbuffer); } - if (u->xflags & MARK_WAS_SET) { - /* If the region was marked backwards, swap the end points. */ - if (u->head_lineno < u->tail_lineno || - (u->head_lineno == u->tail_lineno && - u->head_x < u->tail_x)) { - ssize_t number = u->head_lineno; - size_t position = u->head_x; - - u->head_lineno = u->tail_lineno; - u->head_x = u->tail_x; - - u->tail_lineno = number; - u->tail_x = position; - } else - u->xflags |= WAS_MARKED_FORWARD; - } else { + if (!(u->xflags & MARK_WAS_SET)) { linestruct *bottomline = u->cutbuffer; size_t count = 0;