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 <mccoy39082@163.com>
This commit is contained in:
Paweł Mrocheń
2026-05-06 18:18:29 +02:00
committed by GitHub
parent df71d1d287
commit c84a85f6af
2 changed files with 21 additions and 3 deletions
+14
View File
@@ -237,6 +237,20 @@ These keys are also stored in `QuickLook.config`.
- Example:
- `<AllowDarkTheme>True</AllowDarkTheme>`
### `<FontFamily>`
- Default: default font of the current language
- Type: `String`
- Description: Allow setting of the font used in the text viewer.
- Example:
- `<FontFamily>Cascadia Mono SemiLight</FontFamily>`
### `<FontSize>`
- Default: 14.0
- Type: `Double`
- Description: Allow setting of font size used in the text viewer.
- Example:
- `<FontSize>13</FontSize>`
## Notes
- All option names are case-sensitive and stored as XML element names under `<Settings>`.
@@ -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());