Skip to content

Commit

Permalink
hack to make markdown projector fixed size
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Nov 5, 2024
1 parent 3925028 commit 0255afe
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 19 deletions.
File renamed without changes.
6 changes: 4 additions & 2 deletions src/haz3lcore/zipper/ProjectorBase.re
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ module type Projector = {
model,
~info: info,
~local: action => Ui_effect.t(unit),
~parent: external_action => Ui_effect.t(unit)
~parent: external_action => Ui_effect.t(unit),
~font_metrics: FontMetrics.t
) =>
Node.t;
/* How much space should be left in the code view for
Expand Down Expand Up @@ -123,12 +124,13 @@ module Cook = (C: Projector) : Cooked => {
let init = C.init |> serialize_m;
let can_project = C.can_project;
let can_focus = C.can_focus;
let view = (m, ~info, ~local, ~parent) =>
let view = (m, ~info, ~local, ~parent, ~font_metrics) =>
C.view(
deserialize_m(m),
~info,
~local=a => local(serialize_a(a)),
~parent,
~font_metrics,
);
let placeholder = m =>
m |> Sexplib.Sexp.of_string |> C.model_of_sexp |> C.placeholder;
Expand Down
8 changes: 7 additions & 1 deletion src/haz3lcore/zipper/projectors/CheckboxProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ let put = (bool: bool): Piece.t => bool |> string_of_bool |> mk_mono(Exp);
let toggle = (piece: Piece.t) => put(!get(piece));

let view =
(_, ~info, ~local as _, ~parent: external_action => Ui_effect.t(unit)) =>
(
_,
~info,
~local as _,
~parent: external_action => Ui_effect.t(unit),
~font_metrics as _,
) =>
Node.input(
~attrs=
[
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/zipper/projectors/FoldProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module M: Projector = {
let can_focus = false;
let placeholder = (_, _) => Inline(2);
let update = (_, _) => ();
let view = (_, ~info as _, ~local as _, ~parent) =>
let view = (_, ~info as _, ~local as _, ~parent, ~font_metrics as _) =>
div(
~attrs=[Attr.on_double_click(_ => parent(Remove))],
[text("⋱")],
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/zipper/projectors/InfoProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module M: Projector = {
| (ToggleDisplay, Self) => Expected
};

let view = (model, ~info, ~local, ~parent as _) =>
let view = (model, ~info, ~local, ~parent as _, ~font_metrics as _) =>
div(
~attrs=[
Attr.classes(["info", "code"]),
Expand Down
27 changes: 19 additions & 8 deletions src/haz3lcore/zipper/projectors/MarkdownProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,39 @@ let key_handler = (id, ~parent, evt) => {
let safe_html_to_node = (html_string: string): Node.t =>
Node.div(~attrs=[Attr.create("innerHTML", html_string)], []);
let textarea =
(id, ~parent: external_action => Ui_effect.t(unit), text: string) => {
(
id,
~parent as _: external_action => Ui_effect.t(unit),
~font_metrics: FontMetrics.t,
text: string,
) => {
let foo = Omd.of_string(text);
let bar = Omd.to_html(foo);
let size =
Css_gen.concat([
Css_gen.overflow(`Auto),
Css_gen.height(`Px(int_of_float(30. *. font_metrics.row_height))),
Css_gen.width(`Px(int_of_float(150. *. font_metrics.col_width))),
]);
// Node.innerHtml(bar);
let foo =
Node.inner_html(
~attrs=[Attr.id(of_id(id))],
~attrs=[Attr.id(of_id(id)), Attr.style(size)],
~this_html_is_sanitized_and_is_totally_safe_trust_me=bar, // ;)
~tag="div",
);
foo();
};

let view = (_, ~info, ~local as _, ~parent) => {
let view = (_, ~info, ~local as _, ~parent, ~font_metrics) => {
let text = info.syntax |> get |> Form.strip_quotes;
Node.div(
~attrs=[Attr.classes(["wrapper"])],
[
Node.div(
~attrs=[Attr.classes(["cols", "code"])],
[Node.text("·")] @ [textarea(info.id, ~parent, text)],
[Node.text("·")]
@ [textarea(info.id, ~parent, ~font_metrics, text)],
),
],
);
Expand All @@ -94,12 +106,11 @@ module M: Projector = {
let init = ();
let can_project = _ => true; //TODO(andrew): restrict somehow
let can_focus = true;
let placeholder = (_, info) => {
let str = Form.strip_quotes(get(info.syntax));
let placeholder = (_, _info) => {
Block({
row: StringUtil.num_lines(str),
row: 30,
/* +2 for left and right padding */
col: 2 + StringUtil.max_line_width(str),
col: 150,
});
};
let update = (model, _) => model;
Expand Down
8 changes: 7 additions & 1 deletion src/haz3lcore/zipper/projectors/SliderFProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ module M: Projector = {
let placeholder = (_, _) => Inline(10);
let update = (model, _) => model;
let view =
(_, ~info, ~local as _, ~parent: external_action => Ui_effect.t(unit)) =>
(
_,
~info,
~local as _,
~parent: external_action => Ui_effect.t(unit),
~font_metrics as _,
) =>
Util.Web.range(
~attrs=[Attr.on_input((_, v) => parent(SetSyntax(put(v))))],
get(info.syntax) |> Printf.sprintf("%.2f"),
Expand Down
8 changes: 7 additions & 1 deletion src/haz3lcore/zipper/projectors/SliderProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ module M: Projector = {
let placeholder = (_, _) => Inline(10);
let update = (model, _) => model;
let view =
(_, ~info, ~local as _, ~parent: external_action => Ui_effect.t(unit)) =>
(
_,
~info,
~local as _,
~parent: external_action => Ui_effect.t(unit),
~font_metrics as _,
) =>
Util.Web.range(
~attrs=[Attr.on_input((_, v) => parent(SetSyntax(put(v))))],
get(info.syntax),
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lcore/zipper/projectors/TextAreaProj.re
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ let textarea =
[],
);

let view = (_, ~info, ~local as _, ~parent) => {
let view = (_, ~info, ~local as _, ~parent, ~font_metrics as _) => {
let text = info.syntax |> get |> Form.strip_quotes;
Node.div(
~attrs=[Attr.classes(["wrapper"])],
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lweb/view/ProjectorView.re
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ let setup_view =
~info,
~selected=List.mem(id, meta.syntax.selection_ids),
p,
P.view(p.model, ~info, ~local, ~parent),
P.view(p.model, ~font_metrics, ~info, ~local, ~parent),
);
};

Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/view/dec/CaretDec.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Util;
open Haz3lcore;

module Profile = {
type t = {
Expand Down
1 change: 1 addition & 0 deletions src/haz3lweb/view/dec/CaretPosDec.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Virtual_dom.Vdom;
open Haz3lcore;

module Profile = {
type style = [ | `Sibling];
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lweb/view/dec/DecUtil.re
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Virtual_dom.Vdom;
open Node;
open Util;

open Haz3lcore;
let caret_width = 0.2;

let tip_width = 0.32;
Expand Down
2 changes: 1 addition & 1 deletion src/haz3lweb/view/dhcode/Decoration_common.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Virtual_dom.Vdom;

open Haz3lcore;
module MeasuredPosition = Pretty.MeasuredPosition;
module MeasuredLayout = Pretty.MeasuredLayout;

Expand Down

0 comments on commit 0255afe

Please sign in to comment.