From cbaf6361731121ceed8ceba4d33802ae9ea31661 Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Tue, 6 Jul 2021 21:19:52 +0200 Subject: [PATCH] set syntax highlighting limit to 512KB --- .../QuickLook.Plugin.TextViewer/TextViewerPanel.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs index 5d706e0..f1c9b77 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs @@ -144,12 +144,13 @@ namespace QuickLook.Plugin.TextViewer Task.Run(() => { const int maxLength = 5 * 1024 * 1024; + const int maxHighlightingLength = (int) (0.5 * 1024 * 1024); var buffer = new MemoryStream(); - bool tooLong; + bool fileTooLong; using (var s = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { - tooLong = s.Length > maxLength; + fileTooLong = s.Length > maxLength; while (s.Position < s.Length && buffer.Length < maxLength) { if (_disposed) @@ -164,7 +165,7 @@ namespace QuickLook.Plugin.TextViewer if (_disposed) return; - if (tooLong) + if (fileTooLong) _context.Title += " (0 ~ 5MB)"; var bufferCopy = buffer.ToArray(); @@ -182,7 +183,7 @@ namespace QuickLook.Plugin.TextViewer Dispatcher.BeginInvoke(new Action(() => { Encoding = encoding; - SyntaxHighlighting = tooLong + SyntaxHighlighting = bufferCopy.Length > maxHighlightingLength ? null : HighlightingManager.Instance.GetDefinitionByExtension(Path.GetExtension(path)); Document = doc;