From 6d81d61cc5e1c6d23d7871b8d0abad2785ed6b5c Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Sun, 10 Jan 2021 14:56:38 +0100 Subject: [PATCH] Fix #787: add CTRL-F search bar. --- .../QuickLook.Plugin.TextViewer/TextViewerPanel.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs index f139f65..94d9bb8 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.TextViewer/TextViewerPanel.cs @@ -27,6 +27,7 @@ using ICSharpCode.AvalonEdit; using ICSharpCode.AvalonEdit.Document; using ICSharpCode.AvalonEdit.Highlighting; using ICSharpCode.AvalonEdit.Rendering; +using ICSharpCode.AvalonEdit.Search; using QuickLook.Common.Helpers; using QuickLook.Common.Plugin; using UtfUnknown; @@ -67,6 +68,8 @@ namespace QuickLook.Plugin.TextViewer TextArea.TextView.ElementGenerators.Add(new TruncateLongLines()); + SearchPanel.Install(this); + LoadFileAsync(path); } @@ -106,15 +109,15 @@ namespace QuickLook.Plugin.TextViewer private class TruncateLongLines : VisualLineElementGenerator { - const int maxLength = 10000; - const string ellipsis = "……………"; + const int MAX_LENGTH = 10000; + const string ELLIPSIS = "……………"; public override int GetFirstInterestedOffset(int startOffset) { var line = CurrentContext.VisualLine.LastDocumentLine; - if (line.Length > maxLength) + if (line.Length > MAX_LENGTH) { - int ellipsisOffset = line.Offset + maxLength - ellipsis.Length; + int ellipsisOffset = line.Offset + MAX_LENGTH - ELLIPSIS.Length; if (startOffset <= ellipsisOffset) return ellipsisOffset; } @@ -123,7 +126,7 @@ namespace QuickLook.Plugin.TextViewer public override VisualLineElement ConstructElement(int offset) { - return new FormattedTextElement(ellipsis, CurrentContext.VisualLine.LastDocumentLine.EndOffset - offset); + return new FormattedTextElement(ELLIPSIS, CurrentContext.VisualLine.LastDocumentLine.EndOffset - offset); } }