-
Notifications
You must be signed in to change notification settings - Fork 52
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
Markdown Projectors #1417
Draft
7h3kk1d
wants to merge
4
commits into
dev
Choose a base branch
from
markdown_projector
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Markdown Projectors #1417
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
open Util; | ||
open Virtual_dom.Vdom; | ||
open ProjectorBase; | ||
|
||
let of_id = (id: Id.t) => | ||
"id" ++ (id |> Id.to_string |> String.sub(_, 0, 8)); | ||
|
||
let of_mono = (syntax: Piece.t): option(string) => | ||
switch (syntax) { | ||
| Tile({label: [l], _}) => Some(StringUtil.unescape_linebreaks(l)) | ||
| _ => None | ||
}; | ||
|
||
let mk_mono = (sort: Sort.t, string: string): Piece.t => | ||
string | ||
|> StringUtil.escape_linebreaks | ||
|> Form.mk_atomic(sort) | ||
|> Piece.mk_tile(_, []); | ||
|
||
let get = (piece: Piece.t): string => | ||
switch (piece |> of_mono) { | ||
| None => failwith("TextArea: not string literal") | ||
| Some(s) => s | ||
}; | ||
|
||
let put = (s: string): Piece.t => s |> mk_mono(Exp); | ||
|
||
let put = (str: string): external_action => | ||
SetSyntax(str |> Form.string_quote |> put); | ||
|
||
let is_last_pos = id => | ||
Web.TextArea.caret_at_end(Web.TextArea.get(of_id(id))); | ||
let is_first_pos = id => | ||
Web.TextArea.caret_at_start(Web.TextArea.get(of_id(id))); | ||
|
||
let key_handler = (id, ~parent, evt) => { | ||
open Effect; | ||
let key = Key.mk(KeyDown, evt); | ||
|
||
switch (key.key) { | ||
| D("ArrowRight" | "ArrowDown") when is_last_pos(id) => | ||
JsUtil.get_elem_by_id(of_id(id))##blur; | ||
Many([parent(Escape(Right)), Stop_propagation]); | ||
| D("ArrowLeft" | "ArrowUp") when is_first_pos(id) => | ||
JsUtil.get_elem_by_id(of_id(id))##blur; | ||
Many([parent(Escape(Left)), Stop_propagation]); | ||
/* Defer to parent editor undo for now */ | ||
| D("z" | "Z" | "y" | "Y") when Key.ctrl_held(evt) || Key.meta_held(evt) => | ||
Many([Prevent_default]) | ||
| D("z" | "Z") | ||
when Key.shift_held(evt) && (Key.ctrl_held(evt) || Key.meta_held(evt)) => | ||
Many([Prevent_default]) | ||
| D("\"") => | ||
/* Hide quotes from both the textarea and parent editor */ | ||
Many([Prevent_default, Stop_propagation]) | ||
| _ => Stop_propagation | ||
}; | ||
}; | ||
|
||
let safe_html_to_node = (html_string: string): Node.t => | ||
Node.div(~attrs=[Attr.create("innerHTML", html_string)], []); | ||
let textarea = | ||
( | ||
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)), Attr.style(size)], | ||
~this_html_is_sanitized_and_is_totally_safe_trust_me=bar, // ;) | ||
~tag="div", | ||
); | ||
foo(); | ||
}; | ||
|
||
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, ~font_metrics, text)], | ||
), | ||
], | ||
); | ||
}; | ||
|
||
module M: Projector = { | ||
[@deriving (show({with_path: false}), sexp, yojson)] | ||
type model = unit; | ||
[@deriving (show({with_path: false}), sexp, yojson)] | ||
type action = unit; | ||
let init = (); | ||
let can_project = _ => true; //TODO(andrew): restrict somehow | ||
let can_focus = true; | ||
let placeholder = (_, _info) => { | ||
Block({ | ||
row: 30, | ||
/* +2 for left and right padding */ | ||
col: 150, | ||
}); | ||
}; | ||
let update = (model, _) => model; | ||
let view = view; | ||
let focus = ((id: Id.t, d: option(Direction.t))) => { | ||
JsUtil.get_elem_by_id(of_id(id))##focus; | ||
switch (d) { | ||
| None => () | ||
| Some(Left) => | ||
Web.TextArea.set_caret_to_start(Web.TextArea.get(of_id(id))) | ||
| Some(Right) => | ||
Web.TextArea.set_caret_to_end(Web.TextArea.get(of_id(id))) | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
open Util; | ||
open Haz3lcore; | ||
|
||
module Profile = { | ||
type t = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
trust me bro