mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 18:39:45 +00:00
Fix #377: truncate long lines for better performance
This commit is contained in:
@@ -25,6 +25,7 @@ using System.Windows.Threading;
|
|||||||
using ICSharpCode.AvalonEdit;
|
using ICSharpCode.AvalonEdit;
|
||||||
using ICSharpCode.AvalonEdit.Document;
|
using ICSharpCode.AvalonEdit.Document;
|
||||||
using ICSharpCode.AvalonEdit.Highlighting;
|
using ICSharpCode.AvalonEdit.Highlighting;
|
||||||
|
using ICSharpCode.AvalonEdit.Rendering;
|
||||||
using QuickLook.Common.Helpers;
|
using QuickLook.Common.Helpers;
|
||||||
using QuickLook.Common.Plugin;
|
using QuickLook.Common.Plugin;
|
||||||
using UtfUnknown;
|
using UtfUnknown;
|
||||||
@@ -46,6 +47,8 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
WordWrap = true;
|
WordWrap = true;
|
||||||
IsReadOnly = true;
|
IsReadOnly = true;
|
||||||
IsManipulationEnabled = true;
|
IsManipulationEnabled = true;
|
||||||
|
Options.EnableEmailHyperlinks = false;
|
||||||
|
Options.EnableHyperlinks = false;
|
||||||
|
|
||||||
ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting;
|
ManipulationInertiaStarting += Viewer_ManipulationInertiaStarting;
|
||||||
ManipulationStarting += Viewer_ManipulationStarting;
|
ManipulationStarting += Viewer_ManipulationStarting;
|
||||||
@@ -55,6 +58,8 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
|
|
||||||
FontFamily = new FontFamily(TranslationHelper.Get("Editor_FontFamily"));
|
FontFamily = new FontFamily(TranslationHelper.Get("Editor_FontFamily"));
|
||||||
|
|
||||||
|
TextArea.TextView.ElementGenerators.Add(new TruncateLongLines());
|
||||||
|
|
||||||
LoadFileAsync(path);
|
LoadFileAsync(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +97,29 @@ namespace QuickLook.Plugin.TextViewer
|
|||||||
e.Mode = ManipulationModes.Translate;
|
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)
|
private void LoadFileAsync(string path)
|
||||||
{
|
{
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
|
Reference in New Issue
Block a user