diff --git a/src/utils.c b/src/utils.c index 849cebcb..8a5e8499 100644 --- a/src/utils.c +++ b/src/utils.c @@ -450,15 +450,15 @@ void remove_magicline(void) #endif #ifndef NANO_TINY -/* Set (top, top_x) and (bot, bot_x) to the start and end "coordinates" of - * the marked region. If right_side_up isn't NULL, set it to TRUE when the - * mark is at the top of the marked region, and to FALSE otherwise. */ +/* Return in (top, top_x) and (bot, bot_x) the start and end "coordinates" + * of the marked region. If right_side_up isn't NULL, set it to TRUE when + * the mark is at the top of the marked region, and to FALSE otherwise. */ void get_region(const linestruct **top, size_t *top_x, - const linestruct **bot, size_t *bot_x, bool *right_side_up) + const linestruct **bot, size_t *bot_x, bool *right_side_up) { - if ((openfile->current->lineno == openfile->mark->lineno && - openfile->current_x > openfile->mark_x) || - openfile->current->lineno > openfile->mark->lineno) { + if (openfile->mark->lineno < openfile->current->lineno || + (openfile->mark == openfile->current && + openfile->mark_x < openfile->current_x)) { *top = openfile->mark; *top_x = openfile->mark_x; *bot = openfile->current;