From f406701a9466ef32c935a274787adc9cbcbef188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20G=C5=82uchowski?= Date: Thu, 5 Dec 2024 18:43:22 +0100 Subject: [PATCH] Add comment and check for newline before multiline layout --- crates/epaint/src/text/fonts.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/epaint/src/text/fonts.rs b/crates/epaint/src/text/fonts.rs index 75dcf1958cc..f2fe70db0be 100644 --- a/crates/epaint/src/text/fonts.rs +++ b/crates/epaint/src/text/fonts.rs @@ -762,7 +762,11 @@ impl GalleyCache { cached.galley.clone() } std::collections::hash_map::Entry::Vacant(entry) => { - if job.break_on_newline { + // If the text contains newlines that will always break into a new row then + // we can easily lay out all the lines separately and then merge the `Galley`s. + // This allows individual lines to be cached separately which means small + // modifications to the source text will only cause impacted lines to be laid out again. + if job.break_on_newline && job.text.contains('\n') { let galley = self.layout_multiline(fonts, job); let galley = Arc::new(galley); self.cache.insert(