From 87dcfa6edd43316068347ff5b8f23c76bdc7b472 Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Thu, 30 May 2024 10:04:25 -0500 Subject: Add half-screen down/up scrolling --- lib/stitched_article.ml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/stitched_article.ml') diff --git a/lib/stitched_article.ml b/lib/stitched_article.ml index 9548e11..9df2bd6 100644 --- a/lib/stitched_article.ml +++ b/lib/stitched_article.ml @@ -72,14 +72,17 @@ let rec render in Common.Term.image t img; let content_length = Array.length content_pretty in - let scroll_up () = - let scroll = if y - content_start - scroll = 0 then max (scroll - 1) 0 else scroll in - render t @@ { state with pos = x, max (y - 1) content_start; scroll; output = None } + let scroll_up ?(amount = 1) () = + let scroll = + if y - content_start - scroll - amount < 0 then max (scroll - amount) 0 else scroll + in + render t { state with pos = x, max (y - amount) content_start; scroll; output = None } in - let scroll_down () = - let scroll = if y - scroll >= size_y - 1 then scroll + 1 else scroll in - render t - @@ { state with pos = x, min (y + 1) (content_length - 1); scroll; output = None } + let scroll_down ?(amount = 1) () = + let scroll = if y - scroll >= size_y - amount then scroll + amount else scroll in + render + t + { state with pos = x, min (y + amount) content_length; scroll; output = None } in match Common.Term.event t with | `End | `Key (`Escape, []) | `Key (`ASCII 'q', []) | `Key (`ASCII 'C', [ `Ctrl ]) -> () @@ -120,6 +123,10 @@ let rec render } in Input_prompt.render t input_state + | `Key (`ASCII 'D', [ `Ctrl ]) | `Key (`Page `Down, []) -> + scroll_down ~amount:(size_y / 2) () + | `Key (`ASCII 'U', [ `Ctrl ]) | `Key (`Page `Up, []) -> + scroll_up ~amount:(size_y / 2) () | `Key (`ASCII '!', []) -> let file_number_offset, content_line = Array.get content_pretty (y - content_start) in let content_line = Grep.display_type_line content_line in -- cgit v1.2.3