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 {
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
}
},

View file

@ -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);
}
}

View file

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

View file

@ -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
}
}