move more event handling from PTYListController into being handled by ListEditor with ListCmd
This commit is contained in:
parent
81a22aa831
commit
9af00d7294
5 changed files with 145 additions and 139 deletions
137
nested/src/editors/list/cmd.rs
Normal file
137
nested/src/editors/list/cmd.rs
Normal file
|
@ -0,0 +1,137 @@
|
|||
use {
|
||||
r3vi::{
|
||||
view::{singleton::*},
|
||||
buffer::{singleton::*}
|
||||
},
|
||||
crate::{
|
||||
editors::list::{ListEditor, ListCursorMode},
|
||||
type_system::{Context, ReprTree},
|
||||
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||
commander::{ObjCommander}
|
||||
},
|
||||
std::sync::{Arc, RwLock}
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum ListCmd {
|
||||
DeletePxev,
|
||||
DeleteNexd,
|
||||
JoinNexd,
|
||||
JoinPxev,
|
||||
Split,
|
||||
Clear,
|
||||
Close,
|
||||
}
|
||||
|
||||
impl ListCmd {
|
||||
pub fn into_repr_tree(self, ctx: &Arc<RwLock<Context>>) -> Arc<RwLock<ReprTree>> {
|
||||
let buf = r3vi::buffer::singleton::SingletonBuffer::new(self);
|
||||
ReprTree::new_leaf(
|
||||
(ctx, "( ListCmd )"),
|
||||
buf.get_port().into()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjCommander for ListEditor {
|
||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||
let cmd_repr = cmd_obj.read().unwrap();
|
||||
|
||||
if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
|
||||
let cur = self.cursor.get();
|
||||
drop(cmd_repr);
|
||||
|
||||
if let Some(idx) = cur.idx {
|
||||
match cur.mode {
|
||||
ListCursorMode::Select => {
|
||||
if let Some(mut item) = self.get_item().clone() {
|
||||
if self.is_listlist() {
|
||||
let item_cur = item.get_cursor();
|
||||
|
||||
match cmd.get() {
|
||||
ListCmd::DeletePxev => {
|
||||
if idx > 0
|
||||
&& item_cur.tree_addr.iter().fold(
|
||||
true,
|
||||
|is_zero, x| is_zero && (*x == 0)
|
||||
)
|
||||
{
|
||||
self.listlist_join_pxev(idx, &item);
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
item.send_cmd_obj(cmd_obj)
|
||||
}
|
||||
}
|
||||
|
||||
ListCmd::DeleteNexd => {
|
||||
let item_cur = item.get_cursor_warp();
|
||||
let next_idx = idx as usize + 1;
|
||||
|
||||
if next_idx < self.data.len()
|
||||
&& item_cur.tree_addr.iter().fold(
|
||||
true,
|
||||
|is_end, x| is_end && (*x == -1)
|
||||
)
|
||||
{
|
||||
self.listlist_join_nexd(next_idx, &item);
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
item.send_cmd_obj(cmd_obj)
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
} else {
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
},
|
||||
|
||||
ListCursorMode::Insert => {
|
||||
match cmd.get() {
|
||||
ListCmd::DeletePxev => {
|
||||
self.delete_pxev();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::DeleteNexd => {
|
||||
self.delete_nexd();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::Split => {
|
||||
self.listlist_split();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::Clear => {
|
||||
self.clear();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::Close => {
|
||||
self.goto(TreeCursor::none());
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
_ =>{
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
|
||||
} else {
|
||||
if let Some(cur_item) = self.get_item_mut() {
|
||||
drop(cmd_repr);
|
||||
cur_item.write().unwrap().send_cmd_obj(cmd_obj)
|
||||
} else {
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
use {
|
||||
r3vi::{
|
||||
view::{singleton::*},
|
||||
buffer::{singleton::*}
|
||||
},
|
||||
crate::{
|
||||
editors::list::ListEditor,
|
||||
type_system::{Context, ReprTree},
|
||||
tree::{NestedNode, TreeNav, TreeNavResult, TreeCursor},
|
||||
commander::{ObjCommander}
|
||||
},
|
||||
std::sync::{Arc, RwLock}
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum ListCmd {
|
||||
DeletePxev,
|
||||
DeleteNexd,
|
||||
JoinNexd,
|
||||
JoinPxev,
|
||||
Split,
|
||||
Clear,
|
||||
Close,
|
||||
}
|
||||
|
||||
impl ListCmd {
|
||||
fn into_repr_tree(self, ctx: &Arc<RwLock<Context>>) -> Arc<RwLock<ReprTree>> {
|
||||
let buf = r3vi::buffer::singleton::SingletonBuffer::new(self);
|
||||
ReprTree::new_leaf(
|
||||
(ctx, "( ListCmd )"),
|
||||
buf.get_port().into()
|
||||
)
|
||||
}
|
||||
}
|
||||
/*
|
||||
impl Into< Arc<RwLock<ReprTree>> > for (&Arc<RwLock<Context>>, ListCmd) {
|
||||
fn into(self) -> Arc<RwLock<ReprTree>> {
|
||||
self.1.into_repr_tree(self.0)
|
||||
}
|
||||
}
|
||||
*/
|
||||
impl ObjCommander for ListEditor {
|
||||
fn send_cmd_obj(&mut self, cmd_obj: Arc<RwLock<ReprTree>>) -> TreeNavResult {
|
||||
let cmd_repr = cmd_obj.read().unwrap();
|
||||
if let Some(cmd) = cmd_repr.get_view::<dyn SingletonView<Item = ListCmd>>() {
|
||||
match cmd.get() {
|
||||
ListCmd::DeletePxev => {
|
||||
self.delete_pxev();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::DeleteNexd => {
|
||||
self.delete_nexd();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::JoinPxev => {
|
||||
// TODO
|
||||
//self.listlist_join_pxev();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::JoinNexd => {
|
||||
// TODO
|
||||
//self.listlist_join_nexd();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::Split => {
|
||||
self.listlist_split();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::Clear => {
|
||||
self.clear();
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
ListCmd::Close => {
|
||||
self.goto(TreeCursor::none());
|
||||
TreeNavResult::Exit
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(cur_item) = self.get_item_mut() {
|
||||
drop(cmd_repr);
|
||||
cur_item.write().unwrap().send_cmd_obj(cmd_obj)
|
||||
} else {
|
||||
TreeNavResult::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ use {
|
|||
},
|
||||
crate::{
|
||||
type_system::{Context, TypeTerm, ReprTree},
|
||||
editors::list::{ListCursor, ListCursorMode, commander::ListCmd, PTYListController, PTYListStyle},
|
||||
editors::list::{ListCursor, ListCursorMode, ListCmd, PTYListController, PTYListStyle},
|
||||
tree::{NestedNode, TreeNav, TreeCursor},
|
||||
diagnostics::Diagnostics
|
||||
},
|
||||
|
|
|
@ -5,13 +5,13 @@ pub mod editor;
|
|||
pub mod nav;
|
||||
pub mod segment;
|
||||
pub mod pty_editor;
|
||||
pub mod commander;
|
||||
pub mod cmd;
|
||||
|
||||
pub use {
|
||||
cursor::{ListCursor, ListCursorMode},
|
||||
editor::ListEditor,
|
||||
segment::{ListSegment, ListSegmentSequence},
|
||||
pty_editor::{PTYListStyle, PTYListController},
|
||||
commander::ListCmd
|
||||
cmd::ListCmd
|
||||
};
|
||||
|
||||
|
|
|
@ -161,6 +161,7 @@ impl ObjCommander for PTYListController {
|
|||
let cur = e.cursor.get();
|
||||
let cur_depth = e.get_cursor().tree_addr.len();
|
||||
|
||||
let ctx0 = e.ctx.clone();
|
||||
let ctx = e.ctx.clone();
|
||||
let ctx = ctx.read().unwrap();
|
||||
|
||||
|
@ -218,12 +219,10 @@ impl ObjCommander for PTYListController {
|
|||
ListCursorMode::Insert => {
|
||||
match event {
|
||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||
e.delete_pxev();
|
||||
TreeNavResult::Continue
|
||||
e.send_cmd_obj( ListCmd::DeletePxev.into_repr_tree(&ctx0) )
|
||||
}
|
||||
TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
||||
e.delete_nexd();
|
||||
TreeNavResult::Continue
|
||||
e.send_cmd_obj( ListCmd::DeletePxev.into_repr_tree(&ctx0) )
|
||||
}
|
||||
_ => {
|
||||
let mut node = Context::make_node(&e.ctx, e.typ.clone(), self.depth).unwrap();
|
||||
|
@ -251,52 +250,10 @@ impl ObjCommander for PTYListController {
|
|||
if e.is_listlist() {
|
||||
match event {
|
||||
TerminalEvent::Input(Event::Key(Key::Backspace)) => {
|
||||
let item_cur = item.get_cursor();
|
||||
|
||||
if idx > 0
|
||||
&& item_cur.tree_addr.iter().fold(
|
||||
true,
|
||||
|is_zero, x| is_zero && (*x == 0)
|
||||
)
|
||||
{
|
||||
e.listlist_join_pxev(idx, &item);
|
||||
|
||||
/* Optional: recursive joining
|
||||
|
||||
if item_cur.tree_addr.len() > 1 {
|
||||
let mut item = e.get_item_mut().unwrap();
|
||||
item.handle_terminal_event(event);
|
||||
}
|
||||
*/
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
item.send_cmd_obj(cmd_obj)
|
||||
}
|
||||
e.send_cmd_obj( ListCmd::DeletePxev.into_repr_tree(&ctx0) )
|
||||
}
|
||||
TerminalEvent::Input(Event::Key(Key::Delete)) => {
|
||||
let item_cur = item.get_cursor_warp();
|
||||
let next_idx = idx as usize + 1;
|
||||
|
||||
if next_idx < e.data.len()
|
||||
&& item_cur.tree_addr.iter().fold(
|
||||
true,
|
||||
|is_end, x| is_end && (*x == -1)
|
||||
)
|
||||
{
|
||||
e.listlist_join_nexd(next_idx, &item);
|
||||
|
||||
/* Optional: recursive joining
|
||||
|
||||
if item_cur.tree_addr.len() > 1 {
|
||||
let mut item = e.get_item_mut().unwrap();
|
||||
item.handle_terminal_event(event);
|
||||
}
|
||||
*/
|
||||
|
||||
TreeNavResult::Continue
|
||||
} else {
|
||||
item.send_cmd_obj(cmd_obj)
|
||||
}
|
||||
e.send_cmd_obj( ListCmd::DeleteNexd.into_repr_tree(&ctx0) )
|
||||
}
|
||||
|
||||
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
|
||||
|
|
Loading…
Reference in a new issue