Fix using Page-Up in TUI source window close to the top

Currently, when you're already less than a page from the top in the TUI
source window, and you press Page-Up, nothing happens, while I would
expect that it then scrolls the source up to the first line.

It's happening because scrolling a full page up would result in a
negative starting line number, which is then checked if it's higher than
the (unsigned) number of available lines, and since this will always be
true, the original starting line number is restored.
Afterwards it would check if the line number is too low, but since the
negative value was already gone, it didn't do much.

Fixed by moving the low line number check before the maximum line number
check.

Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Hannes Domani 2024-11-11 17:13:28 +01:00
parent df0445b370
commit 427cc3b541

View File

@ -164,12 +164,12 @@ tui_source_window::do_scroll_vertical (int num_to_scroll)
s = cursal.symtab;
int line_no = m_start_line_or_addr.u.line_no + num_to_scroll;
if (line_no <= 0)
line_no = 1;
const std::vector<off_t> *offsets;
if (g_source_cache.get_line_charpos (s, &offsets)
&& line_no > offsets->size ())
line_no = m_start_line_or_addr.u.line_no;
if (line_no <= 0)
line_no = 1;
cursal.line = line_no;
find_line_pc (cursal.symtab, cursal.line, &cursal.pc);