diff options
author | Marc Coquand <marc@mccd.space> | 2024-05-30 10:04:25 -0500 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2024-05-30 10:04:25 -0500 |
commit | 87dcfa6edd43316068347ff5b8f23c76bdc7b472 (patch) | |
tree | c10abd3e81df14e0eaf5b9b1e35d2e76d5ce66e7 /lib/todos.ml | |
parent | 2c0f6e026acb2ecfc1c39d617f47d024e404bb9d (diff) | |
download | stitch-87dcfa6edd43316068347ff5b8f23c76bdc7b472.tar.gz stitch-87dcfa6edd43316068347ff5b8f23c76bdc7b472.tar.bz2 stitch-87dcfa6edd43316068347ff5b8f23c76bdc7b472.zip |
Add half-screen down/up scrolling
Diffstat (limited to '')
-rw-r--r-- | lib/todos.ml | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/todos.ml b/lib/todos.ml index f2e461d..4ee911d 100644 --- a/lib/todos.ml +++ b/lib/todos.ml @@ -94,13 +94,15 @@ let rec render in Common.Term.image t img; let content_end = Array.length content_pretty + (content_start - 1) 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_end; 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_end; scroll; output = None } in match Common.Term.event t with | `End | `Key (`Escape, []) | `Key (`ASCII 'q', []) | `Key (`ASCII 'C', [ `Ctrl ]) -> () @@ -114,6 +116,10 @@ let rec render | `Key (`ASCII '?', []) -> Help_screen.render t { go_back = (fun () -> render t state) } | `Key (`ASCII '1', []) -> goto_headlines (fun () -> render t state) | `Key (`ASCII '3', []) -> goto_done (fun () -> render t 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 'g', []) -> let content, content_pretty = load_todos ~hide_file_name () in let y = min (List.length content_pretty + content_start) y in |