Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove legacy traverse module in core #76

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/state/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
types::DirectoryId,
Error, Event, Glues, NotebookTransition, Result,
},
consume::{directory, note, tabs, traverse},
consume::{directory, note, tabs},
};

pub use inner_state::{
Expand Down
1 change: 0 additions & 1 deletion core/src/state/notebook/consume.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod directory;
pub mod note;
pub mod tabs;
pub mod traverse;
42 changes: 0 additions & 42 deletions core/src/state/notebook/consume/traverse.rs

This file was deleted.

6 changes: 3 additions & 3 deletions core/src/state/notebook/inner_state/directory_selected.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
db::Db,
state::notebook::{directory, note, tabs, traverse, InnerState, NotebookState},
state::notebook::{directory, note, tabs, InnerState, NotebookState},
Error, Event, KeyEvent, NotebookEvent, NotebookTransition, Result,
};

Expand Down Expand Up @@ -51,8 +51,8 @@ pub async fn consume(

directory::close(state, parent)
}
Key(KeyEvent::J | KeyEvent::Down) => traverse::select_next(state),
Key(KeyEvent::K | KeyEvent::Up) => traverse::select_prev(state),
Key(KeyEvent::J | KeyEvent::Down) => Ok(NotebookTransition::SelectNext(1)),
Key(KeyEvent::K | KeyEvent::Up) => Ok(NotebookTransition::SelectPrev(1)),
Key(KeyEvent::M) => {
let directory = state.get_selected_directory()?.clone();

Expand Down
6 changes: 3 additions & 3 deletions core/src/state/notebook/inner_state/note_selected.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
db::Db,
state::notebook::{directory, note, tabs, traverse, InnerState, NotebookState},
state::notebook::{directory, note, tabs, InnerState, NotebookState},
Error, Event, KeyEvent, NotebookEvent, NotebookTransition, Result,
};

Expand Down Expand Up @@ -35,8 +35,8 @@ pub async fn consume(

directory::close(state, directory)
}
Key(KeyEvent::J | KeyEvent::Down) => traverse::select_next(state),
Key(KeyEvent::K | KeyEvent::Up) => traverse::select_prev(state),
Key(KeyEvent::J | KeyEvent::Down) => Ok(NotebookTransition::SelectNext(1)),
Key(KeyEvent::K | KeyEvent::Up) => Ok(NotebookTransition::SelectPrev(1)),
Key(KeyEvent::M) => {
let note = state.get_selected_note()?.clone();

Expand Down
2 changes: 0 additions & 2 deletions core/src/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub enum NotebookTransition {
BrowseNoteTree,
FocusEditor,

SelectNote(Note),
SelectDirectory(Directory),
UpdateNoteContent(NoteId),

Alert(String),
Expand Down
48 changes: 6 additions & 42 deletions tui/src/context/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,49 +255,13 @@ impl NotebookContext {
}

fn consume_on_note_tree_browsing(&mut self, code: KeyCode) -> Action {
macro_rules! item {
() => {
self.tree_state
.selected()
.and_then(|idx| self.tree_items.get(idx))
.log_expect("[NotebookContext::consume] selected must not be empty")
};
}

match code {
KeyCode::Char('j') | KeyCode::Down => {
self.tree_state.select_next();

match self
.tree_state
.selected()
.and_then(|i| self.tree_items.get(i))
{
Some(TreeItem::Directory { value, .. }) => {
Action::Dispatch(NotebookEvent::SelectDirectory(value.clone()).into())
}
Some(TreeItem::Note { value, .. }) => {
Action::Dispatch(NotebookEvent::SelectNote(value.clone()).into())
}
None => {
self.tree_state.select_last();
Action::None
}
}
}
KeyCode::Char('k') | KeyCode::Up => {
self.tree_state.select_previous();

match item!() {
TreeItem::Directory { value, .. } => {
Action::Dispatch(NotebookEvent::SelectDirectory(value.clone()).into())
}
TreeItem::Note { value, .. } => {
Action::Dispatch(NotebookEvent::SelectNote(value.clone()).into())
}
}
}
KeyCode::Char('m') => match item!() {
KeyCode::Char('m') => match self
.tree_state
.selected()
.and_then(|idx| self.tree_items.get(idx))
.log_expect("[NotebookContext::consume] selected must not be empty")
{
TreeItem::Directory { .. } => {
self.directory_actions_state.select_first();

Expand Down