-
Notifications
You must be signed in to change notification settings - Fork 13
Updated the implementation for hscroll area #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,12 +122,19 @@ let view (patches : Patch.t list) = | |
| | None -> failwith "zipper_of_list: empty list" | ||
| in | ||
| let curr_scroll_state = Lwd.var W.default_scroll_state in | ||
| let curr_scroll_state_h = Lwd.var W.default_scroll_state in | ||
| let change_scroll_state _action state = | ||
| let off_screen = state.W.position > state.W.bound in | ||
| if off_screen then | ||
| Lwd.set curr_scroll_state { state with position = state.W.bound } | ||
| else Lwd.set curr_scroll_state state | ||
| in | ||
| let change_scroll_state_h _action state = | ||
| let off_screen = state.W.position > state.W.bound in | ||
| if off_screen then | ||
| Lwd.set curr_scroll_state_h { state with position = state.W.bound } | ||
| else Lwd.set curr_scroll_state_h state | ||
| in | ||
| let ui = | ||
| let$* help_visible = Lwd.get help in | ||
| if help_visible then | ||
|
|
@@ -149,9 +156,19 @@ let view (patches : Patch.t list) = | |
| operation_info z_patches; | ||
| change_summary z_patches; | ||
| current_operation z_patches; | ||
| W.vscroll_area | ||
| ~state:(Lwd.get curr_scroll_state) | ||
| ~change:change_scroll_state | ||
| (* W.vscroll_area | ||
| ~state:(Lwd.get curr_scroll_state) | ||
| ~change:change_scroll_state | ||
| @@ W.hscroll_area | ||
| ~state:(Lwd.get curr_scroll_state_h) | ||
| ~change:change_scroll_state_h | ||
| @@ current_hunks z_patches; *) | ||
| W.hscroll_area | ||
| ~state:(Lwd.get curr_scroll_state_h) | ||
| ~change:change_scroll_state_h | ||
| @@ W.vscroll_area | ||
| ~state:(Lwd.get curr_scroll_state) | ||
| ~change:change_scroll_state | ||
| @@ current_hunks z_patches; | ||
| Lwd.pure | ||
| @@ Ui.keyboard_area | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test ? A good test would use the recent cram test and would add a new diff file dedicated to testing scroll. The test would use the sequences of keys that you found to misbehave during your testing.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok sure @Julow, Thank you for your suggestion to add a test for the scrolling functionality. I'll work on adding a new cram test
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Key bindings would be a great addition ! In what other tools are
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Julow, I understand that we currently use h for opening the help panel. we may need to explore alternative options for incorporating horizontal scrolling keys while ensuring consistency and usability in our application. What are your thoughts on this?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! Then
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can you describe the unexpected behavior and how to get to it ? I notice one unexpected behavior: I'm not sure why this happens by reading the code. Could you try printing the values of the states. Here's a setup that can work with two terminals: In one terminal run the app with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'll investigate further and try to understand why the right key is not having any effect, I'll set up the suggested environment with two terminals as you described. Thanks for your guidance, and I'll keep you updated on my progress! |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,6 +196,48 @@ let vscroll_area ~state ~change t = | |
| |> Ui.mouse_area (scroll_handler state) | ||
| |> Ui.keyboard_area (focus_handler state) | ||
| end | ||
| let hscroll_area ~state ~change t = | ||
| let visible = ref (-1) in | ||
| let total = ref (-1) in | ||
| let scroll state delta = | ||
| let position = state.position + delta in | ||
| let position = clampi position ~min:0 ~max:state.bound in | ||
| if position <> state.position then | ||
| change `Action {state with position}; | ||
| `Handled | ||
| in | ||
| let focus_handler state = function | ||
| | `Arrow `Left , [] -> scroll state (-scroll_step) | ||
| | `Arrow `Right, [] -> scroll state (+scroll_step) | ||
| | _ -> `Unhandled | ||
| in | ||
| (* let scroll_handler state ~x:_ ~y:_ = function | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, no scroll handler is possible, you can remove the comment entirely. |
||
| | `Scroll `Up -> scroll state (0) | ||
| | `Scroll `Down -> scroll state (0) | ||
| | _ -> `Unhandled | ||
| in *) | ||
| Lwd.map2 t state ~f:begin fun t state -> | ||
| t | ||
| |> Ui.shift_area state.position 0 | ||
| |> Ui.resize ~w:0 ~sw:1 | ||
| |> Ui.size_sensor (fun ~w ~h:_ -> | ||
| let tchange = | ||
| if !total <> (Ui.layout_spec t).Ui.w | ||
| then (total := (Ui.layout_spec t).Ui.w; true) | ||
| else false | ||
| in | ||
| let vchange = | ||
| if !visible <> w | ||
| then (visible := w; true) | ||
| else false | ||
| in | ||
| if tchange || vchange then | ||
| change `Content {state with visible = !visible; total = !total; | ||
| bound = maxi 0 (!total - !visible); } | ||
| ) | ||
| (* |> Ui.mouse_area (scroll_handler state) *) | ||
| |> Ui.keyboard_area (focus_handler state) | ||
| end | ||
|
|
||
| let scroll_area ?(offset=0,0) t = | ||
| let offset = Lwd.var offset in | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing scroll related function and variable could be renamed to have
_vto make things clear.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that clear and descriptive names are essential for maintaining readability.