justify: stay at the same line number when doing a full justification

The same line number may not be the same position in the text, but
it will be approximately -- and it is certainly better than leaving
the cursor at the end of the buffer.

This fulfills https://savannah.gnu.org/bugs/?61175.
This commit is contained in:
Benno Schulenberg 2022-03-24 12:40:28 +01:00
parent 9b014876cd
commit 803ea0d7a0

View File

@ -1761,6 +1761,8 @@ void justify_text(bool whole_buffer)
/* The leading part for lines after the first one. */
size_t secondary_len = 0;
/* The length of that later lead. */
ssize_t was_the_linenumber = openfile->current->lineno;
/* The line to return to after a full justification. */
/* TRANSLATORS: This one goes with Undid/Redid messages. */
add_undo(COUPLE_BEGIN, N_("justification"));
@ -1977,7 +1979,8 @@ void justify_text(bool whole_buffer)
openfile->current_x = openfile->mark_x;
openfile->mark = bottom;
openfile->mark_x = bottom_x;
}
} else if (whole_buffer && !openfile->mark)
goto_line_posx(was_the_linenumber, 0);
add_undo(COUPLE_END, N_("justification"));