list editor: create node with full type already instaed of calling morph after inserting the tail elements

This commit is contained in:
Michael Sippel 2023-08-11 18:25:46 +02:00
parent efb4cd39da
commit b97ba8dedb
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 37 additions and 54 deletions

View file

@ -268,18 +268,26 @@ impl ListEditor {
} }
/// split the list off at the current cursor position and return the second half /// split the list off at the current cursor position and return the second half
pub fn split(&mut self) -> ListEditor { pub fn split(&mut self, le_node: &mut NestedNode) {
let mut le = ListEditor::new(
Arc::new(RwLock::new(self.ctx.read().unwrap().clone())),
self.typ.clone());
let cur = self.cursor.get(); let cur = self.cursor.get();
if let Some(idx) = cur.idx { if let Some(idx) = cur.idx {
let idx = idx as usize; let idx = idx as usize;
le_node.goto(TreeCursor::home());
for _ in idx .. self.data.len() { 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::<NestedNode>::new( self.data.get(idx).clone().read().unwrap().clone() ).get_port().into()
)
*/
);
self.data.remove(idx); self.data.remove(idx);
} }
le_node.goto(TreeCursor::none());
if self.is_listlist() { if self.is_listlist() {
if idx > 0 && idx < self.data.len()+1 { 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 /// 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() { if let Some(item) = self.get_item() {
// let item = item.read().unwrap(); // let item = item.read().unwrap();
let depth = item.depth; let depth = item.depth;
if let Some(head_editor) = item.editor.get() { if let Some(head_editor) = item.editor.get() {
let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap(); let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut head = head.write().unwrap(); let mut head = head.write().unwrap();
if head.data.len() > 0 { if head.data.len() > 0 {
if cur.tree_addr.len() > 2 { if cur.tree_addr.len() > 2 {
eprintln!("call child head listlist split");
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()); head.goto(TreeCursor::none());
drop(head);
tail.cursor.set( eprintln!("done goto");
ListCursor {
idx: Some(0), tail_node.goto(
mode: if cur.tree_addr.len() > 2 { TreeCursor {
tree_addr: vec![0],
leaf_mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select ListCursorMode::Select
} else { } else {
ListCursorMode::Insert 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( self.insert(
Arc::new(RwLock::new(tail_node)) Arc::new(RwLock::new(tail_node))
); );
eprintln!("made insert");
} }
} }
} }

View file

@ -64,34 +64,14 @@ impl TypeTermEditor {
src_tyid: ctx.get_typeid("List"), src_tyid: ctx.get_typeid("List"),
dst_tyid: ctx.get_typeid("TypeTerm").unwrap() dst_tyid: ctx.get_typeid("TypeTerm").unwrap()
}; };
ctx.add_morphism(pattern, ctx.add_morphism(pattern,
Arc::new( Arc::new(
|mut node, _dst_type:_| { move |mut node, _dst_type:_| {
// eprintln!("morphism to typeterm"); eprintln!("morphism to typeterm");
PTYListController::for_node( &mut node, Some(' '), None ); PTYListController::for_node( &mut node, Some(' '), None );
PTYListStyle::for_node( &mut node, ("","","") ); PTYListStyle::for_node( &mut node, ("","","") );
let mut new_node = TypeTermEditor::with_node( node.ctx.clone().unwrap(), node.depth.get(), node.clone(), State::Any ); let mut new_node = TypeTermEditor::with_node( node.ctx.clone().unwrap(), node.depth.get(), node.clone(), State::Any );
let item_editor1 = node.get_edit::<ListEditor>().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::<crate::editors::char::CharEditor>().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) Some(new_node)
} }
) )