From 7fb72f4d99df97d906cd984a4a7202f7d1434dcc Mon Sep 17 00:00:00 2001 From: Phil Date: Sat, 31 Oct 2026 19:58:46 -0600 Subject: [PATCH] Soft-wrap the note body Co-Authored-By: Claude Opus 5.5 --- src/app.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/app.rs b/src/app.rs index 3c32e1b..7028f6f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,7 +2,7 @@ use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use ratatui::style::{Modifier, Style}; -use ratatui_textarea::{Input, Key, TextArea}; +use ratatui_textarea::{Input, Key, TextArea, WrapMode}; use crate::micropub::{self, Error, Note, ServerConfig, SyndicationTarget}; use crate::worker::{Request, Response}; @@ -78,13 +78,20 @@ fn text_area(placeholder: &str) -> TextArea<'static> { t } +/// The note body: soft-wraps at word boundaries (long words such as URLs break mid-word). +fn content_area() -> TextArea<'static> { + let mut t = text_area("What's on your mind? (Markdown)"); + t.set_wrap_mode(WrapMode::WordOrGlyph); + t +} + impl App { pub fn new(me: String, endpoint: String) -> Self { let mut app = App { me, endpoint, title: text_area("Optional title"), - content: text_area("What's on your mind? (Markdown)"), + content: content_area(), tags: text_area("Comma-separated, e.g. rust, indieweb"), targets: Vec::new(), targets_state: Targets::Loading, @@ -124,7 +131,7 @@ impl App { fn clear_form(&mut self) { self.title = text_area("Optional title"); - self.content = text_area("What's on your mind? (Markdown)"); + self.content = content_area(); self.tags = text_area("Comma-separated, e.g. rust, indieweb"); self.focus = Focus::Content; self.update_cursors(); @@ -436,6 +443,15 @@ mod tests { assert_eq!(app.mode, Mode::Editing); } + #[test] + fn content_wraps_and_keeps_wrapping_after_publish() { + let mut app = loaded(&[]); + assert_eq!(app.content.wrap_mode(), WrapMode::WordOrGlyph); + assert_eq!(app.title.wrap_mode(), WrapMode::None); + app.handle_response(Response::Published(Ok("u".into()))); + assert_eq!(app.content.wrap_mode(), WrapMode::WordOrGlyph); + } + #[test] fn title_enter_moves_to_content() { let mut app = loaded(&[]);