Ejemplo n.º 1
0
        void UpdateFocusedOccurrence()
        {
            LocalOccurrence selectedOccurrence;

            lock (mySyncRoot)
            {
                selectedOccurrence        = mySelectedOccurrence;
                myUpdateSelectedScheduled = false;
            }

            var documentMarkup = myMarkupManager.GetMarkupModel(myTextControl.Document);

            if (myShouldDropHighlightings)
            {
                var toRemove = new LocalList <IHighlighter>();
                foreach (var highlighter in documentMarkup.GetHighlightersEnumerable(GotoWordFocusedOccurrence))
                {
                    toRemove.Add(highlighter);
                }

                foreach (var highlighter in toRemove)
                {
                    documentMarkup.RemoveHighlighter(highlighter);
                }
            }

            if (selectedOccurrence != null)
            {
                var range = selectedOccurrence.Range.TextRange;
                documentMarkup.AddHighlighter(GotoWordFocusedOccurrence, range, AreaType.EXACT_RANGE, 0,
                                              CustomHighlightingManagerIds.NavigationHighlighterID, ErrorStripeAttributes.Empty, null);

                myShouldDropHighlightings = true;

                // todo: better positioning
                var position = Math.Max(selectedOccurrence.LineNumber - 2, 0);
                var target   = myTextControl.Coords.FromDocLineColumn(
                    new DocumentCoords((Int32 <DocLine>)position, (Int32 <DocColumn>) 0));
                myTextControl.Scrolling.ScrollTo(target, TextControlScrollType.TopOfView);
            }
            else
            {
                myTextControl.Scrolling.ScrollTo(myTextControlViewportRect.Location);
            }
        }
        public HighlightingTracker(Lifetime lifetime, ITextControlManager textControlManager,
                                   IDocumentMarkupManager markupManager, IViewable <IHighlightingChangeHandler> handlers)
        {
            textControlManager.TextControls.View(lifetime, (textControlLifetime, textControl) =>
            {
                var markupModel = markupManager.GetMarkupModel(textControl.Document);

                Action <DocumentMarkupModifiedEventArgs> onChanged = args =>
                {
                    Lifetimes.Using(l =>
                    {
                        handlers.View(l, (_, h) =>
                        {
                            h.OnHighlightingChanged(textControl.Document, args.Added, args.Removed, args.Modified);
                        });
                    });
                };

                markupModel.Changed += onChanged;
                textControlLifetime.AddAction(() => markupModel.Changed -= onChanged);
            });
        }
        private void UpdateHighlighting([NotNull] ITextControl textControl, TextRange expressionRange)
        {
            myThreading.ExecuteOrQueue(ChooserName, () =>
            {
                using (ReadLockCookie.Create())
                {
                    var documentMarkup = myMarkupManager.GetMarkupModel(textControl.Document);
                    foreach (var highlighter in documentMarkup.GetHighlightersEnumerable(HighlightingKey))
                    {
                        documentMarkup.RemoveHighlighter(highlighter);
                        break;
                    }

                    if (expressionRange.IsValid)
                    {
                        documentMarkup.AddHighlighter(
                            HighlightingKey, expressionRange, AreaType.LINES_IN_RANGE, 0,
                            HotspotSessionUi.CURRENT_HOTSPOT_HIGHLIGHTER,
                            ErrorStripeAttributes.Empty, null);
                    }
                }
            });
        }