From c84a85f6afead911bdf5f157311d16d35b7bc82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Mroche=C5=84?= Date: Wed, 6 May 2026 18:18:29 +0200 Subject: [PATCH] Allow setting of the font and font size used in the text viewer (#1930) * Allow setting of the font and font size used in the text viewer * Refactor font settings initialization * Clamp TextViewer font size from Settings --------- Co-authored-by: ema --- OPTIONS.md | 14 ++++++++++++++ .../QuickLook.Plugin.TextViewer/TextViewerPanel.cs | 10 +++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/OPTIONS.md b/OPTIONS.md index 9d7c429..7e0c9b6 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -237,6 +237,20 @@ These keys are also stored in `QuickLook.config`. - Example: - `True` +### `` +- Default: default font of the current language +- Type: `String` +- Description: Allow setting of the font used in the text viewer. +- Example: + - `Cascadia Mono SemiLight` + +### `` +- Default: 14.0 +- Type: `Double` +- Description: Allow setting of font size used in the text viewer. +- Example: + - `13` + ## Notes - All option names are case-sensitive and stored as XML element names under ``. diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs index a07c6e6..7952559 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs @@ -72,7 +72,6 @@ public partial class TextViewerPanel : TextEditor, IDisposable public TextViewerPanel() { - FontSize = 14; ShowLineNumbers = true; WordWrap = true; IsReadOnly = true; @@ -117,8 +116,13 @@ public partial class TextViewerPanel : TextEditor, IDisposable PreviewMouseWheel += Viewer_MouseWheel; - FontFamily = new FontFamily(TranslationHelper.Get("Editor_FontFamily", - domain: Assembly.GetExecutingAssembly().GetName().Name)); + // Read configured font size and validate it to avoid negative or unreasonable values + FontSize = Math.Max(1d, Math.Min(72d, SettingHelper.Get("FontSize", 14d, "QuickLook.Plugin.TextViewer"))); + FontFamily = new FontFamily( + SettingHelper.Get("FontFamily", + failsafe: TranslationHelper.Get("Editor_FontFamily", + domain: Assembly.GetExecutingAssembly().GetName().Name), + "QuickLook.Plugin.TextViewer")); // Add a custom element generator (e.g., to truncate extremely long lines). TextArea.TextView.ElementGenerators.Add(new TruncateLongLines());