list editor: avoid empty lists when splitting at multiple levels

adds compatibility to load shell pipeline from file
This commit is contained in:
Michael Sippel 2023-02-21 15:17:24 +01:00
parent c2a9d8e3bd
commit aafc9235ab
Signed by: senvas
GPG key ID: F96CF119C34B64A6
5 changed files with 43 additions and 57 deletions

View file

@ -5,7 +5,8 @@ name = "nested"
version = "0.1.0"
[dependencies]
r3vi = { git = "https://git.exobiont.de/senvas/r3vi.git" }
#r3vi = { git = "https://git.exobiont.de/senvas/r3vi.git" }
r3vi = { path = "../../r3vi" }
no_deadlocks = "*"
cgmath = { version = "0.18.0", features = ["serde"] }
termion = "1.5.5"

View file

@ -91,7 +91,7 @@ impl CharEditor {
.map(move |c| {
match c {
Some(c) => TerminalAtom::from(c),
None => TerminalAtom::new('*', TerminalStyle::fg_color((255,0,0)))
None => TerminalAtom::new(' ', TerminalStyle::bg_color((255,0,0)))
}
})
.to_grid()

View file

@ -250,26 +250,16 @@ impl ListEditor {
}
if self.is_listlist() {
if idx > 0 && idx < self.data.len() {
let prev_idx = idx - 1;
if idx > 0 && idx < self.data.len()+1 {
let prev_idx = idx - 1; // we are in insert mode, last element before cursor
let prev_node = self.data.get(prev_idx);
if let Some(prev_editor) = prev_node.editor.clone() {
eprintln!("prev prev editor");
let mut prev_editor = prev_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut prev_editor = prev_editor.write().unwrap();
if prev_editor.get_data_port().get_view().unwrap()
.iter().filter(
|x|
/*
if let Some(data) = x.data.clone() {
let data = data.;
data.read().unwrap().is_some()
} else {
false
}
*/ true
).count() == 0
if prev_editor.get_data_port().get_view().unwrap().iter()
.filter_map(|x| x.get_data_view::<dyn SingletonView<Item = Option<char>>>(vec![].into_iter())?.get()).count() == 0
{
drop(prev_editor);
self.data.remove(prev_idx);

View file

@ -144,43 +144,46 @@ impl PTYListEditor {
let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut head = head.write().unwrap();
if cur.tree_addr.len() > 2 {
PTYListEditor::split(&mut head);
}
if head.data.len() > 0 {
let mut tail = head.split();
head.goto(TreeCursor::none());
tail.cursor.set(
ListCursor {
idx: Some(0),
mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select
} else {
ListCursorMode::Insert
}
if cur.tree_addr.len() > 2 {
PTYListEditor::split(&mut head);
}
);
let item_type =
if let Some(data) = item.data.clone() {
let data = data.read().unwrap();
Some(data.get_type().clone())
} else {
None
};
let mut tail = head.split();
let mut tail_node = tail.into_node(depth);
tail_node = tail_node.set_ctx(item.ctx.clone().unwrap());
head.goto(TreeCursor::none());
if let Some(item_type) = item_type {
tail_node = tail_node.morph(item_type);
tail.cursor.set(
ListCursor {
idx: Some(0),
mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select
} else {
ListCursorMode::Insert
}
}
);
let item_type =
if let Some(data) = item.data.clone() {
let data = data.read().unwrap();
Some(data.get_type().clone())
} else {
None
};
let mut tail_node = tail.into_node(depth);
tail_node = tail_node.set_ctx(item.ctx.clone().unwrap());
if let Some(item_type) = item_type {
tail_node = tail_node.morph(item_type);
}
e.insert(
tail_node
);
}
e.insert(
tail_node
);
}
}
}

View file

@ -73,21 +73,13 @@ pub fn init_editor_ctx(parent: Arc<RwLock<Context>>) -> Arc<RwLock<Context>> {
id: _, args
} => {
if args.len() > 0 {
let editor = PTYListEditor::new(
ctx,
args[0].clone(),
Some(','),
depth + 1
);
let view = editor.pty_view(
(
"{".into(),
", ".into(),
"}".into()
)
);
let view = editor.pty_view(("{",", ", "}"));
Some(editor
.into_node()