コード例 #1
0
        private static IHighlightingHandler MakeSelectionInplaceHighlightingHander(
            SelectionInfo selection, MessageTextGetter displayTextGetter, IWordSelection wordSelection, int cacheSize)
        {
            IHighlightingHandler newHandler = null;

            if (selection?.IsSingleLine == true)
            {
                var normSelection = selection.Normalize();
                var text          = displayTextGetter(normSelection.First.Message);
                var line          = text.GetNthTextLine(normSelection.First.TextLineIndex);
                int beginIdx      = normSelection.First.LineCharIndex;
                int endIdx        = normSelection.Last.LineCharIndex;
                var selectedPart  = line.SubString(beginIdx, endIdx - beginIdx);
                if (selectedPart.Any(c => !char.IsWhiteSpace(c)))
                {
                    var options = new Search.Options()
                    {
                        Template          = selectedPart,
                        MessageTextGetter = displayTextGetter,
                    };
                    var optionsPreprocessed = options.BeginSearch();
                    newHandler = new CachingHighlightingHandler(msg => GetSelectionHighlightingRanges(msg, optionsPreprocessed, wordSelection,
                                                                                                      (normSelection.First.Message, beginIdx + line.StartIndex - text.Text.StartIndex)), cacheSize);
                }
            }

            return(newHandler);
        }
コード例 #2
0
        void UpdateSelectionInplaceHighlightingFields()
        {
            Func <IMessage, IEnumerable <Tuple <int, int> > > newHandler = null;

            if (selection.IsSingleLine)
            {
                var normSelection = selection.Normalize();
                var line          = GetTextToDisplay(normSelection.First.Message).GetNthTextLine(normSelection.First.TextLineIndex);
                int beginIdx      = normSelection.First.LineCharIndex;
                int endIdx        = normSelection.Last.LineCharIndex;
                if (wordSelection.IsWordBoundary(line, beginIdx, endIdx))
                {
                    var selectedPart = line.SubString(beginIdx, endIdx - beginIdx);
                    if (wordSelection.IsWord(selectedPart))
                    {
                        var options = new Search.Options()
                        {
                            Template        = selectedPart,
                            SearchInRawText = presentationDataAccess.ShowRawMessages,
                        };
                        var optionsPreprocessed = options.BeginSearch();
                        newHandler = msg =>
                                     FindAllHightlighRanges(msg, optionsPreprocessed,
                                                            options.ReverseSearch, wordSelection);
                    }
                }
            }

            if ((selectionInplaceHighlightingHandler != null) != (newHandler != null))
            {
                view.Invalidate();
            }
            else if (newHandler != null)
            {
                view.Invalidate();
            }

            selectionInplaceHighlightingHandler = newHandler;
        }
コード例 #3
0
ファイル: SearchTest.cs プロジェクト: cxsun/logjoint
        void TestCore(string text, string template, Search.MatchedTextRange?expectation, int?startPosition = null, bool re = false, bool wholeWord = false, bool reverse = false)
        {
            Search.Options opts = new Search.Options()
            {
                Template      = template,
                Regexp        = re,
                WholeWord     = wholeWord,
                ReverseSearch = reverse
            };
            var actual = opts.BeginSearch().SearchInText(new StringSlice(text), startPosition);

            if (expectation != null)
            {
                Assert.IsTrue(actual != null);
                Assert.AreEqual(expectation.Value.MatchBegin, actual.Value.MatchBegin);
                Assert.AreEqual(expectation.Value.MatchEnd, actual.Value.MatchEnd);
                Assert.AreEqual(expectation.Value.WholeTextMatched, actual.Value.WholeTextMatched);
            }
            else
            {
                Assert.IsTrue(actual == null);
            }
        }