/// <summary>
        /// Initializes a new instance of the <see cref="LinkReferenceTrackerPostProcessor"/> class, and executes the post-processor
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="updateSequenceNumber">A number that is increased every time the source document changed.</param>
        /// <param name="imageProvider">The image provider. Can be null (in this case nothing is tracked).</param>
        public static void TrackLinks(MarkdownDocument document, long updateSequenceNumber, IWpfImageProvider imageProvider)
        {
            var urlCollector = imageProvider?.CreateUrlCollector();

            if (null != urlCollector)
            {
                foreach (var element in PositionHelper.EnumerateAllMarkdownObjectsRecursively(document))
                {
                    if (element is LinkInline linkInline)
                    {
                        if (linkInline.UrlSpan.HasValue)
                        {
                            urlCollector.AddUrl(linkInline.IsImage, linkInline.Url, linkInline.UrlSpan.Value.Start, linkInline.UrlSpan.Value.End);
                        }
                    }
                }
                urlCollector.Freeze(); // announce that the collection proccess has finished
                imageProvider.UpdateUrlCollector(urlCollector, updateSequenceNumber);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the start and end line/column positions (1-based) of the selection. If no selection is active, the position of the caret is returned; in this case start and end line/column positions are the same.
        /// </summary>
        /// <returns>Start and end line/column positions (1-based) of the selection or the caret. If it can not be retrieved, the tuple (0, 0, 0, 0) is returned.</returns>
        private (int startline, int startcolumn, int endline, int endcolumn) GetSelectionOrCaret()
        {
            if (IsViewerSelected)
            {
                var(sourceStart, isSourceStartAccurate) = PositionHelper.ViewersTextPositionToSourceEditorsTextPosition(_guiViewer.Selection.Start);
                var(sourceEnd, isSourceEndAccurate)     = PositionHelper.ViewersTextPositionToSourceEditorsTextPosition(_guiViewer.Selection.End);

                if (isSourceStartAccurate && isSourceEndAccurate)
                {
                    var startLocation = _guiEditor.Document.GetLocation(sourceStart);
                    var endLocation   = _guiEditor.Document.GetLocation(sourceEnd);

                    return(startLocation.Line, startLocation.Column, endLocation.Line, endLocation.Column);
                }
                else
                {
                    return(0, 0, 0, 0);
                }
            }
            else // Editor is selected
            {
                int selectionStart = 0;
                int selectionEnd   = 0;

                if (_guiEditor.SelectionLength > 0)
                {
                    selectionStart = _guiEditor.SelectionStart;
                    selectionEnd   = _guiEditor.SelectionStart + _guiEditor.SelectionLength;
                }
                else
                {
                    selectionStart = _guiEditor.CaretOffset;
                    selectionEnd   = _guiEditor.CaretOffset;
                }

                var startLocation = _guiEditor.Document.GetLocation(selectionStart);
                var endLocation   = _guiEditor.Document.GetLocation(selectionEnd);

                return(startLocation.Line, startLocation.Column, endLocation.Line, endLocation.Column);
            }
        }