copy: properly set preferred x position when region was marked backwards

This fixes https://savannah.gnu.org/bugs/?49964.
This commit is contained in:
Benno Schulenberg 2016-12-31 16:36:14 +01:00
parent e1538e6dc3
commit d3429a7a57
3 changed files with 11 additions and 6 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;