From 0eebd1c85d6c052a954dab6251cadb7da3ab4a67 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 10 Mar 2026 18:31:12 +0200 Subject: [PATCH] update list `State` api --- .../page/content/text/markdown/tags/list.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/app/browser/window/tab/item/page/content/text/markdown/tags/list.rs b/src/app/browser/window/tab/item/page/content/text/markdown/tags/list.rs index d05548df..fc142275 100644 --- a/src/app/browser/window/tab/item/page/content/text/markdown/tags/list.rs +++ b/src/app/browser/window/tab/item/page/content/text/markdown/tags/list.rs @@ -7,22 +7,20 @@ use regex::Regex; const REGEX_LIST: &str = r"(?m)^(?P[ \t]*)\*[ \t]+(?:(?P\[[ xX]\])[ \t]+)?(?P.*)"; -struct State { - pub is_checked: bool, - //tag: TextTag, -} +struct State(bool); impl State { fn parse(value: Option<&str>) -> Option { if let Some(state) = value && (state.starts_with("[ ]") || state.starts_with("[x]")) { - return Some(Self { - is_checked: state.starts_with("[x]"), - }); + return Some(Self(state.starts_with("[x]"))); } None } + fn is_checked(&self) -> bool { + self.0 + } } struct Item { @@ -79,7 +77,7 @@ pub fn render(buffer: &TextBuffer) { if let Some(state) = item.state { buffer.insert_with_tags( &mut start_iter, - if state.is_checked { "[x] " } else { "[ ] " }, + if state.is_checked() { "[x] " } else { "[ ] " }, &[&state_tag], ); } @@ -134,13 +132,13 @@ fn test_regex() { { let item = item(&cap, 5); assert_eq!(item.level, 2); - assert!(item.state.is_some_and(|this| this.is_checked)); + assert!(item.state.is_some_and(|this| this.is_checked())); assert_eq!(item.text, "list item 3.1"); } { let item = item(&cap, 6); assert_eq!(item.level, 2); - assert!(item.state.is_some_and(|this| !this.is_checked)); + assert!(item.state.is_some_and(|this| !this.is_checked())); assert_eq!(item.text, "list item 3.2"); } {