Skip to content

Commit

Permalink
Use a selectable label for syntax-highlighted text in egui_extras
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 22, 2024
1 parent ca6ce2d commit 9fb83d3
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions crates/egui_extras/src/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9fb83d3

Please sign in to comment.