From aafc9235ab90be71eebbacb5191ad16791882b3e Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Tue, 21 Feb 2023 15:17:24 +0100 Subject: [PATCH] list editor: avoid empty lists when splitting at multiple levels adds compatibility to load shell pipeline from file --- nested/Cargo.toml | 3 +- nested/src/editors/char/mod.rs | 2 +- nested/src/editors/list/editor.rs | 20 +++------ nested/src/editors/list/pty_editor.rs | 65 ++++++++++++++------------- nested/src/type_system/make_editor.rs | 10 +---- 5 files changed, 43 insertions(+), 57 deletions(-) diff --git a/nested/Cargo.toml b/nested/Cargo.toml index 90d6432..6793380 100644 --- a/nested/Cargo.toml +++ b/nested/Cargo.toml @@ -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" diff --git a/nested/src/editors/char/mod.rs b/nested/src/editors/char/mod.rs index e77175a..a533dd4 100644 --- a/nested/src/editors/char/mod.rs +++ b/nested/src/editors/char/mod.rs @@ -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() diff --git a/nested/src/editors/list/editor.rs b/nested/src/editors/list/editor.rs index 1c27977..c566e31 100644 --- a/nested/src/editors/list/editor.rs +++ b/nested/src/editors/list/editor.rs @@ -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::>().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::>>(vec![].into_iter())?.get()).count() == 0 { drop(prev_editor); self.data.remove(prev_idx); diff --git a/nested/src/editors/list/pty_editor.rs b/nested/src/editors/list/pty_editor.rs index 8a21fe2..839ae81 100644 --- a/nested/src/editors/list/pty_editor.rs +++ b/nested/src/editors/list/pty_editor.rs @@ -144,43 +144,46 @@ impl PTYListEditor { let head = head_editor.downcast::>().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 - ); } } } diff --git a/nested/src/type_system/make_editor.rs b/nested/src/type_system/make_editor.rs index dda3555..a8cb1f8 100644 --- a/nested/src/type_system/make_editor.rs +++ b/nested/src/type_system/make_editor.rs @@ -73,21 +73,13 @@ pub fn init_editor_ctx(parent: Arc>) -> Arc> { 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()