Soft-wrap the note body
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+19
-3
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||||
use ratatui::style::{Modifier, Style};
|
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::micropub::{self, Error, Note, ServerConfig, SyndicationTarget};
|
||||||
use crate::worker::{Request, Response};
|
use crate::worker::{Request, Response};
|
||||||
@@ -78,13 +78,20 @@ fn text_area(placeholder: &str) -> TextArea<'static> {
|
|||||||
t
|
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 {
|
impl App {
|
||||||
pub fn new(me: String, endpoint: String) -> Self {
|
pub fn new(me: String, endpoint: String) -> Self {
|
||||||
let mut app = App {
|
let mut app = App {
|
||||||
me,
|
me,
|
||||||
endpoint,
|
endpoint,
|
||||||
title: text_area("Optional title"),
|
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"),
|
tags: text_area("Comma-separated, e.g. rust, indieweb"),
|
||||||
targets: Vec::new(),
|
targets: Vec::new(),
|
||||||
targets_state: Targets::Loading,
|
targets_state: Targets::Loading,
|
||||||
@@ -124,7 +131,7 @@ impl App {
|
|||||||
|
|
||||||
fn clear_form(&mut self) {
|
fn clear_form(&mut self) {
|
||||||
self.title = text_area("Optional title");
|
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.tags = text_area("Comma-separated, e.g. rust, indieweb");
|
||||||
self.focus = Focus::Content;
|
self.focus = Focus::Content;
|
||||||
self.update_cursors();
|
self.update_cursors();
|
||||||
@@ -436,6 +443,15 @@ mod tests {
|
|||||||
assert_eq!(app.mode, Mode::Editing);
|
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]
|
#[test]
|
||||||
fn title_enter_moves_to_content() {
|
fn title_enter_moves_to_content() {
|
||||||
let mut app = loaded(&[]);
|
let mut app = loaded(&[]);
|
||||||
|
|||||||
Reference in New Issue
Block a user