list editor: fix out of bounds on backspace
This commit is contained in:
parent
f393704054
commit
cdeb0f9bc8
1 changed files with 22 additions and 18 deletions
|
@ -327,6 +327,8 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.goto_home();
|
||||||
}
|
}
|
||||||
TreeNavResult::Continue
|
TreeNavResult::Continue
|
||||||
}
|
}
|
||||||
|
@ -477,10 +479,10 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static,
|
||||||
ListCursorMode::Insert => {
|
ListCursorMode::Insert => {
|
||||||
match event {
|
match event {
|
||||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||||
if idx > 0 {
|
if idx > 0 && idx <= self.data.len() {
|
||||||
self.data.remove(idx-1);
|
|
||||||
cur.idx = Some(idx-1);
|
cur.idx = Some(idx-1);
|
||||||
self.cursor.set(cur);
|
self.cursor.set(cur);
|
||||||
|
self.data.remove(idx-1);
|
||||||
TerminalEditorResult::Continue
|
TerminalEditorResult::Continue
|
||||||
} else {
|
} else {
|
||||||
TerminalEditorResult::Exit
|
TerminalEditorResult::Exit
|
||||||
|
@ -551,24 +553,26 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static,
|
||||||
TerminalEditorResult::Exit => {
|
TerminalEditorResult::Exit => {
|
||||||
cur_edit.up();
|
cur_edit.up();
|
||||||
drop(cur_edit);
|
drop(cur_edit);
|
||||||
|
drop(ce);
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
TerminalEvent::Input(Event::Key(Key::Char(' '))) => {
|
|
||||||
// split..
|
|
||||||
self.cursor.set(ListCursor {
|
|
||||||
mode: ListCursorMode::Insert,
|
|
||||||
idx: Some(idx+1)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||||
|
// todo: join instead of remove
|
||||||
self.cursor.set(ListCursor {
|
self.cursor.set(ListCursor {
|
||||||
mode: ListCursorMode::Insert,
|
mode: ListCursorMode::Insert,
|
||||||
idx: Some(idx)
|
idx: Some(idx)
|
||||||
});
|
});
|
||||||
|
|
||||||
self.data.remove(idx); // todo: join instead of remove
|
self.data.remove(idx);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// todo: split
|
||||||
|
|
||||||
|
self.cursor.set(ListCursor {
|
||||||
|
mode: ListCursorMode::Insert,
|
||||||
|
idx: Some(idx+1)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
TerminalEditorResult::Continue => {}
|
TerminalEditorResult::Continue => {}
|
||||||
|
@ -611,11 +615,11 @@ where ItemEditor: TerminalEditor + ?Sized + Send + Sync + 'static,
|
||||||
atom.add_style_front(TerminalStyle::bg_color((90,60,200)))
|
atom.add_style_front(TerminalStyle::bg_color((90,60,200)))
|
||||||
),
|
),
|
||||||
ListEditorViewSegment::Modify(sub_view) => {
|
ListEditorViewSegment::Modify(sub_view) => {
|
||||||
sub_view.clone()/*.map_item(
|
sub_view.clone().map_item(
|
||||||
|_pt, atom|
|
|_pt, atom|
|
||||||
atom//.add_style_back(TerminalStyle::bg_color((0,0,0)))
|
atom.add_style_back(TerminalStyle::bg_color((22,15,50)))
|
||||||
//.add_style_back(TerminalStyle::bold(true))
|
//.add_style_back(TerminalStyle::bold(true))
|
||||||
)*/
|
)
|
||||||
},
|
},
|
||||||
ListEditorViewSegment::View(sub_view) =>
|
ListEditorViewSegment::View(sub_view) =>
|
||||||
sub_view.clone()
|
sub_view.clone()
|
||||||
|
@ -624,7 +628,7 @@ where ItemEditor: TerminalEditor + ?Sized + Send + Sync + 'static,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn horizontal_sexpr_view(&self) -> OuterViewPort<dyn TerminalView> {
|
pub fn horizontal_sexpr_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
self.get_seg_seq_view().horizontal_sexpr_view(0)
|
self.get_seg_seq_view().horizontal_sexpr_view(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vertical_sexpr_view(&self) -> OuterViewPort<dyn TerminalView> {
|
pub fn vertical_sexpr_view(&self) -> OuterViewPort<dyn TerminalView> {
|
||||||
|
|
Loading…
Reference in a new issue