X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=terminal.c;h=c0c809c6c7751326b21bed9b4664885461ac7da3;hb=d5aa23c1160e7bf866a0f4ff62c652c8b363a662;hp=aaf8705a5f4eafab90020394f273dee7d9d085cd;hpb=97ca111e2953a18c8f75238d2c5bfb0d6017e4eb;p=PuTTY.git diff --git a/terminal.c b/terminal.c index aaf8705a..c0c809c6 100644 --- a/terminal.c +++ b/terminal.c @@ -5136,6 +5136,31 @@ void term_scroll(Terminal *term, int rel, int where) term_update(term); } +/* + * Scroll the scrollback to centre it on the beginning or end of the + * current selection, if any. + */ +void term_scroll_to_selection(Terminal *term, int which_end) +{ + pos target; + int y; + int sbtop = -sblines(term); + + if (term->selstate != SELECTED) + return; + if (which_end) + target = term->selend; + else + target = term->selstart; + + y = target.y - term->rows/2; + if (y < sbtop) + y = sbtop; + else if (y > 0) + y = 0; + term_scroll(term, -1, y); +} + /* * Helper routine for clipme(): growing buffer. */