From b97ba8dedb505c95bfc8e53de76bfe63aca1ea3f Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 11 Aug 2023 18:25:46 +0200 Subject: [PATCH] list editor: create node with full type already instaed of calling morph after inserting the tail elements --- nested/src/editors/list/editor.rs | 65 ++++++++++++++++--------------- nested/src/type_system/editor.rs | 26 ++----------- 2 files changed, 37 insertions(+), 54 deletions(-) diff --git a/nested/src/editors/list/editor.rs b/nested/src/editors/list/editor.rs index 517ced8..6e14178 100644 --- a/nested/src/editors/list/editor.rs +++ b/nested/src/editors/list/editor.rs @@ -268,18 +268,26 @@ impl ListEditor { } /// split the list off at the current cursor position and return the second half - pub fn split(&mut self) -> ListEditor { - let mut le = ListEditor::new( - Arc::new(RwLock::new(self.ctx.read().unwrap().clone())), - self.typ.clone()); - + pub fn split(&mut self, le_node: &mut NestedNode) { let cur = self.cursor.get(); if let Some(idx) = cur.idx { let idx = idx as usize; + le_node.goto(TreeCursor::home()); for _ in idx .. self.data.len() { - le.data.push( self.data.get(idx) ); + + eprintln!("send items to new tail"); + le_node.cmd.get().unwrap().write().unwrap().send_cmd_obj( + self.data.get(idx).read().unwrap().data.clone().unwrap() +/* + ReprTree::new_leaf( + self.ctx.read().unwrap().type_term_from_str("( NestedNode )").unwrap(), + SingletonBuffer::::new( self.data.get(idx).clone().read().unwrap().clone() ).get_port().into() + ) +*/ + ); self.data.remove(idx); } + le_node.goto(TreeCursor::none()); if self.is_listlist() { if idx > 0 && idx < self.data.len()+1 { @@ -303,8 +311,6 @@ impl ListEditor { } } } - - le } /// append data of other editor at the end and set cursor accordingly @@ -347,24 +353,35 @@ impl ListEditor { if let Some(item) = self.get_item() { // let item = item.read().unwrap(); let depth = item.depth; - + if let Some(head_editor) = item.editor.get() { + let head = head_editor.downcast::>().unwrap(); let mut head = head.write().unwrap(); - + if head.data.len() > 0 { if cur.tree_addr.len() > 2 { + eprintln!("call child head listlist split"); head.listlist_split(); + eprintln!("return"); } - let mut tail = head.split(); + eprintln!("got head"); + + let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), 0).unwrap(); + head.split( &mut tail_node ); + + eprintln!("made split"); head.goto(TreeCursor::none()); + drop(head); - tail.cursor.set( - ListCursor { - idx: Some(0), - mode: if cur.tree_addr.len() > 2 { + eprintln!("done goto"); + + tail_node.goto( + TreeCursor { + tree_addr: vec![0], + leaf_mode: if cur.tree_addr.len() > 2 { ListCursorMode::Select } else { ListCursorMode::Insert @@ -372,25 +389,11 @@ impl ListEditor { } ); - let item_type = - if let Some(data) = item.data.clone() { - let data = data.read().unwrap(); - Some(data.get_type().clone()) - } else { - None - }; - - let mut tail_node = tail.into_node(depth.get()); - - //if let Some(item_type) = item_type { - //eprintln!("morph to {}", self.ctx.read().unwrap().type_term_to_str(&self.typ)); - tail_node = tail_node.morph(self.typ.clone()); - //} - - //eprintln!("insert node"); self.insert( Arc::new(RwLock::new(tail_node)) ); + + eprintln!("made insert"); } } } diff --git a/nested/src/type_system/editor.rs b/nested/src/type_system/editor.rs index 1c5ee6a..90fac88 100644 --- a/nested/src/type_system/editor.rs +++ b/nested/src/type_system/editor.rs @@ -64,34 +64,14 @@ impl TypeTermEditor { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("TypeTerm").unwrap() }; + ctx.add_morphism(pattern, Arc::new( - |mut node, _dst_type:_| { - // eprintln!("morphism to typeterm"); + move |mut node, _dst_type:_| { + eprintln!("morphism to typeterm"); PTYListController::for_node( &mut node, Some(' '), None ); PTYListStyle::for_node( &mut node, ("","","") ); let mut new_node = TypeTermEditor::with_node( node.ctx.clone().unwrap(), node.depth.get(), node.clone(), State::Any ); - - let item_editor1 = node.get_edit::().clone().unwrap(); - let item_editor = item_editor1.read().unwrap(); - - for i in 0..item_editor.data.len() { - let item_node = item_editor.data.get(i); - let item_node = item_node.read().unwrap(); - - let item_val_editor = item_node.get_edit::().clone().unwrap(); - let item_val_editor = item_val_editor.read().unwrap(); - let c = item_val_editor.get(); - - new_node.send_cmd_obj( - ReprTree::from_char(new_node.ctx.as_ref().unwrap(), c) - ); - } - - if item_editor.data.len() > 0 { - new_node.goto(TreeCursor::home()); - } - Some(new_node) } )