Beispiel #1
0
        /// <summary>
        /// Gets the start and end positions (0-based) of the selection.
        /// If no selection is active, the position of the caret is returned; in this case start and end positions are the same.
        /// </summary>
        /// <returns>Start and end positions (0-based) of the selection or the caret. If it can not be retrieved, the tuple (-1, -1) is returned.</returns>
        private (int selectionStartPosition, int selectionEndPosition) GetSelectionStartAndEndPosition()
        {
            if (IsViewerSelected)
            {
                var(sourceStart, isSourceStartAccurate) = PositionHelper.ViewersTextPositionToSourceEditorsTextPosition(_guiViewer.Selection.Start);
                var(sourceEnd, isSourceEndAccurate)     = PositionHelper.ViewersTextPositionToSourceEditorsTextPosition(_guiViewer.Selection.End);

                if (isSourceStartAccurate && isSourceEndAccurate)
                {
                    return(sourceStart, sourceEnd);
                }
                else
                {
                    return(-1, -1);
                }
            }
            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;
                }

                return(selectionStart, selectionEnd);
            }
        }
Beispiel #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);
            }
        }