feat: enable creating items on the same level
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
832587b51d
commit
65c2466f97
@ -100,6 +100,7 @@ impl<'a> App<'a> {
|
|||||||
Msg::MoveDown => self.graph_explorer.move_down()?,
|
Msg::MoveDown => self.graph_explorer.move_down()?,
|
||||||
Msg::MoveUp => self.graph_explorer.move_up()?,
|
Msg::MoveUp => self.graph_explorer.move_up()?,
|
||||||
Msg::OpenCreateItemDialog => self.open_dialog(),
|
Msg::OpenCreateItemDialog => self.open_dialog(),
|
||||||
|
Msg::OpenCreateItemDialogBelow => self.open_dialog_below(),
|
||||||
Msg::OpenEditItemDialog { item } => self.open_edit_item_dialog(item),
|
Msg::OpenEditItemDialog { item } => self.open_edit_item_dialog(item),
|
||||||
Msg::EnterInsertMode => self.mode = Mode::Insert,
|
Msg::EnterInsertMode => self.mode = Mode::Insert,
|
||||||
Msg::EnterViewMode => self.mode = Mode::View,
|
Msg::EnterViewMode => self.mode = Mode::View,
|
||||||
@ -181,6 +182,22 @@ impl<'a> App<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn open_dialog_below(&mut self) {
|
||||||
|
if self.dialog.is_none() {
|
||||||
|
let root = self.root.clone();
|
||||||
|
let path = self.graph_explorer.get_current_path();
|
||||||
|
|
||||||
|
if let Some((_, rest)) = path.split_last() {
|
||||||
|
let path = rest.to_vec();
|
||||||
|
|
||||||
|
self.focus = AppFocus::Dialog;
|
||||||
|
self.dialog = Some(Dialog::CreateItem {
|
||||||
|
state: CreateItemState::new(&self.state, root, path),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn open_edit_item_dialog(&mut self, item: &GraphItem) {
|
fn open_edit_item_dialog(&mut self, item: &GraphItem) {
|
||||||
if self.dialog.is_none() {
|
if self.dialog.is_none() {
|
||||||
let root = self.root.clone();
|
let root = self.root.clone();
|
||||||
|
@ -7,6 +7,7 @@ pub enum Commands {
|
|||||||
Archive,
|
Archive,
|
||||||
CreateSection { name: String },
|
CreateSection { name: String },
|
||||||
CreateItem { name: String },
|
CreateItem { name: String },
|
||||||
|
CreateBelow { name: String },
|
||||||
Edit,
|
Edit,
|
||||||
|
|
||||||
ShowAll,
|
ShowAll,
|
||||||
@ -44,6 +45,9 @@ impl CommandParser {
|
|||||||
"ci" | "create-item" => Some(Commands::CreateItem {
|
"ci" | "create-item" => Some(Commands::CreateItem {
|
||||||
name: rest.join(" ").to_string(),
|
name: rest.join(" ").to_string(),
|
||||||
}),
|
}),
|
||||||
|
"cb" | "create-below" => Some(Commands::CreateBelow {
|
||||||
|
name: rest.join(" ").to_string(),
|
||||||
|
}),
|
||||||
"e" | "edit" => Some(Commands::Edit),
|
"e" | "edit" => Some(Commands::Edit),
|
||||||
"show-all" => Some(Commands::ShowAll),
|
"show-all" => Some(Commands::ShowAll),
|
||||||
"hide-done" => Some(Commands::HideDone),
|
"hide-done" => Some(Commands::HideDone),
|
||||||
|
@ -274,6 +274,25 @@ impl<'a> GraphExplorer<'a> {
|
|||||||
batch.with(cmd.into_command());
|
batch.with(cmd.into_command());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Commands::CreateBelow { name } => {
|
||||||
|
if !name.is_empty() {
|
||||||
|
let path = self.get_current_path();
|
||||||
|
if let Some((_, path)) = path.split_last() {
|
||||||
|
let mut path = path.to_vec();
|
||||||
|
path.push(name.replace(".", " "));
|
||||||
|
|
||||||
|
let cmd = self.state.create_item_command().command(
|
||||||
|
&self.inner.root,
|
||||||
|
&path.iter().map(|i| i.as_str()).collect_vec(),
|
||||||
|
name,
|
||||||
|
"",
|
||||||
|
&hyperlog_core::log::ItemState::default(),
|
||||||
|
);
|
||||||
|
|
||||||
|
batch.with(cmd.into_command());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Commands::Edit => {
|
Commands::Edit => {
|
||||||
if let Some(item) = self.get_current_item() {
|
if let Some(item) = self.get_current_item() {
|
||||||
let path = self.get_current_path();
|
let path = self.get_current_path();
|
||||||
|
@ -125,6 +125,11 @@ async fn update<'a>(
|
|||||||
app.update(Msg::OpenCreateItemDialog)?;
|
app.update(Msg::OpenCreateItemDialog)?;
|
||||||
app.update(Msg::EnterInsertMode)?
|
app.update(Msg::EnterInsertMode)?
|
||||||
}
|
}
|
||||||
|
KeyCode::Char('o') => {
|
||||||
|
// TODO: batch commands
|
||||||
|
app.update(Msg::OpenCreateItemDialogBelow)?;
|
||||||
|
app.update(Msg::EnterInsertMode)?
|
||||||
|
}
|
||||||
KeyCode::Char('i') => app.update(Msg::EnterInsertMode)?,
|
KeyCode::Char('i') => app.update(Msg::EnterInsertMode)?,
|
||||||
KeyCode::Char(':') => app.update(Msg::EnterCommandMode)?,
|
KeyCode::Char(':') => app.update(Msg::EnterCommandMode)?,
|
||||||
_ => return Ok(UpdateConclusion(false)),
|
_ => return Ok(UpdateConclusion(false)),
|
||||||
|
@ -10,6 +10,7 @@ pub enum Msg {
|
|||||||
MoveUp,
|
MoveUp,
|
||||||
QuitApp,
|
QuitApp,
|
||||||
OpenCreateItemDialog,
|
OpenCreateItemDialog,
|
||||||
|
OpenCreateItemDialogBelow,
|
||||||
OpenEditItemDialog { item: GraphItem },
|
OpenEditItemDialog { item: GraphItem },
|
||||||
Interact,
|
Interact,
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user