feat: enable creating items on the same level
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-05-16 10:10:11 +02:00
parent 832587b51d
commit 65c2466f97
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
5 changed files with 46 additions and 0 deletions

View File

@ -100,6 +100,7 @@ impl<'a> App<'a> {
Msg::MoveDown => self.graph_explorer.move_down()?,
Msg::MoveUp => self.graph_explorer.move_up()?,
Msg::OpenCreateItemDialog => self.open_dialog(),
Msg::OpenCreateItemDialogBelow => self.open_dialog_below(),
Msg::OpenEditItemDialog { item } => self.open_edit_item_dialog(item),
Msg::EnterInsertMode => self.mode = Mode::Insert,
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) {
if self.dialog.is_none() {
let root = self.root.clone();

View File

@ -7,6 +7,7 @@ pub enum Commands {
Archive,
CreateSection { name: String },
CreateItem { name: String },
CreateBelow { name: String },
Edit,
ShowAll,
@ -44,6 +45,9 @@ impl CommandParser {
"ci" | "create-item" => Some(Commands::CreateItem {
name: rest.join(" ").to_string(),
}),
"cb" | "create-below" => Some(Commands::CreateBelow {
name: rest.join(" ").to_string(),
}),
"e" | "edit" => Some(Commands::Edit),
"show-all" => Some(Commands::ShowAll),
"hide-done" => Some(Commands::HideDone),

View File

@ -274,6 +274,25 @@ impl<'a> GraphExplorer<'a> {
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 => {
if let Some(item) = self.get_current_item() {
let path = self.get_current_path();

View File

@ -125,6 +125,11 @@ async fn update<'a>(
app.update(Msg::OpenCreateItemDialog)?;
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(':') => app.update(Msg::EnterCommandMode)?,
_ => return Ok(UpdateConclusion(false)),

View File

@ -10,6 +10,7 @@ pub enum Msg {
MoveUp,
QuitApp,
OpenCreateItemDialog,
OpenCreateItemDialogBelow,
OpenEditItemDialog { item: GraphItem },
Interact,