From bdab2d2ded5aefcff2f72c40cc136f0ddcc35f5b Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 17 Dec 2024 03:30:55 +0200 Subject: [PATCH] define plain text tag once --- .../tab/item/page/content/text/gemini/reader.rs | 5 +---- .../item/page/content/text/gemini/reader/tag.rs | 6 ++++++ .../page/content/text/gemini/reader/tag/plain.rs | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/plain.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs index ed72172e..e3b417ad 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs @@ -302,10 +302,7 @@ impl Reader { // Nothing match custom tags above, // just append plain text covered in empty tag (to handle controller events properly) - let tag = TextTag::builder().wrap_mode(WrapMode::Word).build(); // @TODO single shared - - buffer.tag_table().add(&tag); - buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag]); + buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag.plain.text_tag]); buffer.insert(&mut buffer.end_iter(), NEW_LINE); } diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs index 72b99c29..a9e31579 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs @@ -2,6 +2,7 @@ mod h1; mod h2; mod h3; mod list; +mod plain; mod quote; mod title; @@ -9,6 +10,7 @@ use h1::H1; use h2::H2; use h3::H3; use list::List; +use plain::Plain; use quote::Quote; use title::Title; @@ -23,6 +25,7 @@ pub struct Tag { pub list: List, pub quote: Quote, pub title: Title, + pub plain: Plain, } impl Tag { @@ -35,6 +38,7 @@ impl Tag { let list = List::new(); let quote = Quote::new(); let title = Title::new(); + let plain = Plain::new(); // Init tag table let text_tag_table = TextTagTable::new(); @@ -45,6 +49,7 @@ impl Tag { text_tag_table.add(&title.text_tag); text_tag_table.add(&list.text_tag); text_tag_table.add("e.text_tag); + text_tag_table.add(&plain.text_tag); Self { text_tag_table, @@ -55,6 +60,7 @@ impl Tag { list, quote, title, + plain, } } } diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/plain.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/plain.rs new file mode 100644 index 00000000..01be2a8d --- /dev/null +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/plain.rs @@ -0,0 +1,14 @@ +use gtk::{TextTag, WrapMode}; + +pub struct Plain { + pub text_tag: TextTag, +} + +impl Plain { + // Construct + pub fn new() -> Self { + Self { + text_tag: TextTag::builder().wrap_mode(WrapMode::Word).build(), + } + } +}