Skip to content

Commit

Permalink
Prevent clicking on stepper steps placing the cursor in random places
Browse files Browse the repository at this point in the history
  • Loading branch information
Negabinary committed Dec 11, 2024
1 parent 399a341 commit 38974de
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 17 deletions.
35 changes: 25 additions & 10 deletions src/haz3lweb/app/editors/decoration/Deco.re
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,31 @@ module Deco =
Some((l, r));
};
};
PieceDec.indicated(
~base_clss="tile-next-step",
~attr=[Virtual_dom.Vdom.Attr.on_mousedown(_ => {inject(i)})],
~line_clss=["next-step-line"],
~font_metrics,
~caret=(Id.invalid, 0),
~rows=measured.rows,
~tiles=[(id, mold, shards)],
)
|> Option.map(_, range);
Option.map(
x => {
PieceDec.indicated(
~base_clss="tile-next-step",
~attr=[Virtual_dom.Vdom.Attr.on_mousedown(_ => {inject(i)})],
~line_clss=["next-step-line"],
~font_metrics,
~caret=(Id.invalid, 0),
~rows=measured.rows,
~tiles=[(id, mold, shards)],
x,
)
@ PieceDec.indicated(
~base_clss="tile-next-step-top",
~attr=[Virtual_dom.Vdom.Attr.on_mousedown(_ => {inject(i)})],
~line_clss=["next-step-line"],
~font_metrics,
~caret=(Id.invalid, 0),
~rows=measured.rows,
~tiles=[(id, mold, shards)],
x,
)
},
range,
);
},
tiles,
)
Expand Down
63 changes: 56 additions & 7 deletions src/haz3lweb/view/StepperView.re
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ module Update = {
[@deriving (show({with_path: false}), sexp, yojson)]
type t =
// int here should include hidden steps
// Note this int is backwards compared to the selection (0 is the most recent step)
| StepperEditor(int, StepperEditor.Update.t)
| StepForward(int)
| StepBackward;
Expand Down Expand Up @@ -356,14 +357,17 @@ module Selection = {
[@deriving (show({with_path: false}), sexp, yojson)]
type t =
// int here should include hidden steps
// Note this int is backwards compared to the editors (so that 0 is the oldest step, and selections are preserved)
| A(int, StepperEditor.Selection.t);

let get_cursor_info = (~selection: t, mr: Model.t): Cursor.cursor(Update.t) => {
Cursor.(
switch (selection) {
| A(n, editor_selection) =>
let a: option(Model.a) =
mr.history |> Aba.get_as |> List.nth_opt(_, n);
mr.history
|> Aba.get_as
|> List.nth_opt(_, List.length(mr.history |> Aba.get_as) - n - 1);
switch (a) {
| Some(Calculated(a)) =>
let+ x =
Expand All @@ -382,7 +386,10 @@ module Selection = {
let handle_key_event =
(~selection: t, ~event, mr: Model.t): option(Update.t) => {
let A(i, s) = selection;
let a: option(Model.a) = mr.history |> Aba.get_as |> List.nth_opt(_, i);
let a: option(Model.a) =
mr.history
|> Aba.get_as
|> List.nth_opt(_, List.length(mr.history |> Aba.get_as) - i - 1);
switch (a) {
| Some(Calculated(a)) =>
let+ x =
Expand Down Expand Up @@ -464,14 +471,33 @@ module View = {
StepperEditor.View.view(
~globals,
~overlays=[],
~selected=selection == Some(A(i + 1, ())),
~selected=
selection
== Some(
A(
List.length(stepper.history |> Aba.get_as)
- (i + 1)
- 1,
(),
),
),
~inject=
(x: StepperEditor.Update.t) =>
inject(StepperEditor(i + 1, x)),
~signal=
fun
| TakeStep(_) => Ui_effect.Ignore
| MakeActive => signal(MakeActive(A(i + 1, ()))),
| MakeActive =>
signal(
MakeActive(
A(
List.length(stepper.history |> Aba.get_as)
- (i + 1)
- 1,
(),
),
),
),
{
editor: a.editor |> Calc.get_value,
next_steps: [],
Expand Down Expand Up @@ -511,14 +537,37 @@ module View = {
div(~attrs=[Attr.class_("equiv")], [Node.text("≡")]),
StepperEditor.View.view(
~globals,
~selected=selection == Some(A(current_n, ())),
~selected=
selection
== Some(
A(
List.length(stepper.history |> Aba.get_as)
- current_n
- 1,
(),
),
),
~inject=
(x: StepperEditor.Update.t) =>
inject(StepperEditor(current_n, x)),
~signal=
fun
| TakeStep(x) => inject(Update.StepForward(x))
| MakeActive => signal(MakeActive(A(current_n, ()))),
| TakeStep(x) =>
Effect.Many([
inject(Update.StepForward(x)),
Effect.Stop_propagation,
])
| MakeActive =>
signal(
MakeActive(
A(
List.length(stepper.history |> Aba.get_as)
- current_n
- 1,
(),
),
),
),
~overlays=[],
{
editor: model.editor |> Calc.get_value,
Expand Down
8 changes: 8 additions & 0 deletions src/haz3lweb/www/style/dynamics.css
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ svg.tile-next-step {
filter: drop-shadow(1px 1px var(--G2));
}

svg.tile-next-step-top {
pointer-events: all;
cursor: pointer;
visibility: hidden;
z-index: var(--stepper-interactive-z);
filter: drop-shadow(1px 1px var(--G2));
}

svg.tile-taken-step {
filter: drop-shadow(1px 1px var(--BR1));
}
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/www/style/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@

/* ABOVE CODE LEVEL */
--backpack-targets-z: 11;
--stepper-interactive-z: 15;
--caret-z: 20;

/* TOP LEVEL UI */
Expand Down

0 comments on commit 38974de

Please sign in to comment.