pty list: add split key
This commit is contained in:
parent
b2f437d7df
commit
273f20d3db
8 changed files with 87 additions and 7 deletions
nested/src
|
@ -115,6 +115,7 @@ impl PosIntEditor {
|
|||
digits_editor: PTYListEditor::new(
|
||||
Box::new(move || Arc::new(RwLock::new(DigitEditor::new(radix)))) as Box<dyn Fn() -> Arc<RwLock<DigitEditor>> + Send + Sync>,
|
||||
SeqDecorStyle::Hex,
|
||||
' ',
|
||||
0
|
||||
),
|
||||
}
|
||||
|
|
|
@ -80,6 +80,20 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
}
|
||||
}
|
||||
|
||||
/// split the list off at the current cursor position and return the second half
|
||||
/*
|
||||
pub fn split(&mut self) -> ListEditor<ItemEditor> {
|
||||
let mut le = ListEditor::new(self.make_item_editor.clone());
|
||||
let p = self.cursor.get();
|
||||
for i in p.idx .. self.data.len() {
|
||||
le.data.push( self.data[p.idx] );
|
||||
self.data.remove(p.idx);
|
||||
}
|
||||
le.goto(TreeCursor::home());
|
||||
le
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn clear(&mut self) {
|
||||
self.data.clear();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
{
|
||||
pub editor: ListEditor<ItemEditor>,
|
||||
|
||||
split_char: char,
|
||||
|
||||
style: SeqDecorStyle,
|
||||
depth: usize,
|
||||
|
||||
|
@ -39,6 +41,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
pub fn new(
|
||||
make_item_editor: impl Fn() -> Arc<RwLock<ItemEditor>> + Send + Sync + 'static,
|
||||
style: SeqDecorStyle,
|
||||
split_char: char,
|
||||
depth: usize
|
||||
) -> Self {
|
||||
let port = ViewPort::new();
|
||||
|
@ -46,6 +49,7 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
editor: ListEditor::new(make_item_editor, depth),
|
||||
style,
|
||||
depth,
|
||||
split_char,
|
||||
port
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +57,13 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
pub fn from_editor(
|
||||
editor: ListEditor<ItemEditor>,
|
||||
style: SeqDecorStyle,
|
||||
split_char: char,
|
||||
depth: usize
|
||||
) -> Self {
|
||||
let port = ViewPort::new();
|
||||
PTYListEditor {
|
||||
editor,
|
||||
split_char,
|
||||
style,
|
||||
depth,
|
||||
port
|
||||
|
@ -158,6 +164,32 @@ where ItemEditor: TerminalTreeEditor + ?Sized + Send + Sync + 'static
|
|||
self.editor.set_leaf_mode(ListCursorMode::Insert);
|
||||
TerminalEditorResult::Continue
|
||||
}
|
||||
|
||||
TerminalEvent::Input(Event::Key(Key::Char(c))) => {
|
||||
if *c == self.split_char {
|
||||
let c = self.editor.cursor.get();
|
||||
self.editor.goto(TreeCursor::none());
|
||||
self.editor.cursor.set(ListCursor {
|
||||
mode: ListCursorMode::Insert,
|
||||
idx: Some(1 + c.idx.unwrap_or(0))
|
||||
});
|
||||
} else {
|
||||
if let Some(e) = self.editor.get_item() {
|
||||
match e.write().unwrap().handle_terminal_event(&TerminalEvent::Input(Event::Key(Key::Char(*c)))) {
|
||||
TerminalEditorResult::Exit => {
|
||||
self.editor.cursor.set(ListCursor {
|
||||
mode: ListCursorMode::Insert,
|
||||
idx: Some(idx as isize + 1),
|
||||
});
|
||||
}
|
||||
TerminalEditorResult::Continue => {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TerminalEditorResult::Continue
|
||||
}
|
||||
ev => {
|
||||
if let Some(e) = self.editor.get_item() {
|
||||
match e.write().unwrap().handle_terminal_event(ev) {
|
||||
|
|
|
@ -29,6 +29,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
Arc::new(RwLock::new(CharEditor::new()))
|
||||
}),
|
||||
SeqDecorStyle::DoubleQuote,
|
||||
'"',
|
||||
depth
|
||||
)
|
||||
))
|
||||
|
@ -48,6 +49,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
}
|
||||
}),
|
||||
SeqDecorStyle::EnumSet,
|
||||
'"',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
@ -59,6 +61,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
|| { Arc::new(RwLock::new(CharEditor::new())) }
|
||||
),
|
||||
SeqDecorStyle::Plain,
|
||||
'\n',
|
||||
depth+1
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
@ -70,6 +73,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
Arc::new(RwLock::new(PosIntEditor::new(16)))
|
||||
}),
|
||||
SeqDecorStyle::EnumSet,
|
||||
',',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
@ -84,10 +88,12 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
Arc::new(RwLock::new(CharEditor::new()))
|
||||
}),
|
||||
SeqDecorStyle::Plain,
|
||||
'\n',
|
||||
d
|
||||
)))
|
||||
}}),
|
||||
SeqDecorStyle::Path,
|
||||
'/',
|
||||
depth
|
||||
))) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
|
@ -106,6 +112,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
}
|
||||
}),
|
||||
SeqDecorStyle::EnumSet,
|
||||
',',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
@ -121,20 +128,21 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
})
|
||||
},
|
||||
SeqDecorStyle::VerticalSexpr,
|
||||
',',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( RGB )").unwrap() {
|
||||
Arc::new(RwLock::new(ProductEditor::new(depth, ctx.clone())
|
||||
.with_t(Point2::new(0, 0), "{")
|
||||
.with_t(Point2::new(0, 0), "{ ")
|
||||
.with_t(Point2::new(1, 1), "r: ")
|
||||
.with_n(Point2::new(2, 1), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
|
||||
.with_t(Point2::new(1, 2), "g: ")
|
||||
.with_n(Point2::new(2, 2), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
|
||||
.with_t(Point2::new(1, 3), "b: ")
|
||||
.with_n(Point2::new(2, 3), vec![ ctx.read().unwrap().type_term_from_str("( PosInt 16 BigEndian )").unwrap() ] )
|
||||
.with_t(Point2::new(0, 4), "}")
|
||||
.with_t(Point2::new(0, 4), "} ")
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
||||
} else if t[0] == c.type_term_from_str("( Vec3i )").unwrap() {
|
||||
|
@ -163,6 +171,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
}
|
||||
}),
|
||||
SeqDecorStyle::VerticalSexpr,
|
||||
'\n',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
@ -177,6 +186,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
}
|
||||
}),
|
||||
SeqDecorStyle::Tuple,
|
||||
'\n',
|
||||
depth
|
||||
)
|
||||
)) as Arc<RwLock<dyn TerminalTreeEditor + Send + Sync>>
|
||||
|
@ -188,6 +198,7 @@ pub fn make_editor(ctx: Arc<RwLock<Context>>, t: &TypeLadder, depth: usize) -> A
|
|||
Arc::new(RwLock::new(CharEditor::new()))
|
||||
},
|
||||
SeqDecorStyle::DoubleQuote,
|
||||
' ',
|
||||
depth
|
||||
)
|
||||
))
|
||||
|
|
|
@ -147,7 +147,7 @@ impl ProductEditor {
|
|||
} else {
|
||||
let mut b = VecBuffer::new();
|
||||
b.push(crate::diagnostics::make_todo(crate::terminal::make_label(&format!("complete {}", self.ctx.read().unwrap().type_term_to_str(&t[0])))));
|
||||
|
||||
|
||||
self.msg_buf.update(idx as usize, Some(b.get_port().to_sequence()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue