From e156fbef030264a28edbe418fce05f61e76f8e3f Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Wed, 7 Jul 2021 18:08:34 +0200 Subject: [PATCH] minor cleanup --- compiler/mono/src/alias_analysis.rs | 4 +-- editor/src/editor/markup/nodes.rs | 2 +- editor/src/editor/mvc/ed_model.rs | 2 +- editor/src/editor/mvc/ed_update.rs | 40 ++++++++++++---------------- editor/src/editor/mvc/list_update.rs | 5 ++-- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/compiler/mono/src/alias_analysis.rs b/compiler/mono/src/alias_analysis.rs index ebd467954d..2b4354d26e 100644 --- a/compiler/mono/src/alias_analysis.rs +++ b/compiler/mono/src/alias_analysis.rs @@ -166,9 +166,9 @@ where p.build()? }; - /*if DEBUG { + if DEBUG { eprintln!("{}", program.to_source_string()); - }*/ + } morphic_lib::solve(program) } diff --git a/editor/src/editor/markup/nodes.rs b/editor/src/editor/markup/nodes.rs index ff31d26673..dd30826d2e 100644 --- a/editor/src/editor/markup/nodes.rs +++ b/editor/src/editor/markup/nodes.rs @@ -75,7 +75,7 @@ impl MarkupNode { } } - // return (index of child in list of children, index of child in list of children of ast node) + // return (index of child in list of children, closest ast index of child corresponding to ast node) pub fn get_child_indices( &self, child_id: MarkNodeId, diff --git a/editor/src/editor/mvc/ed_model.rs b/editor/src/editor/mvc/ed_model.rs index 3a9bc4faa4..b57a36df8a 100644 --- a/editor/src/editor/mvc/ed_model.rs +++ b/editor/src/editor/mvc/ed_model.rs @@ -135,7 +135,7 @@ impl<'a> EdModel<'a> { self.grid_node_map.node_exists_at_pos(self.get_caret()) } - // return (index of child in list of children, index of child in list of children of ast node) of MarkupNode at current caret position + // return (index of child in list of children, closest ast index of child corresponding to ast node) of MarkupNode at current caret position pub fn get_curr_child_indices(&self) -> EdResult<(usize, usize)> { if self.node_exists_at_caret() { let curr_mark_node_id = self.get_curr_mark_node_id()?; diff --git a/editor/src/editor/mvc/ed_update.rs b/editor/src/editor/mvc/ed_update.rs index e16fd306e7..1802854f76 100644 --- a/editor/src/editor/mvc/ed_update.rs +++ b/editor/src/editor/mvc/ed_update.rs @@ -696,16 +696,13 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult Expr2::List{ elem_var: _, elems: _} => { let prev_mark_node = ed_model.markup_node_pool.get(prev_mark_node_id); - if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR { - if curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR { - // based on if, we are at the start of the list - let new_child_index = 1; - let new_ast_child_index = 0; - add_blank_child(new_child_index, new_ast_child_index, ed_model)?; // insert a Blank first, this results in cleaner code - handle_new_char(received_char, ed_model)? - } else { - InputOutcome::Ignored - } + if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR && curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR { + // based on if, we are at the start of the list + let new_child_index = 1; + let new_ast_child_index = 0; + // insert a Blank first, this results in cleaner code + add_blank_child(new_child_index, new_ast_child_index, ed_model)?; + handle_new_char(received_char, ed_model)? } else { InputOutcome::Ignored } @@ -773,22 +770,19 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult } else if "\"{[".contains(*ch) { let prev_mark_node = ed_model.markup_node_pool.get(prev_mark_node_id); - if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR { - if curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR { - let (new_child_index, new_ast_child_index) = ed_model.get_curr_child_indices()?; - // insert a Blank first, this results in cleaner code - add_blank_child( - new_child_index, - new_ast_child_index, - ed_model - )?; - handle_new_char(received_char, ed_model)? - } else { - InputOutcome::Ignored - } + if prev_mark_node.get_content()? == nodes::LEFT_SQUARE_BR && curr_mark_node.get_content()? == nodes::RIGHT_SQUARE_BR { + let (new_child_index, new_ast_child_index) = ed_model.get_curr_child_indices()?; + // insert a Blank first, this results in cleaner code + add_blank_child( + new_child_index, + new_ast_child_index, + ed_model + )?; + handle_new_char(received_char, ed_model)? } else { InputOutcome::Ignored } + } else { InputOutcome::Ignored } diff --git a/editor/src/editor/mvc/list_update.rs b/editor/src/editor/mvc/list_update.rs index efc3eca5a3..24cc7fab32 100644 --- a/editor/src/editor/mvc/list_update.rs +++ b/editor/src/editor/mvc/list_update.rs @@ -164,7 +164,7 @@ pub fn add_blank_child( .fail(), }?; - let new_mark_children = make_mark_children( + let new_mark_children = update_mark_children( new_child_index, blank_elt_id, list_ast_node_id, @@ -182,7 +182,8 @@ pub fn add_blank_child( Ok(InputOutcome::Accepted) } -pub fn make_mark_children( +// add a Blank child to the Nested mark node and update the caret +pub fn update_mark_children( new_child_index: usize, blank_elt_id: ExprId, list_ast_node_id: ExprId,