Skip to content

Commit 8db7aa5

Browse files
committed
v1.3: scrolling
1 parent 8e37dfb commit 8db7aa5

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kiroku-tui"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2024"
55
description = "A simple, terminal-based personal journaling and note-taking tool."
66
repository = "https://github.com/gab-dev-7/kiroku"

src/app.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub enum Action {
2222
Backspace,
2323
SubmitInput,
2424
CancelInput,
25+
ScrollUp,
26+
ScrollDown,
2527
}
2628

2729
#[derive(PartialEq)]
@@ -49,6 +51,7 @@ pub struct App {
4951
pub syncing: bool,
5052
pub spinner_index: usize,
5153
pub clipboard: Option<Clipboard>,
54+
pub preview_scroll: u16,
5255
}
5356

5457
impl App {
@@ -83,6 +86,7 @@ impl App {
8386
syncing: false,
8487
spinner_index: 0,
8588
clipboard,
89+
preview_scroll: 0,
8690
};
8791

8892
if !app.notes.is_empty() {
@@ -168,6 +172,7 @@ impl App {
168172
};
169173
self.list_state.select(Some(i));
170174
self.load_note_content(i);
175+
self.preview_scroll = 0;
171176
}
172177

173178
pub fn previous(&mut self) {
@@ -183,6 +188,7 @@ impl App {
183188
};
184189
self.list_state.select(Some(i));
185190
self.load_note_content(i);
191+
self.preview_scroll = 0;
186192
}
187193

188194
pub fn tick(&mut self) {
@@ -200,6 +206,12 @@ impl App {
200206
match self.input_mode {
201207
InputMode::Normal => match key.code {
202208
KeyCode::Char('q') => Action::Quit,
209+
KeyCode::Char('j') if key.modifiers.contains(crossterm::event::KeyModifiers::CONTROL) => {
210+
Action::ScrollDown
211+
}
212+
KeyCode::Char('k') if key.modifiers.contains(crossterm::event::KeyModifiers::CONTROL) => {
213+
Action::ScrollUp
214+
}
203215
KeyCode::Char('j') => {
204216
self.next();
205217
Action::None

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ fn main() -> Result<()> {
275275
}
276276
}
277277
}
278+
Action::ScrollUp => {
279+
app.preview_scroll = app.preview_scroll.saturating_sub(1);
280+
}
281+
Action::ScrollDown => {
282+
app.preview_scroll = app.preview_scroll.saturating_add(1);
283+
}
278284
Action::None => {}
279285
}
280286
}

src/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pub fn ui(f: &mut Frame, app: &mut App) {
7575

7676
let lines: Vec<Line> = content
7777
.lines()
78-
.take(100)
7978
.map(|line| {
8079
if line.starts_with("# ") {
8180
Line::from(Span::styled(
@@ -146,6 +145,7 @@ pub fn ui(f: &mut Frame, app: &mut App) {
146145
.border_type(BorderType::Rounded)
147146
.border_style(Style::default().fg(ACCENT_COLOR)),
148147
)
148+
.scroll((app.preview_scroll, 0))
149149
.wrap(Wrap { trim: false });
150150

151151
f.render_widget(preview, preview_chunks[0]);

0 commit comments

Comments
 (0)