justify: keep the cursor at the original end of a marked region

When justifying a region that was marked backwards, the cursor
should stay at the beginning of this region.  The old logic was
faulty because mark_is_before_cursor() does not give the correct
result *after* the justification has been done: for some reason
the mark ends up always before the cursor.

Bug existed since version 5.2, commit 0f8423eb,
which mistakenly removed the auxiliary variable.  :/
This commit is contained in:
Benno Schulenberg 2024-03-19 16:24:48 +01:00
parent bb7a9fe7d2
commit e1c6ae7cf3

View File

@ -1767,6 +1767,7 @@ void justify_text(bool whole_buffer)
/* The length of that later lead. */
ssize_t was_the_linenumber = openfile->current->lineno;
/* The line to return to after a full justification. */
bool marked_backward = (openfile->mark && !mark_is_before_cursor());
/* TRANSLATORS: This one goes with Undid/Redid messages. */
add_undo(COUPLE_BEGIN, N_("justification"));
@ -1976,7 +1977,7 @@ void justify_text(bool whole_buffer)
update_undo(PASTE);
/* After justifying a backward-marked text, swap mark and cursor. */
if (openfile->mark && !mark_is_before_cursor()) {
if (marked_backward) {
linestruct *bottom = openfile->current;
size_t bottom_x = openfile->current_x;