From 120d0e1df069495157cf496f7209f6435d746e39 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Fri, 15 Sep 2023 15:15:59 +0200 Subject: [PATCH] context: fix is_list_type for App&Ladder types; properly reset cursor when remaining in same height after insert --- nested/src/editors/list/cmd.rs | 86 +++++++++++++-------------- nested/src/editors/list/editor.rs | 4 +- nested/src/editors/list/pty_editor.rs | 2 + nested/src/type_system/context.rs | 12 ++++ 4 files changed, 59 insertions(+), 45 deletions(-) diff --git a/nested/src/editors/list/cmd.rs b/nested/src/editors/list/cmd.rs index 1cf3c8e..6c10b30 100644 --- a/nested/src/editors/list/cmd.rs +++ b/nested/src/editors/list/cmd.rs @@ -71,55 +71,53 @@ impl ObjCommander for ListEditor { match cur.mode { ListCursorMode::Select => { if let Some(mut item) = self.get_item().clone() { - if self.is_listlist() { - let item_cur = item.get_cursor(); - - match cmd.get() { - ListCmd::DeletePxev => { - if idx > 0 - && item_cur.tree_addr.iter().fold( - true, - |is_zero, x| is_zero && (*x == 0) - ) - { - self.listlist_join_pxev(idx); - TreeNavResult::Continue - } else { - item.send_cmd_obj(cmd_obj) - } - } - - ListCmd::DeleteNexd => { - let item_cur = item.get_cursor_warp(); - let next_idx = idx as usize + 1; - - if next_idx < self.data.len() - && item_cur.tree_addr.iter().fold( - true, - |is_end, x| is_end && (*x == -1) - ) - { - self.listlist_join_nexd(idx as usize); - TreeNavResult::Continue - } else { - item.send_cmd_obj(cmd_obj) - } - } - - ListCmd::Split => { - self.listlist_split(); - TreeNavResult::Continue - } - - _ => { - item.send_cmd_obj(cmd_obj); + let item_cur = item.get_cursor(); + + match cmd.get() { + ListCmd::DeletePxev => { + eprintln!("SELECT: delete pxev"); + if idx > 0 + && item_cur.tree_addr.iter().fold( + true, + |is_zero, x| is_zero && (*x == 0) + ) + { + self.listlist_join_pxev(idx); TreeNavResult::Continue + } else { + item.send_cmd_obj(cmd_obj) } } - } else { - TreeNavResult::Exit + + ListCmd::DeleteNexd => { + let item_cur = item.get_cursor_warp(); + let next_idx = idx as usize + 1; + + if next_idx < self.data.len() + && item_cur.tree_addr.iter().fold( + true, + |is_end, x| is_end && (*x == -1) + ) + { + self.listlist_join_nexd(idx as usize); + TreeNavResult::Continue + } else { + item.send_cmd_obj(cmd_obj) + } + } + + ListCmd::Split => { + self.listlist_split(); + TreeNavResult::Continue + } + + _ => { + item.send_cmd_obj(cmd_obj); + TreeNavResult::Continue + } } } else { + eprintln!("ptylist: no item"); TreeNavResult::Exit } }, diff --git a/nested/src/editors/list/editor.rs b/nested/src/editors/list/editor.rs index a926605..7875864 100644 --- a/nested/src/editors/list/editor.rs +++ b/nested/src/editors/list/editor.rs @@ -245,7 +245,9 @@ impl ListEditor { if self.is_listlist() { cur.mode = ListCursorMode::Select; } else { - cur.idx = Some(idx + 1); + eprintln!("list insert: is not a listlist ({:?})", self.typ); + item.write().unwrap().goto(TreeCursor::none()); + cur.idx = Some(idx + 1); } } diff --git a/nested/src/editors/list/pty_editor.rs b/nested/src/editors/list/pty_editor.rs index 8238a93..ccb5812 100644 --- a/nested/src/editors/list/pty_editor.rs +++ b/nested/src/editors/list/pty_editor.rs @@ -65,6 +65,8 @@ impl PTYListStyle { //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> +// todo: rename to CharController + pub struct PTYListController { pub editor: Arc>, diff --git a/nested/src/type_system/context.rs b/nested/src/type_system/context.rs index 7904994..41df4a5 100644 --- a/nested/src/type_system/context.rs +++ b/nested/src/type_system/context.rs @@ -196,6 +196,18 @@ impl Context { TypeTerm::TypeID(id) => { self.list_types.contains(id) } + TypeTerm::Ladder(args) | + TypeTerm::App(args) => { + if args.len() > 0 { + if self.is_list_type(&args[0]) { + true + } else { + false + } + } else { + false + } + } _ => false } }