From fef4b930ae209787f5b1b4475f488bb215eebeb6 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 16 Aug 2021 00:10:25 +0200 Subject: [PATCH] TreeNav: get tree address of cursor --- nested/src/list/editor.rs | 18 +++++++++++++++++- nested/src/tree_nav.rs | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nested/src/list/editor.rs b/nested/src/list/editor.rs index f118b17..7b2f98a 100644 --- a/nested/src/list/editor.rs +++ b/nested/src/list/editor.rs @@ -61,13 +61,29 @@ where SubEditor: TerminalEditor + ?Sized + Send + Sync + 'static, make_item_editor: FnMakeItemEditor, level: usize, segment_seq: OuterViewPort>, -} + terminal_view: OuterViewPort +} impl TreeNav for ListEditor where SubEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static, FnMakeItemEditor: Fn() -> Arc> { + fn get_cursor(&self) -> Option> { + match self.cursor.get() { + ListEditorCursor::None => None, + ListEditorCursor::Insert(idx) => Some(vec![ idx ]), + ListEditorCursor::Select(idx) => Some(vec![ idx ]), + ListEditorCursor::Edit(idx) => match self.data.get(idx).read().unwrap().get_cursor() { + Some(mut addr) => { + addr.insert(0, idx); + Some(addr) + } + None => Some(vec![ idx ]) + }, + } + } + fn up(&mut self) -> TreeNavResult { match self.cursor.get() { ListEditorCursor::Edit(idx) => { diff --git a/nested/src/tree_nav.rs b/nested/src/tree_nav.rs index a9174a0..c60054d 100644 --- a/nested/src/tree_nav.rs +++ b/nested/src/tree_nav.rs @@ -29,10 +29,14 @@ pub trait TreeNav { fn goto_end(&mut self) -> TreeNavResult { TreeNavResult::Exit } - + fn goto(&mut self, tree_addr: Vec) -> TreeNavResult { TreeNavResult::Exit } + + fn get_cursor(&self) -> Option> { + None + } } use crate::terminal::{TerminalView, TerminalEditor};