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" version = "0.1.0"
[dependencies] [dependencies]
r3vi = { git = "https://git.exobiont.de/senvas/r3vi.git" } #r3vi = { git = "https://git.exobiont.de/senvas/r3vi.git" }
r3vi = { path = "../../r3vi" }
no_deadlocks = "*" no_deadlocks = "*"
cgmath = { version = "0.18.0", features = ["serde"] } cgmath = { version = "0.18.0", features = ["serde"] }
termion = "1.5.5" termion = "1.5.5"

View file

@ -91,7 +91,7 @@ impl CharEditor {
.map(move |c| { .map(move |c| {
match c { match c {
Some(c) => TerminalAtom::from(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() .to_grid()

View file

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

View file

@ -144,43 +144,46 @@ impl PTYListEditor {
let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap(); let head = head_editor.downcast::<RwLock<ListEditor>>().unwrap();
let mut head = head.write().unwrap(); let mut head = head.write().unwrap();
if cur.tree_addr.len() > 2 { if head.data.len() > 0 {
PTYListEditor::split(&mut head);
}
let mut tail = head.split(); if cur.tree_addr.len() > 2 {
PTYListEditor::split(&mut head);
head.goto(TreeCursor::none());
tail.cursor.set(
ListCursor {
idx: Some(0),
mode: if cur.tree_addr.len() > 2 {
ListCursorMode::Select
} else {
ListCursorMode::Insert
}
} }
);
let item_type = let mut tail = head.split();
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); head.goto(TreeCursor::none());
tail_node = tail_node.set_ctx(item.ctx.clone().unwrap());
if let Some(item_type) = item_type { tail.cursor.set(
tail_node = tail_node.morph(item_type); 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 id: _, args
} => { } => {
if args.len() > 0 { if args.len() > 0 {
let editor = PTYListEditor::new( let editor = PTYListEditor::new(
ctx, ctx,
args[0].clone(), args[0].clone(),
Some(','), Some(','),
depth + 1 depth + 1
); );
let view = editor.pty_view(("{",", ", "}"));
let view = editor.pty_view(
(
"{".into(),
", ".into(),
"}".into()
)
);
Some(editor Some(editor
.into_node() .into_node()