typeterm editor: avoid nested ladders through more clever event handling instead of dynamically refactoring editor-trees

This commit is contained in:
Michael Sippel 2023-09-07 18:09:01 +02:00
parent d8d282f9e9
commit 62cc40c39c
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 18 additions and 56 deletions

View file

@ -4,7 +4,7 @@ use {
}, },
crate::{ crate::{
type_system::{ReprTree}, type_system::{ReprTree},
editors::{list::{ListEditor, ListCmd}}, editors::{list::{ListEditor, ListCmd, ListCursorMode}},
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
commander::ObjCommander commander::ObjCommander
}, },
@ -64,25 +64,26 @@ impl ObjCommander for TypeTermEditor {
} }
State::Ladder => { State::Ladder => {
let res = self.send_child_cmd( co.clone() ); if c == '~' {
let i0 = self.cur_node.get().get_edit::<ListEditor>().unwrap();
match res { let cur_it = i0.clone().read().unwrap().get_item().clone();
TreeNavResult::Continue => {
match c { if let Some(i) = cur_it {
'~' => { let tte = i.get_edit::<TypeTermEditor>().unwrap();
self.normalize_nested_ladder();
if tte.read().unwrap().state != State::App {
drop(tte);
drop(i);
return self.send_child_cmd(
ListCmd::Split.into_repr_tree( &self.ctx )
);
} }
_ => {}
} }
TreeNavResult::Continue
}
TreeNavResult::Exit => {
match c {
'~' => TreeNavResult::Continue,
_ => TreeNavResult::Exit
}
}
} }
self.send_child_cmd( co.clone() )
} }
State::App => { State::App => {

View file

@ -316,45 +316,6 @@ impl TypeTermEditor {
self.cur_node.set(other_tt.cur_node.get()); self.cur_node.set(other_tt.cur_node.get());
self.state = other_tt.state; self.state = other_tt.state;
} }
} else {
}
}
/* flatten ladder of ladders into one ladder editor
*/
pub fn normalize_nested_ladder(&mut self) {
let mut subladder_list_node = self.cur_node.get().clone();
let subladder_list_edit = subladder_list_node.get_edit::<ListEditor>().unwrap();
let item = subladder_list_edit.write().unwrap().get_item().clone();
if let Some(it_node) = item {
if it_node.get_type() == (&self.ctx, "( Type )").into() {
let other_tt = it_node.get_edit::<TypeTermEditor>().unwrap();
if other_tt.write().unwrap().state == State::Ladder {
let other = other_tt.read().unwrap().cur_node.get().get_edit::<ListEditor>().unwrap();
let buf = other.read().unwrap().data.clone();
subladder_list_edit.write().unwrap().up();
subladder_list_edit.write().unwrap().up();
subladder_list_node.send_cmd_obj(
ListCmd::DeleteNexd.into_repr_tree( &self.ctx )
);
if subladder_list_edit.read().unwrap().get_cursor_warp().tree_addr.len() > 0 {
if subladder_list_edit.read().unwrap().get_cursor_warp().tree_addr[0] == -1 {
subladder_list_edit.write().unwrap().delete_nexd();
}
}
let l = buf.len();
for i in 0..l {
subladder_list_edit.write().unwrap().insert( buf.get(i) );
}
subladder_list_node.dn();
}
}
} }
} }