define plain text tag once

This commit is contained in:
yggverse 2024-12-17 03:30:55 +02:00
parent b0d4cf03c8
commit bdab2d2ded
3 changed files with 21 additions and 4 deletions

View File

@ -302,10 +302,7 @@ impl Reader {
// Nothing match custom tags above, // Nothing match custom tags above,
// just append plain text covered in empty tag (to handle controller events properly) // 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.insert_with_tags(&mut buffer.end_iter(), line, &[&tag.plain.text_tag]);
buffer.tag_table().add(&tag);
buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag]);
buffer.insert(&mut buffer.end_iter(), NEW_LINE); buffer.insert(&mut buffer.end_iter(), NEW_LINE);
} }

View File

@ -2,6 +2,7 @@ mod h1;
mod h2; mod h2;
mod h3; mod h3;
mod list; mod list;
mod plain;
mod quote; mod quote;
mod title; mod title;
@ -9,6 +10,7 @@ use h1::H1;
use h2::H2; use h2::H2;
use h3::H3; use h3::H3;
use list::List; use list::List;
use plain::Plain;
use quote::Quote; use quote::Quote;
use title::Title; use title::Title;
@ -23,6 +25,7 @@ pub struct Tag {
pub list: List, pub list: List,
pub quote: Quote, pub quote: Quote,
pub title: Title, pub title: Title,
pub plain: Plain,
} }
impl Tag { impl Tag {
@ -35,6 +38,7 @@ impl Tag {
let list = List::new(); let list = List::new();
let quote = Quote::new(); let quote = Quote::new();
let title = Title::new(); let title = Title::new();
let plain = Plain::new();
// Init tag table // Init tag table
let text_tag_table = TextTagTable::new(); let text_tag_table = TextTagTable::new();
@ -45,6 +49,7 @@ impl Tag {
text_tag_table.add(&title.text_tag); text_tag_table.add(&title.text_tag);
text_tag_table.add(&list.text_tag); text_tag_table.add(&list.text_tag);
text_tag_table.add(&quote.text_tag); text_tag_table.add(&quote.text_tag);
text_tag_table.add(&plain.text_tag);
Self { Self {
text_tag_table, text_tag_table,
@ -55,6 +60,7 @@ impl Tag {
list, list,
quote, quote,
title, title,
plain,
} }
} }
} }

View File

@ -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(),
}
}
}