context: fix is_list_type for App&Ladder types; properly reset cursor when remaining in same height after insert

This commit is contained in:
Michael Sippel 2023-09-15 15:15:59 +02:00
parent 119105c6a2
commit 120d0e1df0
Signed by: senvas
GPG key ID: F96CF119C34B64A6
4 changed files with 59 additions and 45 deletions

View file

@ -71,55 +71,53 @@ impl ObjCommander for ListEditor {
match cur.mode { match cur.mode {
ListCursorMode::Select => { ListCursorMode::Select => {
if let Some(mut item) = self.get_item().clone() { if let Some(mut item) = self.get_item().clone() {
if self.is_listlist() { let item_cur = item.get_cursor();
let item_cur = item.get_cursor();
match cmd.get() { match cmd.get() {
ListCmd::DeletePxev => { ListCmd::DeletePxev => {
if idx > 0 eprintln!("SELECT: delete pxev");
&& item_cur.tree_addr.iter().fold( if idx > 0
true, && item_cur.tree_addr.iter().fold(
|is_zero, x| is_zero && (*x == 0) true,
) |is_zero, x| is_zero && (*x == 0)
{ )
self.listlist_join_pxev(idx); {
TreeNavResult::Continue self.listlist_join_pxev(idx);
} 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);
TreeNavResult::Continue 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 { } else {
eprintln!("ptylist: no item");
TreeNavResult::Exit TreeNavResult::Exit
} }
}, },

View file

@ -245,6 +245,8 @@ impl ListEditor {
if self.is_listlist() { if self.is_listlist() {
cur.mode = ListCursorMode::Select; cur.mode = ListCursorMode::Select;
} else { } else {
eprintln!("list insert: is not a listlist ({:?})", self.typ);
item.write().unwrap().goto(TreeCursor::none());
cur.idx = Some(idx + 1); cur.idx = Some(idx + 1);
} }
} }

View file

@ -65,6 +65,8 @@ impl PTYListStyle {
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
// todo: rename to CharController
pub struct PTYListController { pub struct PTYListController {
pub editor: Arc<RwLock<ListEditor>>, pub editor: Arc<RwLock<ListEditor>>,

View file

@ -196,6 +196,18 @@ impl Context {
TypeTerm::TypeID(id) => { TypeTerm::TypeID(id) => {
self.list_types.contains(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 _ => false
} }
} }