list editor: add some bounds checks and debug messages
This commit is contained in:
parent
120d0e1df0
commit
10bff8a32c
5 changed files with 40 additions and 7 deletions
|
@ -58,6 +58,8 @@ impl ObjCommander for ListEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
else if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
|
else if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
|
||||||
|
eprintln!("pty-list-editor some list cmmd");
|
||||||
|
|
||||||
let cur = self.cursor.get();
|
let cur = self.cursor.get();
|
||||||
drop(cmd_repr);
|
drop(cmd_repr);
|
||||||
|
|
||||||
|
@ -125,6 +127,7 @@ impl ObjCommander for ListEditor {
|
||||||
ListCursorMode::Insert => {
|
ListCursorMode::Insert => {
|
||||||
match cmd.get() {
|
match cmd.get() {
|
||||||
ListCmd::DeletePxev => {
|
ListCmd::DeletePxev => {
|
||||||
|
eprintln!("INSERT: delete pxev");
|
||||||
self.delete_pxev();
|
self.delete_pxev();
|
||||||
TreeNavResult::Continue
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
|
@ -147,6 +150,7 @@ impl ObjCommander for ListEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
eprintln!("ptylist: cursor has no idx");
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,6 +194,7 @@ impl ListEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// is the element-type also a list-like editor (i.e. impls TreeNav)
|
||||||
pub fn is_listlist(&self) -> bool {
|
pub fn is_listlist(&self) -> bool {
|
||||||
self.ctx.read().unwrap().is_list_type(&self.typ)
|
self.ctx.read().unwrap().is_list_type(&self.typ)
|
||||||
}
|
}
|
||||||
|
@ -233,6 +234,7 @@ impl ListEditor {
|
||||||
/// insert a new element
|
/// insert a new element
|
||||||
pub fn insert(&mut self, item: Arc<RwLock<NestedNode>>) {
|
pub fn insert(&mut self, item: Arc<RwLock<NestedNode>>) {
|
||||||
eprintln!("list insert");
|
eprintln!("list insert");
|
||||||
|
|
||||||
item.read().unwrap().depth.0.set_view(
|
item.read().unwrap().depth.0.set_view(
|
||||||
self.depth.map(|d| d+1).get_view()
|
self.depth.map(|d| d+1).get_view()
|
||||||
);
|
);
|
||||||
|
@ -277,6 +279,27 @@ impl ListEditor {
|
||||||
);
|
);
|
||||||
self.data.remove(idx);
|
self.data.remove(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* in case the split leaves an empty item-list
|
||||||
|
* as a last element, remove it
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
if self.is_listlist() {
|
||||||
|
if idx > 0 && idx < self.data.len()+1 {
|
||||||
|
/* we are in insert mode,
|
||||||
|
* get element before cursor
|
||||||
|
*/
|
||||||
|
let prev_idx = idx - 1;
|
||||||
|
let prev_node = self.data.get(prev_idx);
|
||||||
|
let prev_node = prev_node.read().unwrap();
|
||||||
|
|
||||||
|
if prev_node.get_data_view::<dyn SequenceView<Item = NestedNode>>(vec![].into_iter()).iter().count() == 0 {
|
||||||
|
drop(prev_node);
|
||||||
|
self.data.remove(prev_idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +337,7 @@ impl ListEditor {
|
||||||
drop(item);
|
drop(item);
|
||||||
|
|
||||||
tail_node.goto(TreeCursor::home());
|
tail_node.goto(TreeCursor::home());
|
||||||
if cur.tree_addr.len() > 2 {
|
if cur.tree_addr.len() > 1 {
|
||||||
tail_node.dn();
|
tail_node.dn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,13 +387,15 @@ impl ListEditor {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// fixme: is it oc0 or old_cur ??
|
||||||
if oc0.tree_addr.len() > 1 {
|
if oc0.tree_addr.len() > 1 {
|
||||||
pxv_editor.goto(TreeCursor {
|
pxv_editor.goto(TreeCursor {
|
||||||
tree_addr: vec![ old_cur.tree_addr[0], 0 ],
|
tree_addr: vec![ old_cur.tree_addr[0], 0 ],
|
||||||
leaf_mode: ListCursorMode::Insert
|
leaf_mode: ListCursorMode::Insert
|
||||||
});
|
});
|
||||||
pxv_editor.send_cmd_obj(ListCmd::DeletePxev.into_repr_tree( &self.ctx ));
|
pxv_editor.send_cmd_obj(ListCmd::DeletePxev.into_repr_tree( &self.ctx ));
|
||||||
} else {
|
} else if oc0.tree_addr.len() > 0 {
|
||||||
pxv_editor.goto(TreeCursor {
|
pxv_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
|
||||||
|
@ -421,17 +446,20 @@ impl ListEditor {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fixme: is it oc0 or old_cur ??
|
||||||
if oc0.tree_addr.len() > 1 {
|
if oc0.tree_addr.len() > 1 {
|
||||||
cur_editor.goto(TreeCursor {
|
cur_editor.goto(TreeCursor {
|
||||||
tree_addr: vec![ old_cur.tree_addr[0], -1 ],
|
tree_addr: vec![ old_cur.tree_addr[0], -1 ],
|
||||||
leaf_mode: ListCursorMode::Insert
|
leaf_mode: ListCursorMode::Insert
|
||||||
});
|
});
|
||||||
cur_editor.send_cmd_obj(ListCmd::DeleteNexd.into_repr_tree( &self.ctx ));
|
cur_editor.send_cmd_obj(ListCmd::DeleteNexd.into_repr_tree( &self.ctx ));
|
||||||
} else {
|
} else if oc0.tree_addr.len() > 0 {
|
||||||
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
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
cur_editor.goto(TreeCursor::none());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,7 @@ impl TreeNav for ListEditor {
|
||||||
TreeNavResult::Exit
|
TreeNavResult::Exit
|
||||||
} else if direction.y > 0 {
|
} else if direction.y > 0 {
|
||||||
// dn
|
// dn
|
||||||
|
eprintln!("dn: data.len() = {}", self.data.len());
|
||||||
self.cursor.set(ListCursor {
|
self.cursor.set(ListCursor {
|
||||||
mode: if self.data.len() > 0 { cur.leaf_mode } else { ListCursorMode::Insert },
|
mode: if self.data.len() > 0 { cur.leaf_mode } else { ListCursorMode::Insert },
|
||||||
idx: Some(0)
|
idx: Some(0)
|
||||||
|
@ -210,18 +211,18 @@ impl TreeNav for ListEditor {
|
||||||
1 => {
|
1 => {
|
||||||
if direction.y > 0 {
|
if direction.y > 0 {
|
||||||
// dn
|
// dn
|
||||||
|
|
||||||
if cur.tree_addr[0] < self.data.len() as isize {
|
if cur.tree_addr[0] < self.data.len() as isize {
|
||||||
if self.data
|
if self.data
|
||||||
.get_mut(cur.tree_addr[0] as usize)
|
.get_mut(cur.tree_addr[0] as usize)
|
||||||
.write().unwrap()
|
.write().unwrap()
|
||||||
.goby(Vector2::new(direction.x, direction.y))
|
.goby(Vector2::new(direction.x, direction.y))
|
||||||
== TreeNavResult::Continue {
|
== TreeNavResult::Continue {
|
||||||
let res = self.cursor.set(ListCursor {
|
self.cursor.set(ListCursor {
|
||||||
mode: ListCursorMode::Select,
|
mode: ListCursorMode::Select,
|
||||||
idx: Some(cur.tree_addr[0])
|
idx: Some(cur.tree_addr[0])
|
||||||
});
|
});
|
||||||
self.set_leaf_mode(cur.leaf_mode);
|
self.set_leaf_mode(cur.leaf_mode);
|
||||||
res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ impl PTYListController {
|
||||||
|
|
||||||
match new_edit.send_cmd_obj(cmd_obj.clone()) {
|
match new_edit.send_cmd_obj(cmd_obj.clone()) {
|
||||||
TreeNavResult::Continue => {
|
TreeNavResult::Continue => {
|
||||||
e.insert(Arc::new(RwLock::new(new_edit)));
|
e.insert(Arc::new(RwLock::new(new_edit.clone())));
|
||||||
TreeNavResult::Continue
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
TreeNavResult::Exit => {
|
TreeNavResult::Exit => {
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub struct TypeTermEditor {
|
||||||
depth: OuterViewPort<dyn SingletonView<Item = usize>>,
|
depth: OuterViewPort<dyn SingletonView<Item = usize>>,
|
||||||
|
|
||||||
buf: SingletonBuffer< TypeTerm >,
|
buf: SingletonBuffer< TypeTerm >,
|
||||||
|
|
||||||
// editing/parsing state
|
// editing/parsing state
|
||||||
state: State,
|
state: State,
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue