commit d3429a7a573c832ec2e6dc7731ba6cd2c6fa196e
parent e1538e6dc3434fcda9a42a5b8ecd84c123cd8821
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 31 Dec 2016 16:36:14 +0100
copy: properly set preferred x position when region was marked backwards
This fixes https://savannah.gnu.org/bugs/?49964.
Diffstat:
3 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/cut.c b/src/cut.c
@@ -60,13 +60,13 @@ void cut_line(void)
#ifndef NANO_TINY
/* Move all currently marked text into the cutbuffer, and set the
* current place we want to where the text used to start. */
-void cut_marked(void)
+void cut_marked(bool *right_side_up)
{
filestruct *top, *bot;
size_t top_x, bot_x;
mark_order((const filestruct **)&top, &top_x,
- (const filestruct **)&bot, &bot_x, NULL);
+ (const filestruct **)&bot, &bot_x, right_side_up);
move_to_filestruct(&cutbuffer, &cutbottom, top, top_x, bot, bot_x);
openfile->placewewant = xplustabs();
@@ -124,6 +124,8 @@ void do_cut_text(bool copy_text, bool cut_till_eof)
/* The length of the string at the current end of the cutbuffer,
* before we add text to it. */
bool old_no_newlines = ISSET(NO_NEWLINES);
+ bool right_side_up = TRUE;
+ /* There *is* no region, *or* it is marked forward. */
#endif
size_t was_totsize = openfile->totsize;
@@ -156,7 +158,7 @@ void do_cut_text(bool copy_text, bool cut_till_eof)
cut_to_eof();
} else if (openfile->mark_set) {
/* Move the marked text to the cutbuffer, and turn the mark off. */
- cut_marked();
+ cut_marked(&right_side_up);
openfile->mark_set = FALSE;
} else if (ISSET(CUT_TO_END))
/* Move all text up to the end of the line into the cutbuffer. */
@@ -179,7 +181,10 @@ void do_cut_text(bool copy_text, bool cut_till_eof)
} else
copy_from_filestruct(cutbuffer);
- openfile->placewewant = xplustabs();
+ /* If the copied region was marked forward, put the new desired
+ * x position at its end; otherwise, leave it at its beginning. */
+ if (right_side_up)
+ openfile->placewewant = xplustabs();
}
/* Restore the magicline behavior now that we're done fiddling. */
if (!old_no_newlines)
diff --git a/src/proto.h b/src/proto.h
@@ -276,7 +276,7 @@ void cutbuffer_reset(void);
bool keeping_cutbuffer(void);
void cut_line(void);
#ifndef NANO_TINY
-void cut_marked(void);
+void cut_marked(bool *right_side_up);
void cut_to_eol(void);
void cut_to_eof(void);
#endif
diff --git a/src/text.c b/src/text.c
@@ -798,7 +798,7 @@ void do_undo(void)
openfile->mark_begin_x = u->mark_begin_x;
openfile->mark_set = TRUE;
goto_line_posx(u->lineno, u->begin);
- cut_marked();
+ cut_marked(NULL);
free_filestruct(u->cutbuffer);
u->cutbuffer = cutbuffer;
u->cutbottom = cutbottom;