diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs index 0b125ab..327bdd2 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs @@ -25,6 +25,7 @@ using System.Windows.Threading; using ICSharpCode.AvalonEdit; using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Highlighting; +using ICSharpCode.AvalonEdit.Rendering; using QuickLook.Common.Helpers; using QuickLook.Common.Plugin; using UtfUnknown; @@ -46,6 +47,8 @@ namespace QuickLook.Plugin.TextViewer WordWrap = true; IsReadOnly = true; IsManipulationEnabled = true; + Options.EnableEmailHyperlinks = false; + Options.EnableHyperlinks = false; ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting; ManipulationStarting += Viewer_ManipulationStarting; @@ -55,6 +58,8 @@ namespace QuickLook.Plugin.TextViewer FontFamily = new FontFamily(TranslationHelper.Get("Editor_FontFamily")); + TextArea.TextView.ElementGenerators.Add(new TruncateLongLines()); + LoadFileAsync(path); } @@ -92,6 +97,29 @@ namespace QuickLook.Plugin.TextViewer e.Mode = ManipulationModes.Translate; } + private class TruncateLongLines : VisualLineElementGenerator + { + const int maxLength = 10000; + const string ellipsis = "……………"; + + public override int GetFirstInterestedOffset(int startOffset) + { + var line = CurrentContext.VisualLine.LastDocumentLine; + if (line.Length > maxLength) + { + int ellipsisOffset = line.Offset + maxLength - ellipsis.Length; + if (startOffset <= ellipsisOffset) + return ellipsisOffset; + } + return -1; + } + + public override VisualLineElement ConstructElement(int offset) + { + return new FormattedTextElement(ellipsis, CurrentContext.VisualLine.LastDocumentLine.EndOffset - offset); + } + } + private void LoadFileAsync(string path) { Task.Run(() =>