|
1 | | -use crate::common::MARGIN; |
2 | 1 | use crate::config; |
3 | 2 |
|
4 | 3 | use glib::IsA; |
@@ -90,12 +89,23 @@ impl DrawCtx { |
90 | 89 | tag_a.set_foreground(Some("blue")); |
91 | 90 | tag_a.set_underline(gtk::pango::Underline::Low); |
92 | 91 |
|
| 92 | + let tag_pre = DrawCtx::create_tag( |
| 93 | + "pre", |
| 94 | + self.config |
| 95 | + .fonts |
| 96 | + .preformatted |
| 97 | + .as_ref() |
| 98 | + .unwrap_or(&config::Fonts::default_preformatted()), |
| 99 | + ); |
| 100 | + tag_pre.set_wrap_mode(gtk::WrapMode::None); |
| 101 | + |
93 | 102 | tag_table.add(&tag_h1); |
94 | 103 | tag_table.add(&tag_h2); |
95 | 104 | tag_table.add(&tag_h3); |
96 | 105 | tag_table.add(&tag_q); |
97 | 106 | tag_table.add(&tag_p); |
98 | 107 | tag_table.add(&tag_a); |
| 108 | + tag_table.add(&tag_pre); |
99 | 109 | tag_table |
100 | 110 | } |
101 | 111 | pub fn create_tag(name: &str, config: &crate::config::Font) -> gtk::TextTag { |
@@ -133,39 +143,14 @@ impl DrawCtx { |
133 | 143 | } |
134 | 144 |
|
135 | 145 | pub fn insert_preformatted(&self, text_iter: &mut gtk::TextIter, line: &str) { |
136 | | - let nested_view = { |
137 | | - let text_view = gtk::TextView::new(); |
138 | | - let text_buffer = text_view.buffer(); |
139 | | - |
140 | | - let tag_pre = DrawCtx::create_tag( |
141 | | - "pre", |
142 | | - self.config |
143 | | - .fonts |
144 | | - .preformatted |
145 | | - .as_ref() |
146 | | - .unwrap_or(&config::Fonts::default_preformatted()), |
147 | | - ); |
148 | | - tag_pre.set_wrap_mode(gtk::WrapMode::None); |
149 | | - |
150 | | - text_buffer.tag_table().add(&tag_pre); |
151 | | - text_buffer.insert(&mut text_buffer.end_iter(), line); |
152 | | - text_buffer.apply_tag_by_name( |
153 | | - "pre", |
154 | | - text_buffer.iter_at_line_index(0, 0).as_ref().unwrap(), |
155 | | - &text_buffer.end_iter(), |
156 | | - ); |
157 | | - text_view |
158 | | - }; |
159 | | - |
160 | | - let scrolled_window = gtk::ScrolledWindow::new(); |
161 | | - scrolled_window.set_child(Some(&nested_view)); |
162 | | - scrolled_window.set_vscrollbar_policy(gtk::PolicyType::Never); |
163 | | - self.insert_widget(text_iter, &scrolled_window); |
| 146 | + let start = text_iter.offset(); |
| 147 | + self.text_buffer.insert(text_iter, line); |
| 148 | + self.text_buffer.apply_tag_by_name( |
| 149 | + "pre", |
| 150 | + &self.text_buffer.iter_at_offset(start), |
| 151 | + text_iter, |
| 152 | + ); |
164 | 153 |
|
165 | | - let text_view = self.text_view.clone(); |
166 | | - self.text_view.connect_width_request_notify(move |_| { |
167 | | - scrolled_window.set_width_request(text_view.allocated_width() - MARGIN * 2) |
168 | | - }); |
169 | 154 | self.text_buffer.insert(text_iter, "\n"); |
170 | 155 | } |
171 | 156 | pub fn insert_paragraph(&self, text_iter: &mut gtk::TextIter, line: &str) { |
|
0 commit comments