From 62cc40c39cae578f089650af1eb881c4f1a6892b Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 7 Sep 2023 18:09:01 +0200 Subject: [PATCH] typeterm editor: avoid nested ladders through more clever event handling instead of dynamically refactoring editor-trees --- nested/src/editors/typeterm/cmd.rs | 35 ++++++++++++++------------- nested/src/editors/typeterm/mod.rs | 39 ------------------------------ 2 files changed, 18 insertions(+), 56 deletions(-) diff --git a/nested/src/editors/typeterm/cmd.rs b/nested/src/editors/typeterm/cmd.rs index f5b9aff..23271eb 100644 --- a/nested/src/editors/typeterm/cmd.rs +++ b/nested/src/editors/typeterm/cmd.rs @@ -4,7 +4,7 @@ use { }, crate::{ type_system::{ReprTree}, - editors::{list::{ListEditor, ListCmd}}, + editors::{list::{ListEditor, ListCmd, ListCursorMode}}, tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor}, commander::ObjCommander }, @@ -64,25 +64,26 @@ impl ObjCommander for TypeTermEditor { } State::Ladder => { - let res = self.send_child_cmd( co.clone() ); - - match res { - TreeNavResult::Continue => { - match c { - '~' => { - self.normalize_nested_ladder(); + if c == '~' { + let i0 = self.cur_node.get().get_edit::().unwrap(); + + let cur_it = i0.clone().read().unwrap().get_item().clone(); + + if let Some(i) = cur_it { + let tte = i.get_edit::().unwrap(); + + 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 => { diff --git a/nested/src/editors/typeterm/mod.rs b/nested/src/editors/typeterm/mod.rs index d018c81..259e20d 100644 --- a/nested/src/editors/typeterm/mod.rs +++ b/nested/src/editors/typeterm/mod.rs @@ -316,45 +316,6 @@ impl TypeTermEditor { self.cur_node.set(other_tt.cur_node.get()); 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::().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::().unwrap(); - - if other_tt.write().unwrap().state == State::Ladder { - let other = other_tt.read().unwrap().cur_node.get().get_edit::().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(); - } - } } }