diff --git a/core/src/state/notebook.rs b/core/src/state/notebook.rs index 37c564f..b92b2ab 100644 --- a/core/src/state/notebook.rs +++ b/core/src/state/notebook.rs @@ -137,6 +137,7 @@ impl NotebookState { vec![ "[i] Edit mode", "[b] Browse note tree", + "[n] Toggle line number", "[h] Show editor keymap", "[Esc] Quit", ] diff --git a/tui/src/context/notebook.rs b/tui/src/context/notebook.rs index 0c7f7b2..be05a5f 100644 --- a/tui/src/context/notebook.rs +++ b/tui/src/context/notebook.rs @@ -61,6 +61,7 @@ pub struct NotebookContext { // editor pub editor: TextArea<'static>, pub opened_note: Option, + pub show_line_number: bool, } impl Default for NotebookContext { @@ -75,6 +76,7 @@ impl Default for NotebookContext { editor: TextArea::new(vec!["Welcome to Glues :D".to_owned()]), opened_note: None, + show_line_number: true, } } } @@ -238,6 +240,11 @@ impl NotebookContext { self.state = ContextState::EditorEditMode; Action::Dispatch(NotebookEvent::EditNote.into()) } + KeyCode::Char('n') => { + self.show_line_number = !self.show_line_number; + + Action::None + } KeyCode::Char('h') => TuiAction::ShowEditorKeymap.into(), KeyCode::Esc => TuiAction::Confirm { message: "Do you want to quit?".to_owned(), diff --git a/tui/src/views/body/notebook/editor.rs b/tui/src/views/body/notebook/editor.rs index 76ea745..ac84573 100644 --- a/tui/src/views/body/notebook/editor.rs +++ b/tui/src/views/body/notebook/editor.rs @@ -34,7 +34,11 @@ pub fn draw(frame: &mut Frame, area: Rect, context: &mut Context) { ), None => block, } - .padding(Padding::horizontal(1)); + .padding(if context.notebook.show_line_number { + Padding::ZERO + } else { + Padding::left(1) + }); context.notebook.editor.set_block(block); @@ -46,11 +50,14 @@ pub fn draw(frame: &mut Frame, area: Rect, context: &mut Context) { _ => (Style::default(), Style::default()), }; - context.notebook.editor.set_cursor_style(cursor_style); - context - .notebook - .editor - .set_cursor_line_style(cursor_line_style); + let editor = &mut context.notebook.editor; + editor.set_cursor_style(cursor_style); + editor.set_cursor_line_style(cursor_line_style); + if context.notebook.show_line_number { + editor.set_line_number_style(Style::default().dark_gray().dim()); + } else { + editor.remove_line_number(); + } frame.render_widget(&context.notebook.editor, area); }