typeterm editor: fix split & close

This commit is contained in:
Michael Sippel 2023-08-21 19:05:09 +02:00
parent 077d91c47e
commit ef99a986a8
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 27 additions and 27 deletions

View file

@ -147,7 +147,7 @@ impl PTYListController {
} }
pub fn handle_meta_char(&mut self, c: char, child_close_char: Option<char>) -> TreeNavResult { pub fn handle_meta_char(&mut self, c: char, child_close_char: Option<char>) -> TreeNavResult {
eprintln!("handle meta char"); eprintln!("handle meta char: got '{}', child_close={:?}, self.close={:?}, split={:?}", c, child_close_char, self.close_char, self.split_char);
let mut e = self.editor.write().unwrap(); let mut e = self.editor.write().unwrap();
let cur = e.cursor.get(); let cur = e.cursor.get();
@ -157,8 +157,8 @@ impl PTYListController {
} else if Some(c) == child_close_char { } else if Some(c) == child_close_char {
e.goto(TreeCursor::none()); e.goto(TreeCursor::none());
e.cursor.set(ListCursor { e.cursor.set(ListCursor {
mode: ListCursorMode::Select, mode: ListCursorMode::Insert,
idx: Some(cur.idx.unwrap_or(0)) idx: Some(cur.idx.unwrap_or(0)+1)
}); });
TreeNavResult::Continue TreeNavResult::Continue
} else { } else {
@ -174,33 +174,27 @@ impl PTYListController {
match cur.mode { match cur.mode {
ListCursorMode::Insert => { ListCursorMode::Insert => {
eprintln!("PTYList(insert): create new child and forward cmd");
let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth).unwrap(); let mut new_edit = Context::make_node(&e.ctx, e.typ.clone(), self.depth).unwrap();
new_edit.goto(TreeCursor::home()); new_edit.goto(TreeCursor::home());
match new_edit.send_cmd_obj(cmd_obj.clone()) { match new_edit.send_cmd_obj(cmd_obj.clone()) {
TreeNavResult::Continue => { TreeNavResult::Continue => {
eprintln!("PTYList(insert): child returned cont");
e.insert(Arc::new(RwLock::new(new_edit))); e.insert(Arc::new(RwLock::new(new_edit)));
TreeNavResult::Continue TreeNavResult::Continue
} }
TreeNavResult::Exit => { TreeNavResult::Exit => {
eprintln!("PTYList(insert): child returned exit");
TreeNavResult::Exit TreeNavResult::Exit
} }
} }
}, },
ListCursorMode::Select => { ListCursorMode::Select => {
if let Some(item) = e.get_item_mut() { if let Some(item) = e.get_item_mut() {
eprintln!("PTYList(select): forward any cmd to current child item");
let res = item.write().unwrap().send_cmd_obj(cmd_obj.clone()); let res = item.write().unwrap().send_cmd_obj(cmd_obj.clone());
let child_close_char = item.read().unwrap().close_char.get(); let child_close_char = item.read().unwrap().close_char.get();
eprintln!("PTYList(select): child returned");
match res { match res {
TreeNavResult::Continue => TreeNavResult::Continue, TreeNavResult::Continue => TreeNavResult::Continue,
TreeNavResult::Exit => { TreeNavResult::Exit => {
eprintln!("...returned with exit");
// child editor returned control, probably for meta-char handling.. // child editor returned control, probably for meta-char handling..
if cmd_obj.read().unwrap().get_type().clone() == ctx.type_term_from_str("( Char )").unwrap() { if cmd_obj.read().unwrap().get_type().clone() == ctx.type_term_from_str("( Char )").unwrap() {

View file

@ -39,6 +39,8 @@ pub struct TypeTermEditor {
Option< Arc<dyn Any + Send + Sync> > Option< Arc<dyn Any + Send + Sync> >
>, >,
close_char: SingletonBuffer<Option<char>>,
state: State, state: State,
cur_node: SingletonBuffer< NestedNode > cur_node: SingletonBuffer< NestedNode >
} }
@ -56,7 +58,7 @@ impl TypeTermEditor {
TypeID::Var(_) => State::VarSymbol TypeID::Var(_) => State::VarSymbol
}); });
let typename = ctx.read().unwrap().get_typename(&tyid).unwrap_or("UNKNOWN TYPE".into()); let typename = ctx.read().unwrap().get_typename(&tyid).unwrap_or("UNNAMED TYPE".into());
for x in typename.chars() for x in typename.chars()
{ {
node.send_cmd_obj( node.send_cmd_obj(
@ -69,10 +71,11 @@ impl TypeTermEditor {
let editor = node.get_edit::<TypeTermEditor>().expect("typ term edit"); let editor = node.get_edit::<TypeTermEditor>().expect("typ term edit");
editor.write().unwrap().set_state( State::App ); editor.write().unwrap().set_state( State::App );
for x in args.iter() { let parent_ctx = editor.read().unwrap().cur_node.get().ctx.clone();
let arg_node = TypeTermEditor::from_type_term( ctx.clone(), depth+1, x );
for x in args.iter() {
let arg_node = TypeTermEditor::from_type_term( parent_ctx.clone(), depth+1, x );
eprintln!("add node arg!");
node.send_cmd_obj( node.send_cmd_obj(
ReprTree::new_leaf( ReprTree::new_leaf(
(&ctx, "( NestedNode )"), (&ctx, "( NestedNode )"),
@ -86,10 +89,11 @@ impl TypeTermEditor {
let editor = node.get_edit::<TypeTermEditor>().expect("typ term edit"); let editor = node.get_edit::<TypeTermEditor>().expect("typ term edit");
editor.write().unwrap().set_state( State::Ladder ); editor.write().unwrap().set_state( State::Ladder );
for x in args.iter() { let parent_ctx = editor.read().unwrap().cur_node.get().ctx.clone();
let arg_node = TypeTermEditor::from_type_term( ctx.clone(), depth+1, x );
for x in args.iter() {
let arg_node = TypeTermEditor::from_type_term( parent_ctx.clone(), depth+1, x );
eprintln!("add node arg!");
node.send_cmd_obj( node.send_cmd_obj(
ReprTree::new_leaf( ReprTree::new_leaf(
(&ctx, "( NestedNode )"), (&ctx, "( NestedNode )"),
@ -102,7 +106,9 @@ impl TypeTermEditor {
TypeTerm::Num( n ) => { TypeTerm::Num( n ) => {
let editor = node.get_edit::<TypeTermEditor>().expect("typ term edit"); let editor = node.get_edit::<TypeTermEditor>().expect("typ term edit");
let int_edit = crate::editors::integer::PosIntEditor::from_u64(node.ctx.clone(), 10, *n as u64); let parent_ctx = editor.read().unwrap().cur_node.get().ctx.clone();
let int_edit = crate::editors::integer::PosIntEditor::from_u64(parent_ctx, 10, *n as u64);
let node = int_edit.into_node(); let node = int_edit.into_node();
editor.write().unwrap().editor.set(node.editor.get()); editor.write().unwrap().editor.set(node.editor.get());
@ -126,6 +132,7 @@ impl TypeTermEditor {
fn set_state(&mut self, new_state: State) { fn set_state(&mut self, new_state: 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::App => { State::App => {
let mut node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap(); let mut node = Context::make_node( &self.ctx, (&self.ctx, "( List Type )").into(), 0 ).unwrap();
@ -155,7 +162,6 @@ impl TypeTermEditor {
State::Num => { State::Num => {
let int_edit = crate::editors::integer::PosIntEditor::new(self.ctx.clone(), 10); let int_edit = crate::editors::integer::PosIntEditor::new(self.ctx.clone(), 10);
let mut node = int_edit.into_node(); let mut node = int_edit.into_node();
node = node.morph( (&self.ctx, "( Type::Lit::Num )").into() ); node = node.morph( (&self.ctx, "( Type::Lit::Num )").into() );
node node
} }
@ -172,11 +178,11 @@ impl TypeTermEditor {
node.goto(TreeCursor::home()); node.goto(TreeCursor::home());
let editor = node.editor.get(); let editor = node.editor.get();
eprintln!("set_state:editor = {:?}", Arc::into_raw(editor.clone().unwrap()));
self.editor.set(editor); self.editor.set(editor);
self.cur_node.set(node); self.close_char.set(node.close_char.get());
self.cur_node.set(node);
self.state = new_state; self.state = new_state;
} }
@ -204,7 +210,8 @@ impl TypeTermEditor {
state, state,
data: data.clone(), data: data.clone(),
cur_node: SingletonBuffer::new(node), cur_node: SingletonBuffer::new(node),
editor: SingletonBuffer::new(None) editor: SingletonBuffer::new(None),
close_char: SingletonBuffer::new(None)
}; };
let view = editor.cur_node let view = editor.cur_node
@ -233,7 +240,7 @@ impl TypeTermEditor {
.set_cmd(editor.clone()) .set_cmd(editor.clone())
.set_editor(editor.clone()); .set_editor(editor.clone());
node.close_char.set(cc.get()); editor.write().unwrap().close_char = node.close_char.clone();
editor.write().unwrap().editor = node.editor.clone(); editor.write().unwrap().editor = node.editor.clone();
node node
@ -358,8 +365,7 @@ impl ObjCommander for TypeTermEditor {
} }
} }
// State::App | State::AnySymbol | State::FunSymbol | State::VarSymbol _ => {
_ => {
match self.cur_node.get_mut().send_cmd_obj( co ) { match self.cur_node.get_mut().send_cmd_obj( co ) {
TreeNavResult::Exit => { TreeNavResult::Exit => {
match c { match c {
@ -392,7 +398,7 @@ impl ObjCommander for TypeTermEditor {
} else { } else {
match &self.state { match &self.state {
State::Any => { State::Any => {
eprintln!("undefined comd object set to listl"); eprintln!("undefined comd object set to ladder");
self.set_state( State::Ladder ); self.set_state( State::Ladder );
self.cur_node.get_mut().goto(TreeCursor::home()); self.cur_node.get_mut().goto(TreeCursor::home());
let res = self.cur_node.get().cmd.get().unwrap().write().unwrap().send_cmd_obj( co ); let res = self.cur_node.get().cmd.get().unwrap().write().unwrap().send_cmd_obj( co );