remove debug prints, reduce empty typeterms to any-state and unwrap singleton lists on splits
This commit is contained in:
parent
e111a360a9
commit
40500aa60e
6 changed files with 85 additions and 88 deletions
|
@ -39,7 +39,6 @@ impl ObjCommander for CharEditor {
|
|||
let value = cmd_view.get();
|
||||
|
||||
if self.ctx.read().unwrap().meta_chars.contains(&value) {
|
||||
eprintln!("char: meta char EXID");
|
||||
TreeNavResult::Exit
|
||||
} else {
|
||||
self.data.set(value);
|
||||
|
|
|
@ -155,7 +155,6 @@ impl ObjCommander for ListEditor {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
if let Some(cur_item) = self.get_item_mut() {
|
||||
drop(cmd_repr);
|
||||
|
|
|
@ -196,7 +196,6 @@ impl ListEditor {
|
|||
|
||||
/// delete all items
|
||||
pub fn clear(&mut self) {
|
||||
eprintln!("list editor: clear");
|
||||
let mut b = self.spillbuf.write().unwrap();
|
||||
for i in 0..self.data.len() {
|
||||
b.push( self.data.get(i) );
|
||||
|
@ -266,50 +265,25 @@ impl ListEditor {
|
|||
);
|
||||
self.data.remove(idx);
|
||||
}
|
||||
|
||||
/* TODO
|
||||
*/
|
||||
/*
|
||||
if self.is_listlist() {
|
||||
if idx > 0 && idx < self.data.len()+1 {
|
||||
|
||||
let prev_idx = idx - 1; // get last element before cursor (we are in insert mode)
|
||||
let prev_node = self.data.get(prev_idx);
|
||||
let prev_node = prev_node.read().unwrap();
|
||||
|
||||
if let Some(prev_editor) = prev_node.editor.get() {
|
||||
let prev_editor = prev_editor.downcast::<RwLock<ListEditor>>().unwrap();
|
||||
let prev_editor = prev_editor.write().unwrap();
|
||||
prev_editor.get_data_port().0.update();
|
||||
|
||||
if prev_editor.get_data_port().get_view().unwrap().iter()
|
||||
.filter_map(|x| x.get_data_view::<dyn SingletonView<Item = Option<char>>>(vec![].into_iter())?.get()).count() == 0
|
||||
{
|
||||
drop(prev_editor);
|
||||
self.data.remove(prev_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listlist_split(&mut self) {
|
||||
let cur = self.get_cursor();
|
||||
eprintln!("listlist_split(): cur = {:?}", cur);
|
||||
|
||||
if let Some(mut item) = self.get_item().clone() {
|
||||
eprintln!("listlist_split(): split child item");
|
||||
item.send_cmd_obj(ListCmd::Split.into_repr_tree(&self.ctx));
|
||||
eprintln!("listlist_split(): done child split");
|
||||
|
||||
if cur.tree_addr.len() < 3 {
|
||||
item.goto(TreeCursor::none());
|
||||
let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), 0).unwrap();
|
||||
//tail_node = tail_node.morph( );
|
||||
tail_node.goto(TreeCursor::home());
|
||||
|
||||
self.set_leaf_mode(ListCursorMode::Insert);
|
||||
self.nexd();
|
||||
|
||||
let mut b = item.spillbuf.write().unwrap();
|
||||
let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), 0).unwrap();
|
||||
tail_node.goto(TreeCursor::home());
|
||||
|
||||
for node in b.iter() {
|
||||
tail_node
|
||||
.send_cmd_obj(
|
||||
|
@ -325,23 +299,19 @@ impl ListEditor {
|
|||
drop(b);
|
||||
drop(item);
|
||||
|
||||
self.set_leaf_mode(ListCursorMode::Insert);
|
||||
self.nexd();
|
||||
|
||||
tail_node.goto(TreeCursor::home());
|
||||
if cur.tree_addr.len() > 2 {
|
||||
tail_node.dn();
|
||||
}
|
||||
|
||||
eprintln!("insert tail node");
|
||||
self.insert(
|
||||
Arc::new(RwLock::new(tail_node))
|
||||
);
|
||||
|
||||
} else {
|
||||
self.up();
|
||||
self.listlist_split();
|
||||
self.dn();
|
||||
eprintln!("tree depth >= 3");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -404,7 +374,6 @@ impl ListEditor {
|
|||
}
|
||||
|
||||
pub fn listlist_join_nexd(&mut self, idx: usize) {
|
||||
eprintln!("listilst_join_nexd");
|
||||
{
|
||||
let cur_editor = self.data.get(idx);
|
||||
let nxd_editor = self.data.get(idx + 1);
|
||||
|
@ -426,7 +395,7 @@ impl ListEditor {
|
|||
});
|
||||
|
||||
let data = nxd_editor.spillbuf.read().unwrap();
|
||||
eprintln!("spillbuf of next : {} elements", data.len());
|
||||
|
||||
for x in data.iter() {
|
||||
cur_editor.send_cmd_obj(
|
||||
ReprTree::new_leaf(
|
||||
|
|
|
@ -151,10 +151,10 @@ impl PTYListController {
|
|||
let mut e = self.editor.write().unwrap();
|
||||
let cur = e.cursor.get();
|
||||
|
||||
if Some(c) == self.split_char {
|
||||
eprintln!("handle meta char: --> e.listlist_split()");
|
||||
if Some(c) == self.split_char
|
||||
// || Some(c) == child_close_char
|
||||
{
|
||||
e.listlist_split();
|
||||
eprintln!("e.listlist_split() DONE");
|
||||
TreeNavResult::Continue
|
||||
} else if Some(c) == child_close_char {
|
||||
e.goto(TreeCursor::none());
|
||||
|
|
|
@ -25,7 +25,10 @@ pub fn init_ctx(ctx: &mut Context) {
|
|||
ctx.add_morphism(
|
||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type").unwrap() },
|
||||
Arc::new(move |node, _dst_type:_| {
|
||||
let new_node = TypeTermEditor::with_node( node.ctx.clone(), node.depth.get(), node.clone(), State::Any );
|
||||
let ctx : Arc<RwLock<Context>> = Arc::new(RwLock::new(Context::with_parent(Some(node.ctx.clone()))));
|
||||
ctx.write().unwrap().meta_chars.push('~');
|
||||
|
||||
let new_node = TypeTermEditor::with_node( ctx, node.depth.get(), node.clone(), State::Any );
|
||||
Some(new_node)
|
||||
}));
|
||||
|
||||
|
|
|
@ -128,11 +128,14 @@ impl TypeTermEditor {
|
|||
}
|
||||
|
||||
fn set_state(&mut self, new_state: State) {
|
||||
eprintln!("TypeEdit: set state to {:?}", new_state);
|
||||
|
||||
let old_node = self.cur_node.get();
|
||||
|
||||
let mut node = match new_state {
|
||||
State::Any => {
|
||||
Context::make_node( &self.ctx, (&self.ctx, "( List Char )").into(), 0 ).unwrap()
|
||||
.morph( (&self.ctx, "( Type::Sym )").into() )
|
||||
|
||||
}
|
||||
State::App => {
|
||||
Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap()
|
||||
.morph( (&self.ctx, "( Type::App )").into() )
|
||||
|
@ -238,7 +241,6 @@ impl TypeTermEditor {
|
|||
}
|
||||
|
||||
fn send_child_cmd(&mut self, cmd: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||
eprintln!("send child cmd");
|
||||
let res = self.cur_node.get_mut().send_cmd_obj( cmd );
|
||||
self.forward_spill();
|
||||
res
|
||||
|
@ -283,16 +285,28 @@ impl TypeTermEditor {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn normalize_empty(&mut self) {
|
||||
eprintln!("normalize singleton");
|
||||
let mut subladder_list_node = self.cur_node.get().clone();
|
||||
let mut subladder_list_edit = subladder_list_node.get_edit::<ListEditor>().unwrap();
|
||||
|
||||
let subladder_list_edit = subladder_list_edit.read().unwrap();
|
||||
if subladder_list_edit.data.len() == 0 {
|
||||
|
||||
self.set_state( State::Any );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* unwrap a ladder if it only contains one element
|
||||
*/
|
||||
pub fn normalize_singleton(&mut self) {
|
||||
eprintln!("normalize singleton ladder!");
|
||||
eprintln!("normalize singleton");
|
||||
let mut subladder_list_node = self.cur_node.get().clone();
|
||||
let mut subladder_list_edit = subladder_list_node.get_edit::<ListEditor>().unwrap();
|
||||
|
||||
let subladder_list_edit = subladder_list_edit.read().unwrap();
|
||||
if subladder_list_edit.data.len() == 1 {
|
||||
eprintln!("-> is singleton ladder");
|
||||
let it_node = subladder_list_edit.data.get(0);
|
||||
let it_node = it_node.read().unwrap();
|
||||
if it_node.get_type() == (&self.ctx, "( Type )").into() {
|
||||
|
@ -302,13 +316,11 @@ impl TypeTermEditor {
|
|||
|
||||
other_tt.normalize_singleton();
|
||||
|
||||
eprintln!(">>>==>>> reset curent editor!!");
|
||||
self.close_char.set(other_tt.close_char.get());
|
||||
self.cur_node.set(other_tt.cur_node.get());
|
||||
self.state = other_tt.state;
|
||||
}
|
||||
} else {
|
||||
eprintln!("-> is empty ladder");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +365,6 @@ impl TypeTermEditor {
|
|||
/* in insert mode, morph the previous element into a ladder and continue there
|
||||
*/
|
||||
pub fn previous_item_into_ladder(&mut self) {
|
||||
eprintln!("previous_item_into_ladder()");
|
||||
let app_edit = self.cur_node.get().get_edit::<ListEditor>().expect("editor");
|
||||
let mut app_edit = app_edit.write().unwrap();
|
||||
|
||||
|
@ -376,14 +387,12 @@ impl TypeTermEditor {
|
|||
|
||||
// if item at cursor is Ladder
|
||||
State::Ladder => {
|
||||
eprintln!("current item is already ladder");
|
||||
drop(item_typterm);
|
||||
|
||||
app_edit.dn();
|
||||
app_edit.qnexd();
|
||||
}
|
||||
_ => {
|
||||
eprintln!("create new ladder");
|
||||
item_typterm.goto(TreeCursor::none());
|
||||
drop(item_typterm);
|
||||
|
||||
|
@ -408,14 +417,7 @@ impl TypeTermEditor {
|
|||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
*app_edit.get_item_mut().unwrap().write().unwrap() = new_node;
|
||||
/*
|
||||
let mut c = app_edit.cursor.get();
|
||||
c.mode = ListCursorMode::Select;
|
||||
app_edit.goto( c );
|
||||
*/
|
||||
app_edit.dn();
|
||||
}
|
||||
}
|
||||
|
@ -423,9 +425,10 @@ impl TypeTermEditor {
|
|||
}
|
||||
}
|
||||
|
||||
/* split up current
|
||||
/* replace with new ladder node with self as first element
|
||||
*/
|
||||
pub fn morph_to_ladder(&mut self) {
|
||||
eprintln!("morph into ladder");
|
||||
let old_node = self.cur_node.get().clone();
|
||||
|
||||
/* create a new NestedNode with TerminaltypeEditor,
|
||||
|
@ -460,10 +463,6 @@ impl TypeTermEditor {
|
|||
|
||||
self.set_addr(0);
|
||||
self.dn();
|
||||
|
||||
let res = self.send_cmd_obj(
|
||||
ListCmd::Split.into_repr_tree( &self.ctx )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -499,6 +498,8 @@ impl TreeNav for TypeTermEditor {
|
|||
|
||||
impl ObjCommander for TypeTermEditor {
|
||||
fn send_cmd_obj(&mut self, co: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||
let cur = self.get_cursor();
|
||||
|
||||
let cmd_obj = co.clone();
|
||||
let cmd_obj = cmd_obj.read().unwrap();
|
||||
|
||||
|
@ -546,20 +547,16 @@ impl ObjCommander for TypeTermEditor {
|
|||
}
|
||||
|
||||
State::Ladder => {
|
||||
let res = self.send_child_cmd( co );
|
||||
let cur = self.get_cursor();
|
||||
let res = self.send_child_cmd( co.clone() );
|
||||
|
||||
match res {
|
||||
TreeNavResult::Continue => {
|
||||
if cur.tree_addr.len() == 3 {
|
||||
match c {
|
||||
'~' => {
|
||||
self.normalize_nested_ladder();
|
||||
self.normalize_singleton();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
TreeNavResult::Exit => {
|
||||
|
@ -574,10 +571,6 @@ impl ObjCommander for TypeTermEditor {
|
|||
State::App => {
|
||||
let res = self.send_child_cmd( co.clone() );
|
||||
|
||||
if let Some(cmd) = co.read().unwrap().get_view::<dyn SingletonView<Item = ListCmd>>() {
|
||||
|
||||
}
|
||||
|
||||
match res {
|
||||
TreeNavResult::Exit => {
|
||||
match c {
|
||||
|
@ -588,7 +581,26 @@ impl ObjCommander for TypeTermEditor {
|
|||
_ => {TreeNavResult::Exit}
|
||||
}
|
||||
},
|
||||
res => res
|
||||
TreeNavResult::Continue => {
|
||||
match c {
|
||||
'>'|
|
||||
' ' => {
|
||||
let i = self.cur_node.get().get_edit::<ListEditor>().unwrap();
|
||||
let i = i.read().unwrap();
|
||||
if let Some(i) = i.get_item() {
|
||||
let tte = i.get_edit::<TypeTermEditor>().unwrap();
|
||||
let mut tte = tte.write().unwrap();
|
||||
|
||||
if tte.state == State::Ladder {
|
||||
tte.normalize_singleton();
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -601,7 +613,9 @@ impl ObjCommander for TypeTermEditor {
|
|||
match c {
|
||||
'~' => {
|
||||
self.morph_to_ladder();
|
||||
TreeNavResult::Continue
|
||||
self.send_cmd_obj(
|
||||
ListCmd::Split.into_repr_tree( &self.ctx )
|
||||
)
|
||||
}
|
||||
_ => {
|
||||
TreeNavResult::Exit
|
||||
|
@ -647,7 +661,20 @@ impl ObjCommander for TypeTermEditor {
|
|||
}
|
||||
}
|
||||
|
||||
let res = self.send_child_cmd( co );
|
||||
let res = self.send_child_cmd( co.clone() );
|
||||
|
||||
self.normalize_empty();
|
||||
|
||||
if let Some(cmd) = co.read().unwrap().get_view::<dyn SingletonView<Item = ListCmd>>() {
|
||||
match cmd.get() {
|
||||
ListCmd::Split => {
|
||||
if self.state == State::Ladder {
|
||||
self.normalize_singleton();
|
||||
}
|
||||
}
|
||||
_ =>{}
|
||||
}
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue