From 9fb83d35414cc026adb7faca72e39adb7e7edb3f Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 22 Jan 2024 14:47:58 +0100 Subject: [PATCH] Use a selectable label for syntax-highlighted text in egui_extras --- crates/egui_extras/src/syntax_highlighting.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/crates/egui_extras/src/syntax_highlighting.rs b/crates/egui_extras/src/syntax_highlighting.rs index 4d1859b9..5bb6605b 100644 --- a/crates/egui_extras/src/syntax_highlighting.rs +++ b/crates/egui_extras/src/syntax_highlighting.rs @@ -11,23 +11,11 @@ use egui::text::LayoutJob; pub fn code_view_ui( ui: &mut egui::Ui, theme: &CodeTheme, - mut code: &str, + code: &str, language: &str, ) -> egui::Response { - let mut layouter = |ui: &egui::Ui, string: &str, _wrap_width: f32| { - let layout_job = highlight(ui.ctx(), theme, string, language); - // layout_job.wrap.max_width = wrap_width; // no wrapping - ui.fonts(|f| f.layout_job(layout_job)) - }; - - ui.add( - egui::TextEdit::multiline(&mut code) - .font(egui::TextStyle::Monospace) // for cursor height - .code_editor() - .desired_rows(1) - .lock_focus(true) - .layouter(&mut layouter), - ) + let layout_job = highlight(ui.ctx(), theme, code, language); + ui.add(egui::Label::new(layout_job).selectable(true)) } /// Add syntax highlighting to a code string.