colors #6
@ -80,6 +80,8 @@ pub(super) fn editor_view_ui(ui: &mut egui::Ui, app: &mut TextEditor) -> egui::R
|
||||
let show_shortcuts = app.show_shortcuts;
|
||||
let word_wrap = app.word_wrap;
|
||||
let font_size = app.font_size;
|
||||
let font_id = app.get_font_id();
|
||||
let syntax_highlighting_enabled = app.syntax_highlighting;
|
||||
|
||||
let reset_zoom_key = egui::Id::new("editor_reset_zoom");
|
||||
let should_reset_zoom = ui
|
||||
@ -164,26 +166,29 @@ pub(super) fn editor_view_ui(ui: &mut egui::Ui, app: &mut TextEditor) -> egui::R
|
||||
f32::INFINITY
|
||||
};
|
||||
|
||||
// Determine the language for syntax highlighting
|
||||
let language = get_language_from_extension(active_tab.file_path.as_deref());
|
||||
|
||||
// Create a code theme based on the current system theme visuals
|
||||
let theme = create_code_theme_from_visuals(ui.visuals(), font_size);
|
||||
|
||||
let mut layouter = |ui: &egui::Ui, string: &dyn egui::TextBuffer, wrap_width: f32| {
|
||||
let text = string.as_str();
|
||||
let mut layout_job = if language == "txt" {
|
||||
syntax_highlighting::highlight(ui.ctx(), &ui.style().clone(), &theme, text, "")
|
||||
} else {
|
||||
let mut layout_job = if syntax_highlighting_enabled && language != "txt" {
|
||||
syntax_highlighting::highlight(ui.ctx(), &ui.style().clone(), &theme, text, &language)
|
||||
} else {
|
||||
syntax_highlighting::highlight(ui.ctx(), &ui.style().clone(), &theme, text, "")
|
||||
};
|
||||
|
||||
if syntax_highlighting_enabled && language != "txt" {
|
||||
for section in &mut layout_job.sections {
|
||||
section.format.font_id = font_id.clone();
|
||||
}
|
||||
}
|
||||
|
||||
layout_job.wrap.max_width = wrap_width;
|
||||
ui.fonts(|f| f.layout_job(layout_job))
|
||||
};
|
||||
|
||||
let text_edit = egui::TextEdit::multiline(&mut active_tab.content)
|
||||
.frame(false)
|
||||
.font(egui::TextStyle::Monospace)
|
||||
.code_editor()
|
||||
.desired_width(desired_width)
|
||||
.desired_rows(0)
|
||||
|
||||
@ -185,6 +185,10 @@ pub(crate) fn menu_bar(app: &mut TextEditor, ctx: &egui::Context) {
|
||||
app.save_config();
|
||||
ui.close_kind(UiKind::Menu);
|
||||
}
|
||||
if ui.checkbox(&mut app.syntax_highlighting, "Syntax Highlighting").clicked() {
|
||||
app.save_config();
|
||||
ui.close_kind(UiKind::Menu);
|
||||
}
|
||||
if ui.checkbox(&mut app.word_wrap, "Word Wrap").clicked() {
|
||||
app.save_config();
|
||||
ui.close_kind(UiKind::Menu);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user