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();
|
let value = cmd_view.get();
|
||||||
|
|
||||||
if self.ctx.read().unwrap().meta_chars.contains(&value) {
|
if self.ctx.read().unwrap().meta_chars.contains(&value) {
|
||||||
eprintln!("char: meta char EXID");
|
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
} else {
|
} else {
|
||||||
self.data.set(value);
|
self.data.set(value);
|
||||||
|
|
|
@ -12,7 +12,7 @@ use {
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum ListCmd {
|
pub enum ListCmd {
|
||||||
DeletePxev,
|
DeletePxev,
|
||||||
DeleteNexd,
|
DeleteNexd,
|
||||||
JoinNexd,
|
JoinNexd,
|
||||||
|
@ -154,7 +154,6 @@ impl ObjCommander for ListEditor {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if let Some(cur_item) = self.get_item_mut() {
|
if let Some(cur_item) = self.get_item_mut() {
|
||||||
|
|
|
@ -196,7 +196,6 @@ impl ListEditor {
|
||||||
|
|
||||||
/// delete all items
|
/// delete all items
|
||||||
pub fn clear(&mut self) {
|
pub fn clear(&mut self) {
|
||||||
eprintln!("list editor: clear");
|
|
||||||
let mut b = self.spillbuf.write().unwrap();
|
let mut b = self.spillbuf.write().unwrap();
|
||||||
for i in 0..self.data.len() {
|
for i in 0..self.data.len() {
|
||||||
b.push( self.data.get(i) );
|
b.push( self.data.get(i) );
|
||||||
|
@ -266,50 +265,25 @@ impl ListEditor {
|
||||||
);
|
);
|
||||||
self.data.remove(idx);
|
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) {
|
pub fn listlist_split(&mut self) {
|
||||||
let cur = self.get_cursor();
|
let cur = self.get_cursor();
|
||||||
eprintln!("listlist_split(): cur = {:?}", cur);
|
|
||||||
if let Some(mut item) = self.get_item().clone() {
|
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));
|
item.send_cmd_obj(ListCmd::Split.into_repr_tree(&self.ctx));
|
||||||
eprintln!("listlist_split(): done child split");
|
|
||||||
|
|
||||||
if cur.tree_addr.len() < 3 {
|
if cur.tree_addr.len() < 3 {
|
||||||
item.goto(TreeCursor::none());
|
item.goto(TreeCursor::none());
|
||||||
let mut tail_node = Context::make_node(&self.ctx, self.typ.clone(), 0).unwrap();
|
|
||||||
//tail_node = tail_node.morph( );
|
self.set_leaf_mode(ListCursorMode::Insert);
|
||||||
tail_node.goto(TreeCursor::home());
|
self.nexd();
|
||||||
|
|
||||||
let mut b = item.spillbuf.write().unwrap();
|
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() {
|
for node in b.iter() {
|
||||||
tail_node
|
tail_node
|
||||||
.send_cmd_obj(
|
.send_cmd_obj(
|
||||||
|
@ -325,23 +299,19 @@ impl ListEditor {
|
||||||
drop(b);
|
drop(b);
|
||||||
drop(item);
|
drop(item);
|
||||||
|
|
||||||
self.set_leaf_mode(ListCursorMode::Insert);
|
|
||||||
self.nexd();
|
|
||||||
|
|
||||||
tail_node.goto(TreeCursor::home());
|
tail_node.goto(TreeCursor::home());
|
||||||
if cur.tree_addr.len() > 2 {
|
if cur.tree_addr.len() > 2 {
|
||||||
tail_node.dn();
|
tail_node.dn();
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln!("insert tail node");
|
|
||||||
self.insert(
|
self.insert(
|
||||||
Arc::new(RwLock::new(tail_node))
|
Arc::new(RwLock::new(tail_node))
|
||||||
);
|
);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
self.up();
|
self.up();
|
||||||
self.listlist_split();
|
self.listlist_split();
|
||||||
self.dn();
|
self.dn();
|
||||||
eprintln!("tree depth >= 3");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,7 +374,6 @@ impl ListEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn listlist_join_nexd(&mut self, idx: usize) {
|
pub fn listlist_join_nexd(&mut self, idx: usize) {
|
||||||
eprintln!("listilst_join_nexd");
|
|
||||||
{
|
{
|
||||||
let cur_editor = self.data.get(idx);
|
let cur_editor = self.data.get(idx);
|
||||||
let nxd_editor = self.data.get(idx + 1);
|
let nxd_editor = self.data.get(idx + 1);
|
||||||
|
@ -426,7 +395,7 @@ impl ListEditor {
|
||||||
});
|
});
|
||||||
|
|
||||||
let data = nxd_editor.spillbuf.read().unwrap();
|
let data = nxd_editor.spillbuf.read().unwrap();
|
||||||
eprintln!("spillbuf of next : {} elements", data.len());
|
|
||||||
for x in data.iter() {
|
for x in data.iter() {
|
||||||
cur_editor.send_cmd_obj(
|
cur_editor.send_cmd_obj(
|
||||||
ReprTree::new_leaf(
|
ReprTree::new_leaf(
|
||||||
|
@ -447,7 +416,7 @@ impl ListEditor {
|
||||||
} else {
|
} else {
|
||||||
cur_editor.goto(TreeCursor {
|
cur_editor.goto(TreeCursor {
|
||||||
tree_addr: vec![ old_cur.tree_addr[0] ],
|
tree_addr: vec![ old_cur.tree_addr[0] ],
|
||||||
leaf_mode: ListCursorMode::Insert
|
leaf_mode: ListCursorMode::Insert
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,10 +151,10 @@ impl PTYListController {
|
||||||
let mut e = self.editor.write().unwrap();
|
let mut e = self.editor.write().unwrap();
|
||||||
let cur = e.cursor.get();
|
let cur = e.cursor.get();
|
||||||
|
|
||||||
if Some(c) == self.split_char {
|
if Some(c) == self.split_char
|
||||||
eprintln!("handle meta char: --> e.listlist_split()");
|
// || Some(c) == child_close_char
|
||||||
|
{
|
||||||
e.listlist_split();
|
e.listlist_split();
|
||||||
eprintln!("e.listlist_split() DONE");
|
|
||||||
TreeNavResult::Continue
|
TreeNavResult::Continue
|
||||||
} else if Some(c) == child_close_char {
|
} else if Some(c) == child_close_char {
|
||||||
e.goto(TreeCursor::none());
|
e.goto(TreeCursor::none());
|
||||||
|
|
|
@ -25,7 +25,10 @@ pub fn init_ctx(ctx: &mut Context) {
|
||||||
ctx.add_morphism(
|
ctx.add_morphism(
|
||||||
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type").unwrap() },
|
MorphismTypePattern { src_tyid: ctx.get_typeid("List"), dst_tyid: ctx.get_typeid("Type").unwrap() },
|
||||||
Arc::new(move |node, _dst_type:_| {
|
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)
|
Some(new_node)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -127,12 +127,15 @@ impl TypeTermEditor {
|
||||||
node
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_state(&mut self, new_state: State) {
|
fn set_state(&mut self, new_state: State) {
|
||||||
eprintln!("TypeEdit: set state to {:?}", new_state);
|
|
||||||
|
|
||||||
let old_node = self.cur_node.get();
|
let old_node = self.cur_node.get();
|
||||||
|
|
||||||
let mut node = match new_state {
|
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 => {
|
State::App => {
|
||||||
Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap()
|
Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap()
|
||||||
.morph( (&self.ctx, "( Type::App )").into() )
|
.morph( (&self.ctx, "( Type::App )").into() )
|
||||||
|
@ -238,7 +241,6 @@ impl TypeTermEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_child_cmd(&mut self, cmd: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
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 );
|
let res = self.cur_node.get_mut().send_cmd_obj( cmd );
|
||||||
self.forward_spill();
|
self.forward_spill();
|
||||||
res
|
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
|
/* unwrap a ladder if it only contains one element
|
||||||
*/
|
*/
|
||||||
pub fn normalize_singleton(&mut self) {
|
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_node = self.cur_node.get().clone();
|
||||||
let mut subladder_list_edit = subladder_list_node.get_edit::<ListEditor>().unwrap();
|
let mut subladder_list_edit = subladder_list_node.get_edit::<ListEditor>().unwrap();
|
||||||
|
|
||||||
let subladder_list_edit = subladder_list_edit.read().unwrap();
|
let subladder_list_edit = subladder_list_edit.read().unwrap();
|
||||||
if subladder_list_edit.data.len() == 1 {
|
if subladder_list_edit.data.len() == 1 {
|
||||||
eprintln!("-> is singleton ladder");
|
|
||||||
let it_node = subladder_list_edit.data.get(0);
|
let it_node = subladder_list_edit.data.get(0);
|
||||||
let it_node = it_node.read().unwrap();
|
let it_node = it_node.read().unwrap();
|
||||||
if it_node.get_type() == (&self.ctx, "( Type )").into() {
|
if it_node.get_type() == (&self.ctx, "( Type )").into() {
|
||||||
|
@ -302,13 +316,11 @@ impl TypeTermEditor {
|
||||||
|
|
||||||
other_tt.normalize_singleton();
|
other_tt.normalize_singleton();
|
||||||
|
|
||||||
eprintln!(">>>==>>> reset curent editor!!");
|
|
||||||
self.close_char.set(other_tt.close_char.get());
|
self.close_char.set(other_tt.close_char.get());
|
||||||
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 {
|
} else {
|
||||||
eprintln!("-> is empty ladder");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +365,6 @@ impl TypeTermEditor {
|
||||||
/* in insert mode, morph the previous element into a ladder and continue there
|
/* in insert mode, morph the previous element into a ladder and continue there
|
||||||
*/
|
*/
|
||||||
pub fn previous_item_into_ladder(&mut self) {
|
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 app_edit = self.cur_node.get().get_edit::<ListEditor>().expect("editor");
|
||||||
let mut app_edit = app_edit.write().unwrap();
|
let mut app_edit = app_edit.write().unwrap();
|
||||||
|
|
||||||
|
@ -376,14 +387,12 @@ impl TypeTermEditor {
|
||||||
|
|
||||||
// if item at cursor is Ladder
|
// if item at cursor is Ladder
|
||||||
State::Ladder => {
|
State::Ladder => {
|
||||||
eprintln!("current item is already ladder");
|
|
||||||
drop(item_typterm);
|
drop(item_typterm);
|
||||||
|
|
||||||
app_edit.dn();
|
app_edit.dn();
|
||||||
app_edit.qnexd();
|
app_edit.qnexd();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!("create new ladder");
|
|
||||||
item_typterm.goto(TreeCursor::none());
|
item_typterm.goto(TreeCursor::none());
|
||||||
drop(item_typterm);
|
drop(item_typterm);
|
||||||
|
|
||||||
|
@ -406,16 +415,9 @@ impl TypeTermEditor {
|
||||||
(&self.ctx, "( NestedNode )"),
|
(&self.ctx, "( NestedNode )"),
|
||||||
SingletonBuffer::<NestedNode>::new( item_node ).get_port().into()
|
SingletonBuffer::<NestedNode>::new( item_node ).get_port().into()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*app_edit.get_item_mut().unwrap().write().unwrap() = new_node;
|
*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();
|
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) {
|
pub fn morph_to_ladder(&mut self) {
|
||||||
|
eprintln!("morph into ladder");
|
||||||
let old_node = self.cur_node.get().clone();
|
let old_node = self.cur_node.get().clone();
|
||||||
|
|
||||||
/* create a new NestedNode with TerminaltypeEditor,
|
/* create a new NestedNode with TerminaltypeEditor,
|
||||||
|
@ -460,10 +463,6 @@ impl TypeTermEditor {
|
||||||
|
|
||||||
self.set_addr(0);
|
self.set_addr(0);
|
||||||
self.dn();
|
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 {
|
impl ObjCommander for TypeTermEditor {
|
||||||
fn send_cmd_obj(&mut self, co: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
fn send_cmd_obj(&mut self, co: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||||
|
let cur = self.get_cursor();
|
||||||
|
|
||||||
let cmd_obj = co.clone();
|
let cmd_obj = co.clone();
|
||||||
let cmd_obj = cmd_obj.read().unwrap();
|
let cmd_obj = cmd_obj.read().unwrap();
|
||||||
|
|
||||||
|
@ -546,19 +547,15 @@ impl ObjCommander for TypeTermEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
State::Ladder => {
|
State::Ladder => {
|
||||||
let res = self.send_child_cmd( co );
|
let res = self.send_child_cmd( co.clone() );
|
||||||
let cur = self.get_cursor();
|
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
TreeNavResult::Continue => {
|
TreeNavResult::Continue => {
|
||||||
if cur.tree_addr.len() == 3 {
|
match c {
|
||||||
match c {
|
'~' => {
|
||||||
'~' => {
|
self.normalize_nested_ladder();
|
||||||
self.normalize_nested_ladder();
|
|
||||||
self.normalize_singleton();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
TreeNavResult::Continue
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
|
@ -574,10 +571,6 @@ impl ObjCommander for TypeTermEditor {
|
||||||
State::App => {
|
State::App => {
|
||||||
let res = self.send_child_cmd( co.clone() );
|
let res = self.send_child_cmd( co.clone() );
|
||||||
|
|
||||||
if let Some(cmd) = co.read().unwrap().get_view::<dyn SingletonView<Item = ListCmd>>() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
TreeNavResult::Exit => {
|
TreeNavResult::Exit => {
|
||||||
match c {
|
match c {
|
||||||
|
@ -588,7 +581,26 @@ impl ObjCommander for TypeTermEditor {
|
||||||
_ => {TreeNavResult::Exit}
|
_ => {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 {
|
match c {
|
||||||
'~' => {
|
'~' => {
|
||||||
self.morph_to_ladder();
|
self.morph_to_ladder();
|
||||||
TreeNavResult::Continue
|
self.send_cmd_obj(
|
||||||
|
ListCmd::Split.into_repr_tree( &self.ctx )
|
||||||
|
)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
TreeNavResult::Exit
|
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
|
res
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue