diff --git a/Cargo.toml b/Cargo.toml index be02294..0863074 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "egui_code_editor" authors = ["Roman Chumak "] -version = "0.2.13" +version = "0.2.14" edition = "2021" license = "MIT" repository = "https://github.com/p4ymak/egui_code_editor" @@ -11,7 +11,7 @@ categories = ["gui", "text-editors"] keywords = ["egui", "GUI", "editor", "syntax", "highlighting"] [dependencies] -egui = { version = "0.31", optional = true } +egui = { version = "0.32", optional = true } serde = { version = "1", optional = true} [lib] @@ -33,5 +33,5 @@ name = "tui" test = true [dev-dependencies] -eframe = "0.31" +eframe = "0.32" colorful = "0.3" diff --git a/src/lib.rs b/src/lib.rs index e8048ba..2a96183 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -263,6 +263,8 @@ impl CodeEditor { #[cfg(feature = "egui")] fn numlines_show(&self, ui: &mut egui::Ui, text: &str) { + use egui::TextBuffer; + let total = if text.ends_with('\n') || text.is_empty() { text.lines().count() + 1 } else { @@ -295,9 +297,9 @@ impl CodeEditor { * 0.5 * !(total + self.numlines_shift <= 0 && self.numlines_only_natural) as u8 as f32; - let mut layouter = |ui: &egui::Ui, string: &str, _wrap_width: f32| { + let mut layouter = |ui: &egui::Ui, text_buffer: &dyn TextBuffer, _wrap_width: f32| { let layout_job = egui::text::LayoutJob::single_section( - string.to_string(), + text_buffer.as_str().to_string(), egui::TextFormat::simple( egui::FontId::monospace(self.fontsize), self.theme.type_color(TokenType::Comment(true)), @@ -321,6 +323,8 @@ impl CodeEditor { #[cfg(feature = "egui")] /// Show Code Editor pub fn show(&mut self, ui: &mut egui::Ui, text: &mut dyn egui::TextBuffer) -> TextEditOutput { + use egui::TextBuffer; + let mut text_edit_output: Option = None; let mut code_editor = |ui: &mut egui::Ui| { ui.horizontal_top(|h| { @@ -331,10 +335,11 @@ impl CodeEditor { egui::ScrollArea::horizontal() .id_salt(format!("{}_inner_scroll", self.id)) .show(h, |ui| { - let mut layouter = |ui: &egui::Ui, string: &str, _wrap_width: f32| { - let layout_job = highlight(ui.ctx(), self, string); - ui.fonts(|f| f.layout_job(layout_job)) - }; + let mut layouter = + |ui: &egui::Ui, text_buffer: &dyn TextBuffer, _wrap_width: f32| { + let layout_job = highlight(ui.ctx(), self, text_buffer.as_str()); + ui.fonts(|f| f.layout_job(layout_job)) + }; let output = egui::TextEdit::multiline(text) .id_source(&self.id) .lock_focus(true)