product editor: fix background color highlighting
introduce update_segment() to simplify updating of meta information of segments
This commit is contained in:
parent
507887535f
commit
21f7043ef0
11 changed files with 449 additions and 257 deletions
|
@ -42,9 +42,8 @@ impl TerminalEditor for CharEditor {
|
|||
self.data
|
||||
.get_port()
|
||||
.map(move |c| {
|
||||
TerminalAtom::new(
|
||||
c.unwrap_or('?'),
|
||||
TerminalStyle::fg_color((100, 140, 100)),
|
||||
TerminalAtom::from(
|
||||
c.unwrap_or('?')
|
||||
)
|
||||
})
|
||||
.to_grid()
|
||||
|
|
|
@ -4,22 +4,19 @@ use {
|
|||
|
||||
pub fn bg_style_from_depth(depth: usize) -> TerminalStyle {
|
||||
match depth {
|
||||
0 => TerminalStyle::default(),
|
||||
1 => TerminalStyle::bg_color((20,20,20)),
|
||||
2 => TerminalStyle::default(),
|
||||
3 => TerminalStyle::default(),
|
||||
4 => TerminalStyle::default(),
|
||||
5 => TerminalStyle::default(),
|
||||
_ => TerminalStyle::bg_color((80,80,80))
|
||||
1 => TerminalStyle::bg_color((40,40,40)),
|
||||
_ => TerminalStyle::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fg_style_from_depth(depth: usize) -> TerminalStyle {
|
||||
match depth % 3 {
|
||||
0 => TerminalStyle::fg_color((200, 200, 80)),
|
||||
1 => TerminalStyle::fg_color((80, 200, 200)).add(TerminalStyle::bold(true)),
|
||||
2 => TerminalStyle::fg_color((80, 80, 200)),
|
||||
3 => TerminalStyle::fg_color((200, 80, 200)),
|
||||
match depth % 6 {
|
||||
0 => TerminalStyle::fg_color((40, 180, 230)),
|
||||
1 => TerminalStyle::fg_color((120, 120, 120)),
|
||||
2 => TerminalStyle::fg_color((230, 180, 40)),
|
||||
3 => TerminalStyle::fg_color((80, 180, 200)),
|
||||
4 => TerminalStyle::fg_color((70, 90, 180)),
|
||||
5 => TerminalStyle::fg_color((200, 190, 70)),
|
||||
_ => TerminalStyle::default()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,11 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
let mut sub_cur = self.data.get(i as usize).read().unwrap().get_cursor_warp();
|
||||
sub_cur.tree_addr.insert(0, i as isize - self.data.len() as isize);
|
||||
return sub_cur;
|
||||
} else {
|
||||
return TreeCursor {
|
||||
leaf_mode: ListCursorMode::Select,
|
||||
tree_addr: vec![ i as isize - self.data.len() as isize ],
|
||||
};
|
||||
}
|
||||
}
|
||||
TreeCursor {
|
||||
|
@ -68,12 +73,19 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
if let Some(i) = cur.idx {
|
||||
if i < self.data.len() as isize {
|
||||
let mut sub_cur = self.data.get(i as usize).read().unwrap().get_cursor();
|
||||
sub_cur.tree_addr.insert(0, i as isize);
|
||||
return sub_cur;
|
||||
if sub_cur.tree_addr.len() > 0 {
|
||||
sub_cur.tree_addr.insert(0, i as isize);
|
||||
return sub_cur;
|
||||
} else {
|
||||
return TreeCursor {
|
||||
leaf_mode: ListCursorMode::Select,
|
||||
tree_addr: vec![ i ],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
TreeCursor {
|
||||
leaf_mode: cur.mode,
|
||||
leaf_mode: ListCursorMode::Select,
|
||||
tree_addr: vec![],
|
||||
}
|
||||
}
|
||||
|
@ -99,10 +111,22 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
TreeNavResult::Continue
|
||||
}
|
||||
1 => {
|
||||
let idx = crate::modulo(new_cur.tree_addr[0], if new_cur.leaf_mode == ListCursorMode::Insert { 1 } else { 0 } + self.data.len() as isize);
|
||||
|
||||
self.cursor.set(ListCursor {
|
||||
mode: new_cur.leaf_mode,
|
||||
idx: Some(crate::modulo(new_cur.tree_addr[0], if new_cur.leaf_mode == ListCursorMode::Insert { 1 } else { 0 } + self.data.len() as isize)),
|
||||
idx: Some(idx),
|
||||
});
|
||||
|
||||
if new_cur.leaf_mode == ListCursorMode::Select {
|
||||
let item = self.data.get_mut(idx as usize);
|
||||
let mut item_edit = item.write().unwrap();
|
||||
item_edit.goto(TreeCursor {
|
||||
leaf_mode: ListCursorMode::Select,
|
||||
tree_addr: vec![]
|
||||
});
|
||||
}
|
||||
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
_ => {
|
||||
|
@ -116,7 +140,6 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
|
||||
let item = self.data.get_mut(idx as usize);
|
||||
let mut item_edit = item.write().unwrap();
|
||||
|
||||
item_edit.goto(TreeCursor {
|
||||
leaf_mode: new_cur.leaf_mode,
|
||||
tree_addr: new_cur.tree_addr[1..].iter().cloned().collect(),
|
||||
|
@ -137,11 +160,18 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
|
||||
if direction.y < 0 {
|
||||
// up
|
||||
self.cursor.set(ListCursor::none());
|
||||
self.cursor.set(ListCursor {
|
||||
mode: cur.leaf_mode,
|
||||
idx: None
|
||||
});
|
||||
TreeNavResult::Exit
|
||||
} else if direction.y > 0 {
|
||||
// dn
|
||||
self.cursor.set(ListCursor::home());
|
||||
self.cursor.set(ListCursor {
|
||||
mode: if self.data.len() > 0 { cur.leaf_mode } else { ListCursorMode::Insert },
|
||||
idx: Some(0)
|
||||
});
|
||||
|
||||
self.goby(Vector2::new(direction.x, direction.y-1));
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
|
@ -168,8 +198,10 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
|
||||
} else if direction.y < 0 {
|
||||
// up
|
||||
|
||||
self.cursor.set(ListCursor::none());
|
||||
self.cursor.set(ListCursor {
|
||||
mode: cur.leaf_mode,
|
||||
idx: None
|
||||
});
|
||||
TreeNavResult::Exit
|
||||
} else {
|
||||
// horizontal
|
||||
|
@ -179,13 +211,27 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
self.data.len() as isize
|
||||
+ if cur.leaf_mode == ListCursorMode::Insert { 1 } else { 0 })
|
||||
{
|
||||
let idx = cur.tree_addr[0] + direction.x;
|
||||
self.cursor.set(ListCursor {
|
||||
mode: if self.data.len() == 0 { ListCursorMode::Insert } else { cur.leaf_mode },
|
||||
idx: Some(cur.tree_addr[0] + direction.x)
|
||||
idx: Some(idx)
|
||||
});
|
||||
|
||||
if idx < self.data.len() as isize {
|
||||
let item = self.data.get_mut(idx as usize);
|
||||
let mut item_edit = item.write().unwrap();
|
||||
item_edit.goto(TreeCursor {
|
||||
leaf_mode: cur.leaf_mode,
|
||||
tree_addr: vec![]
|
||||
});
|
||||
}
|
||||
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
self.cursor.set(ListCursor::none());
|
||||
self.cursor.set(ListCursor {
|
||||
mode: cur.leaf_mode,
|
||||
idx: None
|
||||
});
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +278,10 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
|
||||
self.goto(cur)
|
||||
} else {
|
||||
self.cursor.set(ListCursor::none());
|
||||
self.cursor.set(ListCursor {
|
||||
mode: cur.leaf_mode,
|
||||
idx: None
|
||||
});
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,16 +36,27 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
ListSegment::InsertCursor => {
|
||||
make_label("|")
|
||||
.map_item(move |_pt, atom| {
|
||||
atom.add_style_back(bg_style_from_depth(0))
|
||||
.add_style_back(TerminalStyle::bold(true))
|
||||
atom.add_style_front(TerminalStyle::fg_color((150,80,230)))
|
||||
.add_style_front(TerminalStyle::bold(true))
|
||||
})
|
||||
}
|
||||
ListSegment::Item{ editor, depth, cur_dist } => {
|
||||
let e = editor.clone();
|
||||
let d = *depth;
|
||||
let cur_dist = *cur_dist;
|
||||
editor.read().unwrap().get_term_view().map_item(move |_pt, atom| {
|
||||
let cur_depth = e.read().unwrap().get_cursor().tree_addr.len();
|
||||
atom.add_style_back(bg_style_from_depth(cur_depth))
|
||||
let c = e.read().unwrap().get_cursor();
|
||||
let cur_depth = c.tree_addr.len();
|
||||
let select =
|
||||
cur_dist == 0 &&
|
||||
if c.leaf_mode == ListCursorMode::Select {
|
||||
cur_depth == 0
|
||||
} else {
|
||||
cur_depth == 1
|
||||
};
|
||||
atom
|
||||
.add_style_back(bg_style_from_depth(if select { 1 } else { 0 }))
|
||||
.add_style_back(TerminalStyle::bold(select))
|
||||
.add_style_back(fg_style_from_depth(d))
|
||||
})
|
||||
}
|
||||
|
@ -110,7 +121,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
ListSegment::Item {
|
||||
editor: self.data.get(&(*idx - 1))?,
|
||||
depth: self.depth,
|
||||
cur_dist: cur - (*idx as isize - 1)
|
||||
cur_dist: cur - *idx as isize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,25 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
)
|
||||
))
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( List String )").unwrap() {
|
||||
Arc::new(RwLock::new(
|
||||
PTYListEditor::new(
|
||||
Box::new({
|
||||
let d = depth + 1;
|
||||
let ctx = ctx.clone();
|
||||
move || {
|
||||
make_editor(
|
||||
ctx.clone(),
|
||||
&vec![ctx.read().unwrap().type_term_from_str("( String )").unwrap()],
|
||||
d
|
||||
)
|
||||
}
|
||||
}),
|
||||
SeqDecorStyle::EnumSet,
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( List Char )").unwrap() {
|
||||
Arc::new(RwLock::new(
|
||||
PTYListEditor::new(
|
||||
|
@ -40,7 +59,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
|| { Arc::new(RwLock::new(CharEditor::new())) }
|
||||
),
|
||||
SeqDecorStyle::Plain,
|
||||
depth
|
||||
depth+1
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
|
@ -56,10 +75,9 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( Path )").unwrap() {
|
||||
let d = depth + 1;
|
||||
Arc::new(RwLock::new(PTYListEditor::new(
|
||||
Box::new({
|
||||
let d= depth +1;
|
||||
let d= depth+1;
|
||||
move || {
|
||||
Arc::new(RwLock::new(PTYListEditor::new(
|
||||
Box::new(|| {
|
||||
|
@ -73,6 +91,25 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
depth
|
||||
))) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( List Path )").unwrap() {
|
||||
Arc::new(RwLock::new(
|
||||
PTYListEditor::new(
|
||||
Box::new({
|
||||
let d = depth + 1;
|
||||
let ctx = ctx.clone();
|
||||
move || {
|
||||
make_editor(
|
||||
ctx.clone(),
|
||||
&vec![ctx.read().unwrap().type_term_from_str("( Path )").unwrap()],
|
||||
d
|
||||
)
|
||||
}
|
||||
}),
|
||||
SeqDecorStyle::EnumSet,
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( List RGB )").unwrap() {
|
||||
Arc::new(RwLock::new(
|
||||
PTYListEditor::<dyn TerminalTreeEditor + Send +Sync>::new(
|
||||
|
|
|
@ -38,7 +38,7 @@ impl ProductEditor {
|
|||
depth
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn with_t(mut self, pos: Point2<i16>, t: &str) -> Self {
|
||||
self.segments.insert(pos, ProductEditorSegment::T(t.to_string(), self.depth));
|
||||
self
|
||||
|
@ -48,7 +48,9 @@ impl ProductEditor {
|
|||
self.segments.insert(pos, ProductEditorSegment::N{
|
||||
t: n,
|
||||
editor: None,
|
||||
cur_depth: 0
|
||||
ed_depth: self.depth + 1,
|
||||
cur_depth: 0,
|
||||
cur_dist: isize::MAX
|
||||
});
|
||||
self.n_indices.push(pos);
|
||||
self
|
||||
|
@ -81,7 +83,7 @@ impl ProductEditor {
|
|||
}
|
||||
|
||||
pub fn get_editor(&self, idx: isize) -> Option<Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>> {
|
||||
if let ProductEditorSegment::N{ t: _, editor, cur_depth: _ } = self.get_editor_segment(idx) {
|
||||
if let ProductEditorSegment::N{ t: _, editor, ed_depth: _, cur_depth: _, cur_dist: _ } = self.get_editor_segment(idx) {
|
||||
editor
|
||||
} else {
|
||||
unreachable!()
|
||||
|
@ -97,6 +99,30 @@ impl ProductEditor {
|
|||
c.leaf_mode = mode;
|
||||
self.goto(c);
|
||||
}
|
||||
|
||||
pub fn update_segment(&mut self, idx: isize) {
|
||||
if let Some(ProductEditorSegment::N{ t: _, editor, ed_depth: _, cur_depth, cur_dist }) = self.get_editor_segment_mut(idx).deref_mut() {
|
||||
let cur = self.get_cursor();
|
||||
|
||||
if cur.tree_addr.len() > 0 {
|
||||
if cur.tree_addr[0] == idx {
|
||||
*cur_depth = cur.tree_addr.len();
|
||||
}
|
||||
|
||||
*cur_dist = cur.tree_addr[0] - idx
|
||||
} else {
|
||||
*cur_dist = isize::MAX;
|
||||
};
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_cur_segment(&mut self) {
|
||||
if let Some(c) = self.cursor {
|
||||
self.update_segment(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TerminalEditor for ProductEditor {
|
||||
|
@ -110,40 +136,41 @@ impl TerminalEditor for ProductEditor {
|
|||
|
||||
fn handle_terminal_event(&mut self, event: &TerminalEvent) -> TerminalEditorResult {
|
||||
if let Some(mut segment) = self.get_cur_segment_mut().as_deref_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = segment.deref_mut() {
|
||||
*cur_depth = self.get_cursor().tree_addr.len();
|
||||
if let Some(e) = editor.clone() {
|
||||
let mut ce = e.write().unwrap();
|
||||
match ce.handle_terminal_event(event) {
|
||||
TerminalEditorResult::Exit =>
|
||||
match event {
|
||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||
*editor = None;
|
||||
*cur_depth = 1;
|
||||
TerminalEditorResult::Continue
|
||||
}
|
||||
_ => {
|
||||
*cur_depth = ce.get_cursor().tree_addr.len();
|
||||
drop(ce);
|
||||
match self.nexd() {
|
||||
TreeNavResult::Continue => TerminalEditorResult::Continue,
|
||||
TreeNavResult::Exit => TerminalEditorResult::Exit
|
||||
if let Some(ProductEditorSegment::N{ t, editor, ed_depth, cur_depth, cur_dist }) = segment.deref_mut() {
|
||||
*cur_depth = self.get_cursor().tree_addr.len();
|
||||
|
||||
if let Some(e) = editor.clone() {
|
||||
let mut ce = e.write().unwrap();
|
||||
match ce.handle_terminal_event(event) {
|
||||
TerminalEditorResult::Exit =>
|
||||
match event {
|
||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||
*editor = None;
|
||||
*cur_depth = 1;
|
||||
TerminalEditorResult::Continue
|
||||
}
|
||||
}
|
||||
},
|
||||
TerminalEditorResult::Continue => {
|
||||
*cur_depth = ce.get_cursor().tree_addr.len();
|
||||
TerminalEditorResult::Continue
|
||||
_ => {
|
||||
*cur_depth = ce.get_cursor().tree_addr.len();
|
||||
drop(ce);
|
||||
match self.nexd() {
|
||||
TreeNavResult::Continue => TerminalEditorResult::Continue,
|
||||
TreeNavResult::Exit => TerminalEditorResult::Exit
|
||||
}
|
||||
}
|
||||
},
|
||||
TerminalEditorResult::Continue => {
|
||||
*cur_depth = ce.get_cursor().tree_addr.len();
|
||||
TerminalEditorResult::Continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let e = make_editor(self.ctx.clone(), t, *ed_depth+1);
|
||||
*editor = Some(e.clone());
|
||||
e.write().unwrap().dn();
|
||||
let x = e.write().unwrap().handle_terminal_event(event);
|
||||
*cur_depth = e.write().unwrap().get_cursor().tree_addr.len();
|
||||
x
|
||||
}
|
||||
} else {
|
||||
let e = make_editor(self.ctx.clone(), t, self.depth+1);
|
||||
*editor = Some(e.clone());
|
||||
e.write().unwrap().dn();
|
||||
let x = e.write().unwrap().handle_terminal_event(event);
|
||||
*cur_depth = e.write().unwrap().get_cursor().tree_addr.len();
|
||||
x
|
||||
}
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
|
|
|
@ -52,13 +52,14 @@ impl TreeNav for ProductEditor {
|
|||
}
|
||||
|
||||
fn goto(&mut self, mut c: TreeCursor) -> TreeNavResult {
|
||||
let old_cursor = self.cursor;
|
||||
|
||||
if let Some(mut segment) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t: _t, editor, cur_depth }) = segment.deref_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t: _t, editor, ed_depth, cur_depth, cur_dist:_ }) = segment.deref_mut() {
|
||||
if let Some(e) = editor {
|
||||
let mut e = e.write().unwrap();
|
||||
e.goto(TreeCursor::none());
|
||||
}
|
||||
*cur_depth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,23 +67,34 @@ impl TreeNav for ProductEditor {
|
|||
self.cursor = Some(crate::modulo(c.tree_addr.remove(0), self.n_indices.len() as isize));
|
||||
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, ed_depth, cur_depth, cur_dist:_ }) = element.deref_mut() {
|
||||
if let Some(e) = editor {
|
||||
e.write().unwrap().goto(c.clone());
|
||||
} else if c.tree_addr.len() > 0 {
|
||||
// create editor
|
||||
let e = make_editor(self.ctx.clone(), t, self.depth+1);
|
||||
let e = make_editor(self.ctx.clone(), t, *ed_depth+1);
|
||||
*editor = Some(e.clone());
|
||||
let mut e = e.write().unwrap();
|
||||
e.goto(c.clone());
|
||||
}
|
||||
*cur_depth = c.tree_addr.len();
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(i) = old_cursor{
|
||||
self.update_segment(i);
|
||||
}
|
||||
|
||||
if let Some(i) = self.cursor {
|
||||
self.update_segment(i);
|
||||
}
|
||||
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
self.cursor = None;
|
||||
|
||||
if let Some(i) = old_cursor {
|
||||
self.update_segment(i);
|
||||
}
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
}
|
||||
|
@ -94,12 +106,7 @@ impl TreeNav for ProductEditor {
|
|||
0 => {
|
||||
if direction.y > 0 {
|
||||
self.cursor = Some(0);
|
||||
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
*cur_depth = 1;
|
||||
}
|
||||
}
|
||||
self.update_segment(0);
|
||||
|
||||
self.goby(Vector2::new(direction.x, direction.y-1));
|
||||
TreeNavResult::Continue
|
||||
|
@ -113,134 +120,130 @@ impl TreeNav for ProductEditor {
|
|||
if direction.y > 0 {
|
||||
// dn
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, ed_depth, cur_depth, cur_dist:_ }) = element.deref_mut() {
|
||||
if let Some(e) = editor {
|
||||
let mut e = e.write().unwrap();
|
||||
e.goby(direction);
|
||||
*cur_depth = e.get_cursor().tree_addr.len() + 1;
|
||||
} else {
|
||||
// create editor
|
||||
let e = make_editor(self.ctx.clone(), t, self.depth+1);
|
||||
let e = make_editor(self.ctx.clone(), t, *ed_depth+1);
|
||||
*editor = Some(e.clone());
|
||||
let mut e = e.write().unwrap();
|
||||
e.goby(direction);
|
||||
*cur_depth = e.get_cursor().tree_addr.len() + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.update_segment(cur.tree_addr[0]);
|
||||
TreeNavResult::Continue
|
||||
} else if direction.y < 0 {
|
||||
// up
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
*cur_depth = 0;
|
||||
}
|
||||
}
|
||||
let old_cursor = self.cursor;
|
||||
self.cursor = None;
|
||||
if let Some(i) = old_cursor {
|
||||
self.update_segment(i);
|
||||
}
|
||||
TreeNavResult::Exit
|
||||
} else {
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
*cur_depth = 0;
|
||||
}
|
||||
}
|
||||
let old_cursor = self.cursor;
|
||||
|
||||
// horizontal
|
||||
if (cur.tree_addr[0]+direction.x >= 0) &&
|
||||
(cur.tree_addr[0]+direction.x < self.n_indices.len() as isize)
|
||||
{
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
*cur_depth = 0;
|
||||
}
|
||||
}
|
||||
|
||||
self.cursor = Some(cur.tree_addr[0] + direction.x);
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
*cur_depth = 1;
|
||||
}
|
||||
|
||||
self.update_cur_segment();
|
||||
if let Some(i) = old_cursor {
|
||||
self.update_segment(i);
|
||||
}
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
self.cursor = None;
|
||||
if let Some(i) = old_cursor {
|
||||
self.update_segment(i);
|
||||
}
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
}
|
||||
}
|
||||
depth => {
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, cur_depth }) = element.deref_mut() {
|
||||
if let Some(e) = editor {
|
||||
let mut ce = e.write().unwrap();
|
||||
//\\//\\//\\//\\
|
||||
// horizontal //
|
||||
//\\//\\//\\//\\
|
||||
match ce.goby(direction) {
|
||||
TreeNavResult::Exit => {
|
||||
*cur_depth = 1;
|
||||
drop(ce);
|
||||
drop(e);
|
||||
let old_cursor = self.cursor;
|
||||
let nav_result =
|
||||
if let Some(mut element) = self.get_cur_segment_mut() {
|
||||
if let Some(ProductEditorSegment::N{ t, editor, ed_depth, cur_depth, cur_dist:_ }) = element.deref_mut() {
|
||||
if let Some(e) = editor {
|
||||
let mut ce = e.write().unwrap();
|
||||
//\\//\\//\\//\\
|
||||
// horizontal //
|
||||
//\\//\\//\\//\\
|
||||
match ce.goby(direction) {
|
||||
TreeNavResult::Exit => {
|
||||
*cur_depth = 1;
|
||||
drop(ce);
|
||||
drop(e);
|
||||
|
||||
if direction.y < 0 {
|
||||
if depth <= (1-direction.y) as usize {
|
||||
// up
|
||||
*cur_depth = 1;
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
panic!("unplausible direction.y on exit");
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
} else if direction.y > 0 {
|
||||
// dn
|
||||
*cur_depth = depth + direction.y as usize;
|
||||
|
||||
TreeNavResult::Continue
|
||||
} else if direction.y == 0 {
|
||||
// horizontal
|
||||
|
||||
if direction.x != 0 {
|
||||
*cur_depth = 0;
|
||||
}
|
||||
|
||||
if (cur.tree_addr[0]+direction.x >= 0) &&
|
||||
(cur.tree_addr[0]+direction.x < self.n_indices.len() as isize)
|
||||
{
|
||||
if direction.x < 0 {
|
||||
cur.tree_addr[0] -= 1;
|
||||
for i in 1..depth {
|
||||
cur.tree_addr[i] = -1;
|
||||
}
|
||||
if direction.y < 0 {
|
||||
if depth <= (1-direction.y) as usize {
|
||||
// up
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
cur.tree_addr[0] += 1;
|
||||
for i in 1..depth {
|
||||
cur.tree_addr[i] = 0;
|
||||
}
|
||||
panic!("unplausible direction.y on exit");
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
} else if direction.y > 0 {
|
||||
// dn
|
||||
TreeNavResult::Continue
|
||||
} else if direction.y == 0 {
|
||||
// horizontal
|
||||
|
||||
if direction.x != 0 {
|
||||
*cur_depth = 0;
|
||||
}
|
||||
|
||||
self.goto(cur)
|
||||
if (cur.tree_addr[0]+direction.x >= 0) &&
|
||||
(cur.tree_addr[0]+direction.x < self.n_indices.len() as isize)
|
||||
{
|
||||
if direction.x < 0 {
|
||||
cur.tree_addr[0] -= 1;
|
||||
for i in 1..depth {
|
||||
cur.tree_addr[i] = -1;
|
||||
}
|
||||
} else {
|
||||
cur.tree_addr[0] += 1;
|
||||
for i in 1..depth {
|
||||
cur.tree_addr[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
self.goto(cur)
|
||||
} else {
|
||||
self.cursor = None;
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
} else {
|
||||
self.cursor = None;
|
||||
TreeNavResult::Exit
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
} else {
|
||||
}
|
||||
TreeNavResult::Continue => {
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
}
|
||||
TreeNavResult::Continue => {
|
||||
*cur_depth = (depth as isize + direction.y - 1) as usize;
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
} else {
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
} else {
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
} else {
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
} else {
|
||||
TreeNavResult::Continue
|
||||
};
|
||||
|
||||
if let Some(i) = old_cursor {
|
||||
self.update_segment(i);
|
||||
}
|
||||
|
||||
self.update_cur_segment();
|
||||
return nav_result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use {
|
|||
TerminalEditor, TerminalStyle, TerminalView,
|
||||
make_label
|
||||
},
|
||||
list::{ListCursorMode},
|
||||
tree_nav::{TerminalTreeEditor},
|
||||
color::{bg_style_from_depth, fg_style_from_depth}
|
||||
},
|
||||
|
@ -18,7 +19,9 @@ pub enum ProductEditorSegment {
|
|||
N {
|
||||
t: TypeLadder,
|
||||
editor: Option<Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>>,
|
||||
cur_depth: usize
|
||||
ed_depth: usize,
|
||||
cur_depth: usize,
|
||||
cur_dist: isize
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,30 +33,47 @@ impl ProductEditorSegment {
|
|||
.map_item({
|
||||
let depth = *depth;
|
||||
move |i, x|
|
||||
x.add_style_back(fg_style_from_depth(depth))
|
||||
x.add_style_back(fg_style_from_depth(depth)).add_style_back(TerminalStyle::italic(true))
|
||||
}
|
||||
),
|
||||
|
||||
ProductEditorSegment::N { t: _, editor: Some(e), cur_depth } =>
|
||||
ProductEditorSegment::N { t: _, editor: Some(e), ed_depth, cur_depth, cur_dist } =>
|
||||
e.read().unwrap()
|
||||
.get_term_view()
|
||||
.map_item({
|
||||
let e = e.clone();
|
||||
let d = *ed_depth;
|
||||
let cur_dist = *cur_dist;
|
||||
|
||||
move |i, x| {
|
||||
let cur_depth = e.read().unwrap().get_cursor().tree_addr.len();
|
||||
x
|
||||
.add_style_back(fg_style_from_depth(cur_depth))//fg_color((250,210,0)))
|
||||
.add_style_back(bg_style_from_depth(cur_depth))
|
||||
let c = e.read().unwrap().get_cursor();
|
||||
let cur_depth = c.tree_addr.len();
|
||||
let select =
|
||||
cur_dist == 0 &&
|
||||
if c.leaf_mode == ListCursorMode::Select {
|
||||
cur_depth == 0
|
||||
} else {
|
||||
cur_depth == 1
|
||||
};
|
||||
|
||||
return x
|
||||
.add_style_back(bg_style_from_depth(if select { 1 } else { 0 }))
|
||||
.add_style_back(TerminalStyle::bold(select))
|
||||
.add_style_back(fg_style_from_depth(d));
|
||||
}
|
||||
}),
|
||||
|
||||
ProductEditorSegment::N{ t, editor: None, cur_depth } =>
|
||||
ProductEditorSegment::N{ t, editor: None, ed_depth, cur_depth, cur_dist } =>
|
||||
make_label(&ctx.read().unwrap().type_term_to_str(&t[0]))
|
||||
.map_item({
|
||||
let cur_depth = 0;
|
||||
move |i, x| x
|
||||
.add_style_back(TerminalStyle::fg_color((130,90,40)))
|
||||
.add_style_back(bg_style_from_depth(cur_depth))
|
||||
let cur_depth = *cur_depth;
|
||||
let ed_depth = *ed_depth;
|
||||
let cur_dist = *cur_dist;
|
||||
|
||||
move |i, x|
|
||||
x.add_style_back(TerminalStyle::fg_color((130,90,40)))
|
||||
.add_style_back(bg_style_from_depth(if cur_dist == 0 { 1 } else { 0 }))
|
||||
.add_style_back(TerminalStyle::bold(cur_dist == 0))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ impl TreeCursor {
|
|||
|
||||
pub fn none() -> Self {
|
||||
TreeCursor {
|
||||
leaf_mode: ListCursorMode::Insert,
|
||||
leaf_mode: ListCursorMode::Select,
|
||||
tree_addr: vec![],
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue