Skip to content

Commit b8856d8

Browse files
authored
Fix clicking of links in markdown (#8794)
### Related * Closes #8574 * Bug introduced in #8495 ### What The text document had a `response.interact(Sense::click())` call _on top_ of it, catching all clicks that should have ended up on the hyperlinks. This is now changed into setting `Sense::click` on the underlying `Ui` when creating it, meaning it will catch clicks _behind_ the hyperlinks, i.e. any click that doesn't interact with the document iteself.
1 parent 166068c commit b8856d8

File tree

1 file changed

+63
-57
lines changed

1 file changed

+63
-57
lines changed

crates/viewer/re_view_text_document/src/view_class.rs

+63-57
Original file line numberDiff line numberDiff line change
@@ -122,64 +122,22 @@ Displays text from a text component, as raw text or markdown."
122122
let state = state.downcast_mut::<TextDocumentViewState>()?;
123123
let text_document = system_output.view_systems.get::<TextDocumentSystem>()?;
124124

125-
let response = egui::Frame {
126-
inner_margin: re_ui::DesignTokens::view_padding().into(),
127-
..egui::Frame::default()
128-
}
129-
.show(ui, |ui| {
130-
ui.with_layout(egui::Layout::top_down(egui::Align::LEFT), |ui| {
131-
egui::ScrollArea::both()
132-
.auto_shrink([false, false])
133-
.show(ui, |ui| {
134-
if text_document.text_entries.is_empty() {
135-
// We get here if we scroll back time to before the first text document was logged.
136-
ui.weak("(empty)");
137-
} else if text_document.text_entries.len() == 1 {
138-
let TextDocumentEntry { body, media_type } =
139-
&text_document.text_entries[0];
140-
141-
if media_type == &re_types::components::MediaType::markdown() {
142-
re_tracing::profile_scope!("egui_commonmark");
143-
144-
// Make sure headers are big:
145-
ui.style_mut()
146-
.text_styles
147-
.entry(egui::TextStyle::Heading)
148-
.or_insert(egui::FontId::proportional(32.0))
149-
.size = 24.0;
150-
151-
egui_commonmark::CommonMarkViewer::new()
152-
.max_image_width(Some(ui.available_width().floor() as _))
153-
.show(ui, &mut state.commonmark_cache, body);
154-
return;
155-
}
156-
157-
let mut text = egui::RichText::new(body.as_str());
158-
159-
if state.monospace {
160-
text = text.monospace();
161-
}
162-
163-
ui.add(Label::new(text).wrap_mode(if state.word_wrap {
164-
egui::TextWrapMode::Wrap
165-
} else {
166-
egui::TextWrapMode::Extend
167-
}));
168-
} else {
169-
// TODO(jleibs): better handling for multiple results
170-
ui.error_label(format!(
171-
"Can only show one text document at a time; was given {}. Update \
172-
the query so that it returns a single text document and create \
173-
additional views for the others.",
174-
text_document.text_entries.len()
175-
));
176-
}
177-
})
125+
let frame = egui::Frame::new().inner_margin(re_ui::DesignTokens::view_padding());
126+
let response = frame
127+
.show(ui, |ui| {
128+
let inner_ui_builder = egui::UiBuilder::new()
129+
.layout(egui::Layout::top_down(egui::Align::LEFT))
130+
.sense(Sense::click());
131+
ui.allocate_new_ui(inner_ui_builder, |ui| {
132+
egui::ScrollArea::both()
133+
.auto_shrink([false, false])
134+
.show(ui, |ui| text_document_ui(ui, state, text_document));
135+
136+
ui.response()
137+
})
138+
.inner
178139
})
179-
.response
180-
})
181-
.response
182-
.interact(Sense::click());
140+
.inner;
183141

184142
if response.hovered() {
185143
ctx.selection_state().set_hovered(Item::View(query.view_id));
@@ -193,3 +151,51 @@ Displays text from a text component, as raw text or markdown."
193151
Ok(())
194152
}
195153
}
154+
155+
fn text_document_ui(
156+
ui: &mut egui::Ui,
157+
state: &mut TextDocumentViewState,
158+
text_document: &TextDocumentSystem,
159+
) {
160+
if text_document.text_entries.is_empty() {
161+
// We get here if we scroll back time to before the first text document was logged.
162+
ui.weak("(empty)");
163+
} else if text_document.text_entries.len() == 1 {
164+
let TextDocumentEntry { body, media_type } = &text_document.text_entries[0];
165+
166+
if media_type == &re_types::components::MediaType::markdown() {
167+
re_tracing::profile_scope!("egui_commonmark");
168+
169+
// Make sure headers are big:
170+
ui.style_mut()
171+
.text_styles
172+
.entry(egui::TextStyle::Heading)
173+
.or_insert(egui::FontId::proportional(32.0))
174+
.size = 24.0;
175+
176+
egui_commonmark::CommonMarkViewer::new()
177+
.max_image_width(Some(ui.available_width().floor() as _))
178+
.show(ui, &mut state.commonmark_cache, body);
179+
} else {
180+
let mut text = egui::RichText::new(body.as_str());
181+
182+
if state.monospace {
183+
text = text.monospace();
184+
}
185+
186+
ui.add(Label::new(text).wrap_mode(if state.word_wrap {
187+
egui::TextWrapMode::Wrap
188+
} else {
189+
egui::TextWrapMode::Extend
190+
}));
191+
}
192+
} else {
193+
// TODO(jleibs): better handling for multiple results
194+
ui.error_label(format!(
195+
"Can only show one text document at a time; was given {}. Update \
196+
the query so that it returns a single text document and create \
197+
additional views for the others.",
198+
text_document.text_entries.len()
199+
));
200+
}
201+
}

0 commit comments

Comments
 (0)