mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
improved handle_new_char structure, test updates
This commit is contained in:
parent
f851215917
commit
a2d802dd04
3 changed files with 545 additions and 498 deletions
|
@ -8,6 +8,7 @@ use crate::editor::grid_node_map::GridNodeMap;
|
||||||
use crate::editor::markup::attribute::Attributes;
|
use crate::editor::markup::attribute::Attributes;
|
||||||
use crate::editor::markup::common_nodes::new_blank_mn;
|
use crate::editor::markup::common_nodes::new_blank_mn;
|
||||||
use crate::editor::markup::nodes;
|
use crate::editor::markup::nodes;
|
||||||
|
use crate::editor::markup::nodes::LEFT_ACCOLADE;
|
||||||
use crate::editor::markup::nodes::MarkupNode;
|
use crate::editor::markup::nodes::MarkupNode;
|
||||||
use crate::editor::markup::nodes::EQUALS;
|
use crate::editor::markup::nodes::EQUALS;
|
||||||
use crate::editor::mvc::app_update::InputOutcome;
|
use crate::editor::mvc::app_update::InputOutcome;
|
||||||
|
@ -29,6 +30,7 @@ use crate::editor::slow_pool::MarkNodeId;
|
||||||
use crate::editor::slow_pool::SlowPool;
|
use crate::editor::slow_pool::SlowPool;
|
||||||
use crate::editor::syntax_highlight::HighlightStyle;
|
use crate::editor::syntax_highlight::HighlightStyle;
|
||||||
use crate::lang::ast::Def2;
|
use crate::lang::ast::Def2;
|
||||||
|
use crate::lang::ast::DefId;
|
||||||
use crate::lang::ast::{Expr2, ExprId};
|
use crate::lang::ast::{Expr2, ExprId};
|
||||||
use crate::lang::constrain::constrain_expr;
|
use crate::lang::constrain::constrain_expr;
|
||||||
use crate::lang::parse::ASTNodeId;
|
use crate::lang::parse::ASTNodeId;
|
||||||
|
@ -664,6 +666,319 @@ pub fn get_node_context<'a>(ed_model: &'a EdModel) -> EdResult<NodeContext<'a>>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// current(=caret is here) MarkupNode correspondes to a Def2 in the AST
|
||||||
|
pub fn handle_new_char_def(received_char: &char, def_id: DefId, ed_model: &mut EdModel) -> EdResult<InputOutcome> {
|
||||||
|
let def_ref = ed_model.module.env.pool.get(def_id);
|
||||||
|
let ch = received_char;
|
||||||
|
|
||||||
|
let NodeContext {
|
||||||
|
old_caret_pos,
|
||||||
|
curr_mark_node_id,
|
||||||
|
curr_mark_node,
|
||||||
|
parent_id_opt: _,
|
||||||
|
ast_node_id,
|
||||||
|
} = get_node_context(ed_model)?;
|
||||||
|
|
||||||
|
let outcome =match def_ref {
|
||||||
|
Def2::Blank {..} => {
|
||||||
|
match ch {
|
||||||
|
'a'..='z' => {
|
||||||
|
start_new_tld_value(ed_model, ch)?
|
||||||
|
},
|
||||||
|
_ => InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Def2::ValueDef { .. } => {
|
||||||
|
let val_name_mn_id = if curr_mark_node.get_content() == EQUALS {
|
||||||
|
|
||||||
|
let prev_mark_node_id_opt = ed_model.get_prev_mark_node_id()?;
|
||||||
|
|
||||||
|
if let Some(prev_mark_node_id) = prev_mark_node_id_opt {
|
||||||
|
prev_mark_node_id
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
curr_mark_node_id
|
||||||
|
};
|
||||||
|
|
||||||
|
update_tld_val_name(
|
||||||
|
val_name_mn_id,
|
||||||
|
ed_model.get_caret(), // TODO update for multiple carets
|
||||||
|
ed_model,
|
||||||
|
ch
|
||||||
|
)?
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(outcome)
|
||||||
|
}
|
||||||
|
|
||||||
|
// current(=caret is here) MarkupNode correspondes to an Expr2 in the AST
|
||||||
|
pub fn handle_new_char_expr(received_char: &char, expr_id: ExprId, ed_model: &mut EdModel) -> EdResult<InputOutcome> {
|
||||||
|
let expr_ref = ed_model.module.env.pool.get(expr_id);
|
||||||
|
let ch = received_char;
|
||||||
|
|
||||||
|
let NodeContext {
|
||||||
|
old_caret_pos,
|
||||||
|
curr_mark_node_id,
|
||||||
|
curr_mark_node,
|
||||||
|
parent_id_opt: _,
|
||||||
|
ast_node_id,
|
||||||
|
} = get_node_context(ed_model)?;
|
||||||
|
|
||||||
|
let prev_mark_node_id_opt = ed_model.get_prev_mark_node_id()?;
|
||||||
|
|
||||||
|
let expr_ref = ed_model.module.env.pool.get(expr_id);
|
||||||
|
|
||||||
|
let outcome =
|
||||||
|
if let Expr2::Blank {..} = expr_ref {
|
||||||
|
match ch {
|
||||||
|
'a'..='z' => {
|
||||||
|
start_new_let_value(ed_model, ch)?
|
||||||
|
}
|
||||||
|
'"' => {
|
||||||
|
start_new_string(ed_model)?
|
||||||
|
},
|
||||||
|
'{' => {
|
||||||
|
start_new_record(ed_model)?
|
||||||
|
}
|
||||||
|
'0'..='9' => {
|
||||||
|
start_new_int(ed_model, ch)?
|
||||||
|
}
|
||||||
|
'[' => {
|
||||||
|
// this can also be a tag union or become a set, assuming list for now
|
||||||
|
start_new_list(ed_model)?
|
||||||
|
}
|
||||||
|
'\r' => {
|
||||||
|
// For convenience and consitency there is only one way to format Roc, you can't add extra blank lines.
|
||||||
|
InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
_ => InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
} else if let Some(prev_mark_node_id) = prev_mark_node_id_opt{
|
||||||
|
if prev_mark_node_id == curr_mark_node_id {
|
||||||
|
match expr_ref {
|
||||||
|
Expr2::SmallInt{ .. } => {
|
||||||
|
update_int(ed_model, curr_mark_node_id, ch)?
|
||||||
|
}
|
||||||
|
Expr2::SmallStr(old_arr_str) => {
|
||||||
|
update_small_string(
|
||||||
|
ch, old_arr_str, ed_model
|
||||||
|
)?
|
||||||
|
}
|
||||||
|
Expr2::Str(..) => {
|
||||||
|
update_string(*ch, ed_model)?
|
||||||
|
}
|
||||||
|
Expr2::InvalidLookup(old_pool_str) => {
|
||||||
|
update_invalid_lookup(
|
||||||
|
&ch.to_string(),
|
||||||
|
old_pool_str,
|
||||||
|
curr_mark_node_id,
|
||||||
|
expr_id,
|
||||||
|
ed_model
|
||||||
|
)?
|
||||||
|
}
|
||||||
|
Expr2::EmptyRecord => {
|
||||||
|
// prev_mark_node_id and curr_mark_node_id should be different to allow creating field at current caret position
|
||||||
|
InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
Expr2::Record{ record_var:_, fields } => {
|
||||||
|
if curr_mark_node.get_content().chars().all(|chr| chr.is_ascii_alphanumeric()){
|
||||||
|
update_record_field(
|
||||||
|
&ch.to_string(),
|
||||||
|
ed_model.get_caret(),
|
||||||
|
curr_mark_node_id,
|
||||||
|
fields,
|
||||||
|
ed_model,
|
||||||
|
)?
|
||||||
|
} else {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
} else if ch.is_ascii_alphanumeric() { // prev_mark_node_id != curr_mark_node_id
|
||||||
|
|
||||||
|
match expr_ref {
|
||||||
|
Expr2::SmallInt{ .. } => {
|
||||||
|
update_int(ed_model, curr_mark_node_id, ch)?
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
let prev_ast_node_id =
|
||||||
|
ed_model
|
||||||
|
.mark_node_pool
|
||||||
|
.get(prev_mark_node_id)
|
||||||
|
.get_ast_node_id();
|
||||||
|
|
||||||
|
match prev_ast_node_id {
|
||||||
|
ASTNodeId::ADefId(_) => {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
},
|
||||||
|
ASTNodeId::AExprId(prev_expr_id) => {
|
||||||
|
handle_new_char_diff_mark_nodes_prev_is_expr(ch, prev_expr_id, expr_id, prev_mark_node_id, curr_mark_node_id, ed_model)?
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if *ch == ':' {
|
||||||
|
let mark_parent_id_opt = curr_mark_node.get_parent_id_opt();
|
||||||
|
|
||||||
|
if let Some(mark_parent_id) = mark_parent_id_opt {
|
||||||
|
let parent_ast_id = ed_model.mark_node_pool.get(mark_parent_id).get_ast_node_id();
|
||||||
|
|
||||||
|
match parent_ast_id {
|
||||||
|
ASTNodeId::ADefId(_) => InputOutcome::Ignored,
|
||||||
|
ASTNodeId::AExprId(parent_expr_id) => update_record_colon(ed_model, parent_expr_id)?
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
} else if *ch == ',' {
|
||||||
|
if curr_mark_node.get_content() == nodes::LEFT_SQUARE_BR {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
} else {
|
||||||
|
let mark_parent_id_opt = curr_mark_node.get_parent_id_opt();
|
||||||
|
|
||||||
|
if let Some(mark_parent_id) = mark_parent_id_opt {
|
||||||
|
let parent_ast_id = ed_model.mark_node_pool.get(mark_parent_id).get_ast_node_id();
|
||||||
|
|
||||||
|
match parent_ast_id {
|
||||||
|
ASTNodeId::ADefId(_) => {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
},
|
||||||
|
ASTNodeId::AExprId(parent_expr_id) => {
|
||||||
|
let parent_expr2 = ed_model.module.env.pool.get(parent_expr_id);
|
||||||
|
|
||||||
|
match parent_expr2 {
|
||||||
|
Expr2::List { elem_var:_, elems:_} => {
|
||||||
|
|
||||||
|
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
|
||||||
|
)?
|
||||||
|
}
|
||||||
|
Expr2::Record { record_var:_, fields:_ } => {
|
||||||
|
todo!("multiple record fields")
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if "\"{[".contains(*ch) {
|
||||||
|
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(outcome)
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle new char when prev_mark_node != curr_mark_node and prev_mark_node's AST node is an Expr2
|
||||||
|
pub fn handle_new_char_diff_mark_nodes_prev_is_expr(received_char: &char, prev_expr_id: ExprId, curr_expr_id: ExprId, prev_mark_node_id: MarkNodeId, curr_mark_node_id: MarkNodeId, ed_model: &mut EdModel) -> EdResult<InputOutcome> {
|
||||||
|
|
||||||
|
let prev_expr_ref = ed_model.module.env.pool.get(prev_expr_id);
|
||||||
|
let curr_expr_ref = ed_model.module.env.pool.get(curr_expr_id);
|
||||||
|
let ch = received_char;
|
||||||
|
let curr_mark_node = ed_model.mark_node_pool.get(curr_mark_node_id);
|
||||||
|
|
||||||
|
let outcome = match prev_expr_ref {
|
||||||
|
Expr2::SmallInt{ .. } => {
|
||||||
|
update_int(ed_model, prev_mark_node_id, ch)?
|
||||||
|
}
|
||||||
|
Expr2::InvalidLookup(old_pool_str) => {
|
||||||
|
update_invalid_lookup(
|
||||||
|
&ch.to_string(),
|
||||||
|
old_pool_str,
|
||||||
|
prev_mark_node_id,
|
||||||
|
prev_expr_id,
|
||||||
|
ed_model
|
||||||
|
)?
|
||||||
|
}
|
||||||
|
Expr2::Record{ record_var:_, fields } => {
|
||||||
|
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
||||||
|
|
||||||
|
if (curr_mark_node.get_content() == nodes::RIGHT_ACCOLADE || curr_mark_node.get_content() == nodes::COLON) &&
|
||||||
|
prev_mark_node.is_all_alphanumeric() {
|
||||||
|
update_record_field(
|
||||||
|
&ch.to_string(),
|
||||||
|
ed_model.get_caret(),
|
||||||
|
prev_mark_node_id,
|
||||||
|
fields,
|
||||||
|
ed_model,
|
||||||
|
)?
|
||||||
|
} else if prev_mark_node.get_content() == nodes::LEFT_ACCOLADE && curr_mark_node.is_all_alphanumeric() {
|
||||||
|
update_record_field(
|
||||||
|
&ch.to_string(),
|
||||||
|
ed_model.get_caret(),
|
||||||
|
curr_mark_node_id,
|
||||||
|
fields,
|
||||||
|
ed_model,
|
||||||
|
)?
|
||||||
|
} else {
|
||||||
|
InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Expr2::List{ elem_var: _, elems: _} => {
|
||||||
|
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
match curr_expr_ref {
|
||||||
|
Expr2::EmptyRecord => {
|
||||||
|
let sibling_ids = curr_mark_node.get_sibling_ids(&ed_model.mark_node_pool);
|
||||||
|
|
||||||
|
update_empty_record(
|
||||||
|
&ch.to_string(),
|
||||||
|
prev_mark_node_id,
|
||||||
|
sibling_ids,
|
||||||
|
ed_model
|
||||||
|
)?
|
||||||
|
}
|
||||||
|
_ => InputOutcome::Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(outcome)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult<InputOutcome> {
|
pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult<InputOutcome> {
|
||||||
let input_outcome = match received_char {
|
let input_outcome = match received_char {
|
||||||
'\u{1}' // Ctrl + A
|
'\u{1}' // Ctrl + A
|
||||||
|
@ -696,286 +1011,10 @@ pub fn handle_new_char(received_char: &char, ed_model: &mut EdModel) -> EdResult
|
||||||
|
|
||||||
match ast_node_id {
|
match ast_node_id {
|
||||||
ASTNodeId::ADefId(def_id) => {
|
ASTNodeId::ADefId(def_id) => {
|
||||||
let def_ref = ed_model.module.env.pool.get(def_id);
|
handle_new_char_def(received_char, def_id, ed_model)?
|
||||||
|
|
||||||
match def_ref {
|
|
||||||
Def2::Blank {..} => {
|
|
||||||
match ch {
|
|
||||||
'a'..='z' => {
|
|
||||||
start_new_tld_value(ed_model, ch)?
|
|
||||||
},
|
|
||||||
_ => InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Def2::ValueDef { .. } => {
|
|
||||||
let val_name_mn_id = if curr_mark_node.get_content() == EQUALS {
|
|
||||||
if let Some(prev_mark_node_id) = prev_mark_node_id_opt {
|
|
||||||
prev_mark_node_id
|
|
||||||
} else {
|
|
||||||
unreachable!()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
curr_mark_node_id
|
|
||||||
};
|
|
||||||
|
|
||||||
update_tld_val_name(
|
|
||||||
val_name_mn_id,
|
|
||||||
ed_model.get_caret(), // TODO update for multiple carets
|
|
||||||
ed_model,
|
|
||||||
ch
|
|
||||||
)?
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
ASTNodeId::AExprId(expr_id) => {
|
ASTNodeId::AExprId(expr_id) => {
|
||||||
let expr_ref = ed_model.module.env.pool.get(expr_id);
|
handle_new_char_expr(received_char, expr_id, ed_model)?
|
||||||
|
|
||||||
if let Expr2::Blank {..} = expr_ref {
|
|
||||||
match ch {
|
|
||||||
'a'..='z' => {
|
|
||||||
start_new_let_value(ed_model, ch)?
|
|
||||||
}
|
|
||||||
'"' => {
|
|
||||||
start_new_string(ed_model)?
|
|
||||||
},
|
|
||||||
'{' => {
|
|
||||||
start_new_record(ed_model)?
|
|
||||||
}
|
|
||||||
'0'..='9' => {
|
|
||||||
start_new_int(ed_model, ch)?
|
|
||||||
}
|
|
||||||
'[' => {
|
|
||||||
// this can also be a tag union or become a set, assuming list for now
|
|
||||||
start_new_list(ed_model)?
|
|
||||||
}
|
|
||||||
'\r' => {
|
|
||||||
// For consistency and convenience there is only one way to format Roc, you can't add extra blank lines.
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
_ => InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
} else if let Some(prev_mark_node_id) = prev_mark_node_id_opt{
|
|
||||||
if prev_mark_node_id == curr_mark_node_id {
|
|
||||||
match expr_ref {
|
|
||||||
Expr2::SmallInt{ .. } => {
|
|
||||||
update_int(ed_model, curr_mark_node_id, ch)?
|
|
||||||
}
|
|
||||||
Expr2::SmallStr(old_arr_str) => {
|
|
||||||
update_small_string(
|
|
||||||
ch, old_arr_str, ed_model
|
|
||||||
)?
|
|
||||||
}
|
|
||||||
Expr2::Str(..) => {
|
|
||||||
update_string(*ch, ed_model)?
|
|
||||||
}
|
|
||||||
Expr2::InvalidLookup(old_pool_str) => {
|
|
||||||
update_invalid_lookup(
|
|
||||||
&ch.to_string(),
|
|
||||||
old_pool_str,
|
|
||||||
curr_mark_node_id,
|
|
||||||
expr_id,
|
|
||||||
ed_model
|
|
||||||
)?
|
|
||||||
}
|
|
||||||
Expr2::EmptyRecord => {
|
|
||||||
// prev_mark_node_id and curr_mark_node_id should be different to allow creating field at current caret position
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
Expr2::Record{ record_var:_, fields } => {
|
|
||||||
if curr_mark_node.get_content().chars().all(|chr| chr.is_ascii_alphanumeric()){
|
|
||||||
update_record_field(
|
|
||||||
&ch.to_string(),
|
|
||||||
ed_model.get_caret(),
|
|
||||||
curr_mark_node_id,
|
|
||||||
fields,
|
|
||||||
ed_model,
|
|
||||||
)?
|
|
||||||
} else {
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
} else { // prev_mark_node_id != curr_mark_node_id
|
|
||||||
match expr_ref {
|
|
||||||
Expr2::SmallStr(_) | Expr2::Str(_) | Expr2::EmptyRecord | Expr2::Record{ .. } => {
|
|
||||||
// prev_mark_node and curr_mark_node are different.
|
|
||||||
// Caret is located before first quote or `{`, no input is allowed here
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
if ch.is_ascii_alphanumeric() {
|
|
||||||
match expr_ref {
|
|
||||||
Expr2::SmallInt{ .. } => {
|
|
||||||
update_int(ed_model, curr_mark_node_id, ch)?
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_ => {
|
|
||||||
let prev_ast_node_id =
|
|
||||||
ed_model
|
|
||||||
.mark_node_pool
|
|
||||||
.get(prev_mark_node_id)
|
|
||||||
.get_ast_node_id();
|
|
||||||
|
|
||||||
match prev_ast_node_id {
|
|
||||||
ASTNodeId::ADefId(_) => {
|
|
||||||
//let prev_node_def = ed_model.module.env.pool.get(prev_def_id);
|
|
||||||
unimplemented!("TODO")
|
|
||||||
},
|
|
||||||
ASTNodeId::AExprId(prev_expr_id) => {
|
|
||||||
let prev_node_expr = ed_model.module.env.pool.get(prev_expr_id);
|
|
||||||
|
|
||||||
match prev_node_expr {
|
|
||||||
Expr2::SmallInt{ .. } => {
|
|
||||||
update_int(ed_model, prev_mark_node_id, ch)?
|
|
||||||
}
|
|
||||||
Expr2::InvalidLookup(old_pool_str) => {
|
|
||||||
update_invalid_lookup(
|
|
||||||
&ch.to_string(),
|
|
||||||
old_pool_str,
|
|
||||||
prev_mark_node_id,
|
|
||||||
prev_expr_id,
|
|
||||||
ed_model
|
|
||||||
)?
|
|
||||||
}
|
|
||||||
Expr2::Record{ record_var:_, fields } => {
|
|
||||||
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
|
||||||
|
|
||||||
if (curr_mark_node.get_content() == nodes::RIGHT_ACCOLADE || curr_mark_node.get_content() == nodes::COLON) &&
|
|
||||||
prev_mark_node.is_all_alphanumeric() {
|
|
||||||
update_record_field(
|
|
||||||
&ch.to_string(),
|
|
||||||
ed_model.get_caret(),
|
|
||||||
prev_mark_node_id,
|
|
||||||
fields,
|
|
||||||
ed_model,
|
|
||||||
)?
|
|
||||||
} else if prev_mark_node.get_content() == nodes::LEFT_ACCOLADE && curr_mark_node.is_all_alphanumeric() {
|
|
||||||
update_record_field(
|
|
||||||
&ch.to_string(),
|
|
||||||
ed_model.get_caret(),
|
|
||||||
curr_mark_node_id,
|
|
||||||
fields,
|
|
||||||
ed_model,
|
|
||||||
)?
|
|
||||||
} else {
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Expr2::List{ elem_var: _, elems: _} => {
|
|
||||||
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Expr2::LetValue{ def_id, body_id, body_var:_ } => {
|
|
||||||
update_let_value(prev_mark_node_id, *def_id, *body_id, ed_model, ch)?
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
match prev_node_expr {
|
|
||||||
Expr2::EmptyRecord => {
|
|
||||||
let sibling_ids = curr_mark_node.get_sibling_ids(&ed_model.mark_node_pool);
|
|
||||||
|
|
||||||
update_empty_record(
|
|
||||||
&ch.to_string(),
|
|
||||||
prev_mark_node_id,
|
|
||||||
sibling_ids,
|
|
||||||
ed_model
|
|
||||||
)?
|
|
||||||
}
|
|
||||||
_ => InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if *ch == ':' {
|
|
||||||
let mark_parent_id_opt = curr_mark_node.get_parent_id_opt();
|
|
||||||
|
|
||||||
if let Some(mark_parent_id) = mark_parent_id_opt {
|
|
||||||
let parent_ast_id = ed_model.mark_node_pool.get(mark_parent_id).get_ast_node_id();
|
|
||||||
|
|
||||||
update_record_colon(ed_model, parent_ast_id.to_expr_id()?)?
|
|
||||||
} else {
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
} else if *ch == ',' {
|
|
||||||
if curr_mark_node.get_content() == nodes::LEFT_SQUARE_BR {
|
|
||||||
InputOutcome::Ignored
|
|
||||||
} else {
|
|
||||||
let mark_parent_id_opt = curr_mark_node.get_parent_id_opt();
|
|
||||||
|
|
||||||
if let Some(mark_parent_id) = mark_parent_id_opt {
|
|
||||||
let parent_ast_id = ed_model.mark_node_pool.get(mark_parent_id).get_ast_node_id();
|
|
||||||
|
|
||||||
match parent_ast_id {
|
|
||||||
ASTNodeId::ADefId(_) => {
|
|
||||||
unimplemented!("TODO")
|
|
||||||
},
|
|
||||||
ASTNodeId::AExprId(parent_expr_id) => {
|
|
||||||
let parent_expr2 = ed_model.module.env.pool.get(parent_expr_id);
|
|
||||||
|
|
||||||
match parent_expr2 {
|
|
||||||
Expr2::List { elem_var:_, elems:_} => {
|
|
||||||
|
|
||||||
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
|
|
||||||
)?
|
|
||||||
}
|
|
||||||
Expr2::Record { record_var:_, fields:_ } => {
|
|
||||||
todo!("multiple record fields")
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if "\"{[".contains(*ch) {
|
|
||||||
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
InputOutcome::Ignored
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,6 +1272,7 @@ pub mod test_ed_update {
|
||||||
} else if input_char == '🡰' {
|
} else if input_char == '🡰' {
|
||||||
ed_model.simple_move_carets_left(1);
|
ed_model.simple_move_carets_left(1);
|
||||||
} else {
|
} else {
|
||||||
|
//dbg!(input_char);
|
||||||
ed_res_to_res(handle_new_char(&input_char, &mut ed_model))?;
|
ed_res_to_res(handle_new_char(&input_char, &mut ed_model))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1352,30 +1392,36 @@ pub mod test_ed_update {
|
||||||
.join("")
|
.join("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const IGNORE_CHARS: &str = "{}()[]-><-_\"azAZ:@09";
|
||||||
|
const IGNORE_CHARS_NO_NUM: &str = ",{}()[]-><-_\"azAZ:@";
|
||||||
|
const IGNORE_NO_LTR: &str = "{\"5";
|
||||||
|
const IGNORE_NO_NUM: &str = "a{\"";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ignore_int() -> Result<(), String> {
|
fn test_ignore_int() -> Result<(), String> {
|
||||||
assert_insert_seq_ignore(ovec!["vec = ┃0"], "{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = ┃0"], IGNORE_CHARS_NO_NUM)?;
|
||||||
assert_insert_seq_ignore(ovec!["vec = ┃7"], "{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = ┃7"], IGNORE_CHARS_NO_NUM)?;
|
||||||
|
|
||||||
assert_insert_seq_ignore(ovec!["vec = 0┃"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 0┃"], IGNORE_CHARS_NO_NUM)?;
|
||||||
assert_insert_seq_ignore(ovec!["vec = 8┃"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 8┃"], IGNORE_CHARS_NO_NUM)?;
|
||||||
assert_insert_seq_ignore(ovec!["vec = 20┃"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 20┃"], IGNORE_CHARS_NO_NUM)?;
|
||||||
assert_insert_seq_ignore(ovec!["vec = 83┃"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 83┃"], IGNORE_CHARS_NO_NUM)?;
|
||||||
|
|
||||||
assert_insert_seq_ignore(ovec!["vec = 1┃0"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 1┃0"], IGNORE_CHARS_NO_NUM)?;
|
||||||
assert_insert_seq_ignore(ovec!["vec = 8┃4"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 8┃4"], IGNORE_CHARS_NO_NUM)?;
|
||||||
|
|
||||||
assert_insert_seq_ignore(ovec!["vec = ┃10"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = ┃10"], IGNORE_CHARS_NO_NUM)?;
|
||||||
assert_insert_seq_ignore(ovec!["vec = ┃84"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = ┃84"], IGNORE_CHARS_NO_NUM)?;
|
||||||
|
|
||||||
assert_insert_seq_ignore(ovec!["vec = 129┃96"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 129┃96"], IGNORE_CHARS_NO_NUM)?;
|
||||||
assert_insert_seq_ignore(ovec!["vec = 97┃684"], ",{}()[]-><-_\"azAZ:@")?;
|
assert_insert_seq_ignore_nls(ovec!["vec = 97┃684"], IGNORE_CHARS_NO_NUM)?;
|
||||||
|
|
||||||
assert_insert_ignore(ovec!["vec = 0┃"], '0')?;
|
assert_insert_ignore_nls(ovec!["vec = 0┃"], '0')?;
|
||||||
assert_insert_ignore(ovec!["vec = 0┃"], '9')?;
|
assert_insert_ignore_nls(ovec!["vec = 0┃"], '9')?;
|
||||||
assert_insert_ignore(ovec!["vec = ┃0"], '0')?;
|
assert_insert_ignore_nls(ovec!["vec = ┃0"], '0')?;
|
||||||
assert_insert_ignore(ovec!["vec = ┃1234"], '0')?;
|
assert_insert_ignore_nls(ovec!["vec = ┃1234"], '0')?;
|
||||||
assert_insert_ignore(ovec!["vec = ┃100"], '0')?;
|
assert_insert_ignore_nls(ovec!["vec = ┃100"], '0')?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1727,10 +1773,6 @@ pub mod test_ed_update {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
const IGNORE_CHARS: &str = "{}()[]-><-_\"azAZ:@09";
|
|
||||||
const IGNORE_NO_LTR: &str = "{\"5";
|
|
||||||
const IGNORE_NO_NUM: &str = "a{\"";
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ignore_record() -> Result<(), String> {
|
fn test_ignore_record() -> Result<(), String> {
|
||||||
assert_insert_seq_ignore_nls(ovec!["val = ┃{ }"], IGNORE_CHARS)?;
|
assert_insert_seq_ignore_nls(ovec!["val = ┃{ }"], IGNORE_CHARS)?;
|
||||||
|
@ -1819,187 +1861,187 @@ pub mod test_ed_update {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ignore_nested_record() -> Result<(), String> {
|
fn test_ignore_nested_record() -> Result<(), String> {
|
||||||
assert_insert_seq(ovec!["{ a: { ┃ } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { a: { ┃ } }"], IGNORE_NO_LTR)?;
|
||||||
/*assert_insert_seq(ovec!["{ a: ┃{ } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { a: ┃{ } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ a: {┃ } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { a: {┃ } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ a: { }┃ }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { a: { }┃ }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ a: { } ┃}"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { a: { } ┃}"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ a: { } }┃"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { a: { } }┃"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ a:┃ { } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { a:┃ { } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{┃ a: { } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = {┃ a: { } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["┃{ a: { } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = ┃{ a: { } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ ┃a: { } }"], "1")?;
|
assert_insert_seq_ignore_nls(ovec!["val = { ┃a: { } }"], "1")?;
|
||||||
|
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a:┃ RunTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a:┃ RunTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: {┃ z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: {┃ z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: ┃{ z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: ┃{ z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: ┃RunTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: ┃RunTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: R┃unTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: R┃unTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: Ru┃nTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: Ru┃nTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1:┃ { z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1:┃ { z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{┃ camelCaseB1: { z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = {┃ camelCaseB1: { z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["┃{ camelCaseB1: { z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = ┃{ camelCaseB1: { z15a: RunTimeError } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ ┃camelCaseB1: { z15a: RunTimeError } }"], "1")?;
|
assert_insert_seq_ignore_nls(ovec!["val = { ┃camelCaseB1: { z15a: RunTimeError } }"], "1")?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { ┃z15a: RunTimeError } }"], "1")?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { ┃z15a: RunTimeError } }"], "1")?;
|
||||||
|
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: \"\"┃ } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: \"\"┃ } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: ┃\"\" } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: ┃\"\" } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a:┃ \"\" } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a:┃ \"\" } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: \"\" ┃} }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: \"\" ┃} }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: {┃ z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: {┃ z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: ┃{ z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: ┃{ z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: \"\" }┃ }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: \"\" }┃ }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: \"\" } ┃}"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: \"\" } ┃}"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: \"\" } }┃"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: \"\" } }┃"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1:┃ { z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1:┃ { z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{┃ camelCaseB1: { z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = {┃ camelCaseB1: { z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["┃{ camelCaseB1: { z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
assert_insert_seq_ignore_nls(ovec!["val = ┃{ camelCaseB1: { z15a: \"\" } }"], IGNORE_NO_LTR)?;
|
||||||
assert_insert_seq(ovec!["{ ┃camelCaseB1: { z15a: \"\" } }"], "1")?;
|
assert_insert_seq_ignore_nls(ovec!["val = { ┃camelCaseB1: { z15a: \"\" } }"], "1")?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { ┃z15a: \"\" } }"], "1")?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { ┃z15a: \"\" } }"], "1")?;
|
||||||
|
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: 0┃ } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: 0┃ } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: ┃123 } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: ┃123 } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a:┃ 999 } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a:┃ 999 } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: 80 ┃} }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: 80 ┃} }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: {┃ z15a: 99000 } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: {┃ z15a: 99000 } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: ┃{ z15a: 12 } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: ┃{ z15a: 12 } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: 7 }┃ }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: 7 }┃ }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: 98 } ┃}"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: 98 } ┃}"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { z15a: 4582 } }┃"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { z15a: 4582 } }┃"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1:┃ { z15a: 0 } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1:┃ { z15a: 0 } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{┃ camelCaseB1: { z15a: 44 } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = {┃ camelCaseB1: { z15a: 44 } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["┃{ camelCaseB1: { z15a: 100123 } }"], IGNORE_NO_NUM)?;
|
assert_insert_seq_ignore_nls(ovec!["val = ┃{ camelCaseB1: { z15a: 100123 } }"], IGNORE_NO_NUM)?;
|
||||||
assert_insert_seq(ovec!["{ ┃camelCaseB1: { z15a: 5 } }"], "1")?;
|
assert_insert_seq_ignore_nls(ovec!["val = { ┃camelCaseB1: { z15a: 5 } }"], "1")?;
|
||||||
assert_insert_seq(ovec!["{ camelCaseB1: { ┃z15a: 6 } }"], "1")?;
|
assert_insert_seq_ignore_nls(ovec!["val = { camelCaseB1: { ┃z15a: 6 } }"], "1")?;
|
||||||
|
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\"┃ } }"],
|
ovec!["val = { camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\"┃ } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { z15a: ┃\"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = { camelCaseB1: { z15a: ┃\"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { z15a:┃ \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = { camelCaseB1: { z15a:┃ \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" ┃} }"],
|
ovec!["val = { camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" ┃} }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: {┃ z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = { camelCaseB1: {┃ z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: ┃{ z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = { camelCaseB1: ┃{ z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" }┃ }"],
|
ovec!["val = { camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" }┃ }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } ┃}"],
|
ovec!["val = { camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } ┃}"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }┃"],
|
ovec!["val = { camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }┃"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1:┃ { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = { camelCaseB1:┃ { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{┃ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = {┃ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["┃{ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = ┃{ camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ ┃camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = { ┃camelCaseB1: { z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
"1",
|
"1",
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ camelCaseB1: { ┃z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
ovec!["val = { camelCaseB1: { ┃z15a: \"hello, hello.0123456789ZXY{}[]-><-\" } }"],
|
||||||
"1",
|
"1",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ g: { oi: { ng: { d: { e: { e: { p: { camelCase:┃ RunTimeError } } } } } } } }"],
|
ovec!["val = { g: { oi: { ng: { d: { e: { e: { p: { camelCase:┃ RunTimeError } } } } } } } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ g: { oi: { ng: { d: { e: { e: { p: { camelCase: R┃unTimeError } } } } } } } }"],
|
ovec!["val = { g: { oi: { ng: { d: { e: { e: { p: { camelCase: R┃unTimeError } } } } } } } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }┃"],
|
ovec!["val = { g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }┃"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeEr┃ror } } } } } } } }"],
|
ovec!["val = { g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeEr┃ror } } } } } } } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ g: { oi: { ng: { d: { e: {┃ e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
ovec!["val = { g: { oi: { ng: { d: { e: {┃ e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ g: { oi: { ng: { d: { e: { e:┃ { p: { camelCase: RunTimeError } } } } } } } }"],
|
ovec!["val = { g: { oi: { ng: { d: { e: { e:┃ { p: { camelCase: RunTimeError } } } } } } } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{┃ g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
ovec!["val = {┃ g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["┃{ g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
ovec!["val = ┃{ g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
||||||
IGNORE_NO_LTR,
|
IGNORE_NO_LTR,
|
||||||
)?;
|
)?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_ignore_nls(
|
||||||
ovec!["{ ┃g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
ovec!["val = { ┃g: { oi: { ng: { d: { e: { e: { p: { camelCase: RunTimeError } } } } } } } }"],
|
||||||
"2",
|
"2",
|
||||||
)?;*/
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_single_elt_list() -> Result<(), String> {
|
fn test_single_elt_list() -> Result<(), String> {
|
||||||
/*YOLOassert_insert( ovec!["[ ┃ ]"], '[')?;
|
assert_insert_in_def( ovec!["[ ┃ ]"], '[')?;
|
||||||
|
|
||||||
assert_insert_seq( ovec!["[ 0┃ ]"], "[0")?;
|
assert_insert_nls( ovec!["val = [ ┃ ]"], ovec!["val = [ 0┃ ]"], '0')?;
|
||||||
assert_insert_seq( ovec!["[ 1┃ ]"], "[1")?;
|
assert_insert_nls( ovec!["val = [ ┃ ]"], ovec!["val = [ 1┃ ]"], '1')?;
|
||||||
assert_insert_seq( ovec!["[ 9┃ ]"], "[9")?;
|
assert_insert_nls( ovec!["val = [ ┃ ]"], ovec!["val = [ 9┃ ]"], '9')?;
|
||||||
|
|
||||||
assert_insert_seq( ovec!["[ \"┃\" ]"], "[\"")?;
|
assert_insert_nls( ovec!["val = [ ┃ ]"], ovec!["val = [ \"┃\" ]"], '\"')?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_nls(
|
||||||
ovec!["┃"],
|
ovec!["val = [ ┃ ]"],
|
||||||
ovec!["[ \"hello, hello.0123456789ZXY{}[]-><-┃\" ]"],
|
ovec!["val = [ \"hello, hello.0123456789ZXY{}[]-><-┃\" ]"],
|
||||||
"[\"hello, hello.0123456789ZXY{}[]-><-",
|
"\"hello, hello.0123456789ZXY{}[]-><-",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
assert_insert_seq( ovec!["[ { ┃ } ]"], "[{")?;
|
assert_insert_nls( ovec!["val = [ ┃ ]"], ovec!["val = [ { ┃ } ]"], '{')?;
|
||||||
assert_insert_seq( ovec!["[ { a┃ } ]"], "[{a")?;
|
assert_insert_seq_nls( ovec!["val = [ ┃ ]"], ovec!["val = [ { a┃ } ]"], "{a")?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_nls(
|
||||||
ovec!["┃"],
|
ovec!["val = [ ┃ ]"],
|
||||||
ovec!["[ { camelCase: { zulu: \"nested┃\" } } ]"],
|
ovec!["val = [ { camelCase: { zulu: \"nested┃\" } } ]"],
|
||||||
"[{camelCase:{zulu:\"nested",
|
"{camelCase:{zulu:\"nested",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
assert_insert_seq( ovec!["[ [ ┃ ] ]"], "[[")?;
|
assert_insert_nls( ovec!["val = [ ┃ ]"], ovec!["val = [ [ ┃ ] ]"], '[')?;
|
||||||
assert_insert_seq( ovec!["[ [ [ ┃ ] ] ]"], "[[[")?;
|
assert_insert_seq_nls( ovec!["val = [ ┃ ]"],ovec!["val = [ [ [ ┃ ] ] ]"], "[[")?;
|
||||||
assert_insert_seq( ovec!["[ [ 0┃ ] ]"], "[[0")?;
|
assert_insert_seq_nls( ovec!["val = [ ┃ ]"],ovec!["val = [ [ 0┃ ] ]"], "[0")?;
|
||||||
assert_insert_seq( ovec!["[ [ \"abc┃\" ] ]"], "[[\"abc")?;
|
assert_insert_seq_nls( ovec!["val = [ ┃ ]"],ovec!["val = [ [ \"abc┃\" ] ]"], "[\"abc")?;
|
||||||
assert_insert_seq(
|
assert_insert_seq_nls(
|
||||||
ovec!["┃"],
|
ovec!["val = [ ┃ ]"],
|
||||||
ovec!["[ [ { camelCase: { a: 79000┃ } } ] ]"],
|
ovec!["val = [ [ { camelCase: { a: 79000┃ } } ] ]"],
|
||||||
"[[{camelCase:{a:79000",
|
"[{camelCase:{a:79000",
|
||||||
)?;*/
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub fn update_invalid_lookup(
|
||||||
input_str: &str,
|
input_str: &str,
|
||||||
old_pool_str: &PoolStr,
|
old_pool_str: &PoolStr,
|
||||||
curr_mark_node_id: MarkNodeId,
|
curr_mark_node_id: MarkNodeId,
|
||||||
ast_node_id: ExprId,
|
expr_id: ExprId,
|
||||||
ed_model: &mut EdModel,
|
ed_model: &mut EdModel,
|
||||||
) -> EdResult<InputOutcome> {
|
) -> EdResult<InputOutcome> {
|
||||||
if input_str.chars().all(|ch| ch.is_ascii_alphanumeric()) {
|
if input_str.chars().all(|ch| ch.is_ascii_alphanumeric()) {
|
||||||
|
@ -32,7 +32,7 @@ pub fn update_invalid_lookup(
|
||||||
.module
|
.module
|
||||||
.env
|
.env
|
||||||
.pool
|
.pool
|
||||||
.set(ast_node_id, Expr2::InvalidLookup(new_pool_str));
|
.set(expr_id, Expr2::InvalidLookup(new_pool_str));
|
||||||
|
|
||||||
// update MarkupNode
|
// update MarkupNode
|
||||||
let curr_mark_node_mut = ed_model.mark_node_pool.get_mut(curr_mark_node_id);
|
let curr_mark_node_mut = ed_model.mark_node_pool.get_mut(curr_mark_node_id);
|
||||||
|
|
|
@ -182,101 +182,106 @@ pub fn update_record_colon(
|
||||||
if let Some(prev_mark_node_id) = prev_mark_node_id_opt {
|
if let Some(prev_mark_node_id) = prev_mark_node_id_opt {
|
||||||
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
let prev_mark_node = ed_model.mark_node_pool.get(prev_mark_node_id);
|
||||||
|
|
||||||
let prev_ast_node = ed_model
|
match prev_mark_node.get_ast_node_id() {
|
||||||
.module
|
ASTNodeId::ADefId(_) => Ok(InputOutcome::Ignored),
|
||||||
.env
|
ASTNodeId::AExprId(prev_expr_id) => {
|
||||||
.pool
|
let prev_expr = ed_model
|
||||||
.get(prev_mark_node.get_ast_node_id().to_expr_id()?);
|
.module
|
||||||
|
.env
|
||||||
|
.pool
|
||||||
|
.get(prev_expr_id);
|
||||||
|
|
||||||
// current and prev node should always point to record when in valid position to add ':'
|
// current and prev node should always point to record when in valid position to add ':'
|
||||||
if matches!(prev_ast_node, Expr2::Record { .. })
|
if matches!(prev_expr, Expr2::Record { .. })
|
||||||
&& matches!(curr_ast_node, Expr2::Record { .. })
|
&& matches!(curr_ast_node, Expr2::Record { .. })
|
||||||
{
|
{
|
||||||
let sibling_ids = curr_mark_node.get_sibling_ids(&ed_model.mark_node_pool);
|
let sibling_ids = curr_mark_node.get_sibling_ids(&ed_model.mark_node_pool);
|
||||||
|
|
||||||
let new_child_index = index_of(curr_mark_node_id, &sibling_ids)?;
|
let new_child_index = index_of(curr_mark_node_id, &sibling_ids)?;
|
||||||
|
|
||||||
let ast_node_ref = ed_model.module.env.pool.get(record_ast_node_id);
|
let ast_node_ref = ed_model.module.env.pool.get(record_ast_node_id);
|
||||||
|
|
||||||
match ast_node_ref {
|
match ast_node_ref {
|
||||||
Expr2::Record {
|
Expr2::Record {
|
||||||
record_var: _,
|
record_var: _,
|
||||||
fields,
|
fields,
|
||||||
} => {
|
} => {
|
||||||
if ed_model.node_exists_at_caret() {
|
if ed_model.node_exists_at_caret() {
|
||||||
let next_mark_node_id =
|
let next_mark_node_id =
|
||||||
ed_model.grid_node_map.get_id_at_row_col(old_caret_pos)?;
|
ed_model.grid_node_map.get_id_at_row_col(old_caret_pos)?;
|
||||||
let next_mark_node = ed_model.mark_node_pool.get(next_mark_node_id);
|
let next_mark_node = ed_model.mark_node_pool.get(next_mark_node_id);
|
||||||
if next_mark_node.get_content() == nodes::RIGHT_ACCOLADE {
|
if next_mark_node.get_content() == nodes::RIGHT_ACCOLADE {
|
||||||
// update AST node
|
// update AST node
|
||||||
let new_field_val = Expr2::Blank;
|
let new_field_val = Expr2::Blank;
|
||||||
let new_field_val_id = ed_model.module.env.pool.add(new_field_val);
|
let new_field_val_id = ed_model.module.env.pool.add(new_field_val);
|
||||||
|
|
||||||
let first_field_mut = fields
|
let first_field_mut = fields
|
||||||
.iter_mut(ed_model.module.env.pool)
|
.iter_mut(ed_model.module.env.pool)
|
||||||
.next()
|
.next()
|
||||||
.with_context(|| RecordWithoutFields {})?;
|
.with_context(|| RecordWithoutFields {})?;
|
||||||
|
|
||||||
*first_field_mut = RecordField::LabeledValue(
|
*first_field_mut = RecordField::LabeledValue(
|
||||||
*first_field_mut.get_record_field_pool_str(),
|
*first_field_mut.get_record_field_pool_str(),
|
||||||
*first_field_mut.get_record_field_var(),
|
*first_field_mut.get_record_field_var(),
|
||||||
new_field_val_id,
|
new_field_val_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
// update Markup
|
// update Markup
|
||||||
let record_colon = nodes::COLON;
|
let record_colon = nodes::COLON;
|
||||||
|
|
||||||
let record_colon_node = MarkupNode::Text {
|
let record_colon_node = MarkupNode::Text {
|
||||||
content: record_colon.to_owned(),
|
content: record_colon.to_owned(),
|
||||||
ast_node_id: ASTNodeId::AExprId(record_ast_node_id),
|
ast_node_id: ASTNodeId::AExprId(record_ast_node_id),
|
||||||
syn_high_style: HighlightStyle::Operator,
|
syn_high_style: HighlightStyle::Operator,
|
||||||
attributes: Attributes::new(),
|
attributes: Attributes::new(),
|
||||||
parent_id_opt: Some(parent_id),
|
parent_id_opt: Some(parent_id),
|
||||||
newline_at_end: false,
|
newline_at_end: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let record_colon_node_id =
|
let record_colon_node_id =
|
||||||
ed_model.add_mark_node(record_colon_node);
|
ed_model.add_mark_node(record_colon_node);
|
||||||
ed_model
|
ed_model
|
||||||
.mark_node_pool
|
.mark_node_pool
|
||||||
.get_mut(parent_id)
|
.get_mut(parent_id)
|
||||||
.add_child_at_index(new_child_index, record_colon_node_id)?;
|
.add_child_at_index(new_child_index, record_colon_node_id)?;
|
||||||
|
|
||||||
let record_blank_node_id = ed_model.add_mark_node(new_blank_mn(
|
let record_blank_node_id = ed_model.add_mark_node(new_blank_mn(
|
||||||
ASTNodeId::AExprId(new_field_val_id),
|
ASTNodeId::AExprId(new_field_val_id),
|
||||||
Some(parent_id),
|
Some(parent_id),
|
||||||
));
|
));
|
||||||
|
|
||||||
ed_model
|
ed_model
|
||||||
.mark_node_pool
|
.mark_node_pool
|
||||||
.get_mut(parent_id)
|
.get_mut(parent_id)
|
||||||
.add_child_at_index(
|
.add_child_at_index(
|
||||||
new_child_index + 1,
|
new_child_index + 1,
|
||||||
record_blank_node_id,
|
record_blank_node_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// update caret
|
// update caret
|
||||||
ed_model.simple_move_carets_right(record_colon.len());
|
ed_model.simple_move_carets_right(record_colon.len());
|
||||||
|
|
||||||
// update GridNodeMap and CodeLines
|
// update GridNodeMap and CodeLines
|
||||||
ed_model.insert_all_between_line(
|
ed_model.insert_all_between_line(
|
||||||
old_caret_pos.line,
|
old_caret_pos.line,
|
||||||
old_caret_pos.column,
|
old_caret_pos.column,
|
||||||
&[record_colon_node_id, record_blank_node_id],
|
&[record_colon_node_id, record_blank_node_id],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(InputOutcome::Accepted)
|
Ok(InputOutcome::Accepted)
|
||||||
} else {
|
} else {
|
||||||
Ok(InputOutcome::Ignored)
|
Ok(InputOutcome::Ignored)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Ok(InputOutcome::Ignored)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
_ => Ok(InputOutcome::Ignored),
|
||||||
Ok(InputOutcome::Ignored)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Ok(InputOutcome::Ignored)
|
||||||
}
|
}
|
||||||
_ => Ok(InputOutcome::Ignored),
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Ok(InputOutcome::Ignored)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok(InputOutcome::Ignored)
|
Ok(InputOutcome::Ignored)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue