Exemplo n.º 1
0
        /// <summary>
        /// Gets the document offset (relative to the first line start) from a visual column.
        /// </summary>
        public int GetRelativeOffset(int visualColumn)
        {
            ThrowUtil.CheckNotNegative(visualColumn, "visualColumn");
            int documentLength = 0;

            foreach (VisualLineElement element in elements)
            {
                if (element.VisualColumn <= visualColumn &&
                    element.VisualColumn + element.VisualLength > visualColumn)
                {
                    return(element.GetRelativeOffset(visualColumn));
                }
                documentLength += element.DocumentLength;
            }
            return(documentLength);
        }
Exemplo n.º 2
0
 internal void RemoveSelectedText()
 {
     if (this.Document == null)
     {
         throw ThrowUtil.NoDocumentAssigned();
     }
     selection.ReplaceSelectionWithText(string.Empty);
                 #if DEBUG
     if (!selection.IsEmpty)
     {
         foreach (ISegment s in selection.Segments)
         {
             Debug.Assert(this.ReadOnlySectionProvider.GetDeletableSegments(s).Count() == 0);
         }
     }
                 #endif
 }
Exemplo n.º 3
0
        static void MoveCaretToStartOfLine(TextArea textArea, VisualLine visualLine)
        {
            int newVC = visualLine.GetNextCaretPosition(-1, LogicalDirection.Forward, CaretPositioningMode.WordStart);

            if (newVC < 0)
            {
                throw ThrowUtil.NoValidCaretPosition();
            }
            // when the caret is already at the start of the text, jump to start before whitespace
            if (newVC == textArea.Caret.VisualColumn)
            {
                newVC = 0;
            }
            int offset = visualLine.FirstDocumentLine.Offset + visualLine.GetRelativeOffset(newVC);

            SetCaretPosition(textArea, newVC, offset);
        }
Exemplo n.º 4
0
 /// <inheritdoc/>
 public HighlightedLine HighlightLine(int lineNumber)
 {
     ThrowUtil.CheckInRangeInclusive(lineNumber, "lineNumber", 1, document.LineCount);
     CheckIsHighlighting();
     isHighlighting = true;
     try
     {
         HighlightUpTo(lineNumber - 1);
         IDocumentLine   line   = document.GetLineByNumber(lineNumber);
         HighlightedLine result = engine.HighlightLine(document, line);
         UpdateTreeList(lineNumber);
         return(result);
     }
     finally
     {
         isHighlighting = false;
     }
 }
Exemplo n.º 5
0
 /// <inheritdoc/>
 public SpanStack GetSpanStack(int lineNumber)
 {
     ThrowUtil.CheckInRangeInclusive(lineNumber, "lineNumber", 0, document.LineCount);
     if (firstInvalidLine <= lineNumber)
     {
         CheckIsHighlighting();
         isHighlighting = true;
         try
         {
             HighlightUpTo(lineNumber + 1);
         }
         finally
         {
             isHighlighting = false;
         }
     }
     return(storedSpanStacks[lineNumber]);
 }
Exemplo n.º 6
0
 /// <inheritdoc/>
 public HighlightedLine HighlightLine(int lineNumber)
 {
     ThrowUtil.CheckInRangeInclusive(lineNumber, "lineNumber", 1, document.LineCount);
     CheckIsHighlighting();
     isHighlighting = true;
     try
     {
         HighlightUpTo(lineNumber);
         DocumentLine line = document.GetLineByNumber(lineNumber);
         highlightedLine = new HighlightedLine(document, line);
         HighlightLineAndUpdateTreeList(line, lineNumber);
         return(highlightedLine);
     }
     finally
     {
         highlightedLine = null;
         isHighlighting  = false;
     }
 }
        public static bool TryFind <T>(this IReadOnlyList <T> list, Predicate <T> match, out T result)
#endif
        {
            ThrowUtil.ThrowIfArgumentNull(list);
            ThrowUtil.ThrowIfArgumentNull(match);

            result = default;

            foreach (var item in list)
            {
                if (match(item))
                {
                    result = item;
                    return(true);
                }
            }

            return(false);
        }
        static TextViewPosition GetStartOfLineCaretPosition(int oldVC, VisualLine visualLine, TextLine textLine, bool enableVirtualSpace)
        {
            int newVC = visualLine.GetTextLineVisualStartColumn(textLine);

            if (newVC == 0)
            {
                newVC = visualLine.GetNextCaretPosition(newVC - 1, LogicalDirection.Forward, CaretPositioningMode.WordStart, enableVirtualSpace);
            }
            if (newVC < 0)
            {
                throw ThrowUtil.NoValidCaretPosition();
            }
            // when the caret is already at the start of the text, jump to start before whitespace
            if (newVC == oldVC)
            {
                newVC = 0;
            }
            return(visualLine.GetTextViewPosition(newVC));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Gets the text line containing the specified visual column.
 /// </summary>
 public TextLine GetTextLine(int visualColumn)
 {
     ThrowUtil.CheckInRangeInclusive(visualColumn, "visualColumn", 0, VisualLength);
     if (visualColumn == VisualLength)
     {
         return(TextLines[TextLines.Count - 1]);
     }
     foreach (TextLine line in TextLines)
     {
         if (visualColumn < line.Length)
         {
             return(line);
         }
         else
         {
             visualColumn -= line.Length;
         }
     }
     throw new InvalidOperationException("Shouldn't happen (VisualLength incorrect?)");
 }
Exemplo n.º 10
0
        public static void SwapItem <T>(this IList <T> list, int targetIndex, Func <T, bool> predicate)
        {
            ThrowUtil.ThrowIfArgumentNull(list);
            ThrowUtil.ThrowIfArgumentNull(predicate);
            if (targetIndex >= list.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(targetIndex));
            }

            var index = list.FindIndex(predicate);

            if (index < 0 || index == targetIndex)
            {
                return;
            }

            T v = list[targetIndex];

            list[targetIndex] = list[index];
            list[index]       = v;
        }
Exemplo n.º 11
0
 internal void ReplaceSelectionWithText(string newText)
 {
     if (newText == null)
     {
         throw new ArgumentNullException("newText");
     }
     if (this.Document == null)
     {
         throw ThrowUtil.NoDocumentAssigned();
     }
     using (this.Document.RunUpdate()) {
         RemoveSelectedText();
         if (newText.Length > 0)
         {
             if (ReadOnlySectionProvider.CanInsert(Caret.Offset))
             {
                 this.Document.Insert(Caret.Offset, newText);
             }
         }
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the selected text.
        /// </summary>
        public virtual string GetText()
        {
            var document = textArea.Document;

            if (document == null)
            {
                throw ThrowUtil.NoDocumentAssigned();
            }
            StringBuilder b    = null;
            string        text = null;

            foreach (ISegment s in Segments)
            {
                if (text != null)
                {
                    if (b == null)
                    {
                        b = new StringBuilder(text);
                    }
                    else
                    {
                        b.Append(text);
                    }
                }
                text = document.GetText(s);
            }
            if (b != null)
            {
                if (text != null)
                {
                    b.Append(text);
                }
                return(b.ToString());
            }
            else
            {
                return(text ?? string.Empty);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new DocumentChangeEventArgs object.
        /// </summary>
        public DocumentChangeEventArgs(int offset, string removedText, string insertedText, OffsetChangeMap offsetChangeMap)
        {
            ThrowUtil.CheckNotNegative(offset, "offset");
            ThrowUtil.CheckNotNull(removedText, "removedText");
            ThrowUtil.CheckNotNull(insertedText, "insertedText");

            Offset       = offset;
            RemovedText  = removedText;
            InsertedText = insertedText;

            if (offsetChangeMap != null)
            {
                if (!offsetChangeMap.IsFrozen)
                {
                    throw new ArgumentException("The OffsetChangeMap must be frozen before it can be used in DocumentChangeEventArgs");
                }
                if (!offsetChangeMap.IsValidForDocumentChange(offset, removedText.Length, insertedText.Length))
                {
                    throw new ArgumentException("OffsetChangeMap is not valid for this document change", nameof(offsetChangeMap));
                }
                this.offsetChangeMap = offsetChangeMap;
            }
        }
Exemplo n.º 14
0
        /// <inheritdoc/>
        public Matrix GetDMatrixAt(Element targetElement, params double[] isoCoords)
        {
            var elm = targetElement as BarElement;

            if (elm == null)
            {
                throw new Exception();
            }

            var xi = isoCoords[0];

            var geo  = elm.Section.GetCrossSectionPropertiesAt(xi);
            var mech = elm.Material.GetMaterialPropertiesAt(xi);

            var buf = new Matrix(1, 1);

            ThrowUtil.ThrowIf(!CalcUtil.IsIsotropicMaterial(mech), "anistropic material not impolemented yet");

            var g = mech.Ex / (2 * (1 + mech.NuXy));

            buf.FillRow(0, geo.J * g);

            return(buf);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Validates the visual column of the caret using the specified visual line.
        /// The visual line must contain the caret offset.
        /// </summary>
        void RevalidateVisualColumn(VisualLine visualLine)
        {
            if (visualLine == null)
            {
                throw new ArgumentNullException("visualLine");
            }

            // mark column as validated
            visualColumnValid = true;

            int caretOffset             = textView.Document.GetOffset(position.Location);
            int firstDocumentLineOffset = visualLine.FirstDocumentLine.Offset;

            position.VisualColumn = visualLine.ValidateVisualColumn(position, textArea.Selection.EnableVirtualSpace);

            // search possible caret positions
            int newVisualColumnForwards = visualLine.GetNextCaretPosition(position.VisualColumn - 1, LogicalDirection.Forward, CaretPositioningMode.Normal, textArea.Selection.EnableVirtualSpace);

            // If position.VisualColumn was valid, we're done with validation.
            if (newVisualColumnForwards != position.VisualColumn)
            {
                // also search backwards so that we can pick the better match
                int newVisualColumnBackwards = visualLine.GetNextCaretPosition(position.VisualColumn + 1, LogicalDirection.Backward, CaretPositioningMode.Normal, textArea.Selection.EnableVirtualSpace);

                if (newVisualColumnForwards < 0 && newVisualColumnBackwards < 0)
                {
                    throw ThrowUtil.NoValidCaretPosition();
                }

                // determine offsets for new visual column positions
                int newOffsetForwards;
                if (newVisualColumnForwards >= 0)
                {
                    newOffsetForwards = visualLine.GetRelativeOffset(newVisualColumnForwards) + firstDocumentLineOffset;
                }
                else
                {
                    newOffsetForwards = -1;
                }
                int newOffsetBackwards;
                if (newVisualColumnBackwards >= 0)
                {
                    newOffsetBackwards = visualLine.GetRelativeOffset(newVisualColumnBackwards) + firstDocumentLineOffset;
                }
                else
                {
                    newOffsetBackwards = -1;
                }

                int newVisualColumn, newOffset;
                // if there's only one valid position, use it
                if (newVisualColumnForwards < 0)
                {
                    newVisualColumn = newVisualColumnBackwards;
                    newOffset       = newOffsetBackwards;
                }
                else if (newVisualColumnBackwards < 0)
                {
                    newVisualColumn = newVisualColumnForwards;
                    newOffset       = newOffsetForwards;
                }
                else
                {
                    // two valid positions: find the better match
                    if (Math.Abs(newOffsetBackwards - caretOffset) < Math.Abs(newOffsetForwards - caretOffset))
                    {
                        // backwards is better
                        newVisualColumn = newVisualColumnBackwards;
                        newOffset       = newOffsetBackwards;
                    }
                    else
                    {
                        // forwards is better
                        newVisualColumn = newVisualColumnForwards;
                        newOffset       = newOffsetForwards;
                    }
                }
                this.Position = new TextViewPosition(textView.Document.GetLocation(newOffset), newVisualColumn);
            }
            isInVirtualSpace = (position.VisualColumn > visualLine.VisualLength);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Creates a new AnchorSegment that creates new anchors.
 /// </summary>
 public AnchorSegment(TextDocument document, ISegment segment)
     : this(document, ThrowUtil.CheckNotNull(segment, "segment").Offset, segment.Length)
 {
 }
Exemplo n.º 17
0
        public void AddMethod(MethodBase method, Func <object?>?objGetter = null)
        {
            ThrowUtil.ThrowIfArgumentNull(method);

            mMethods.Add(new Tuple <MethodSpecs, Func <object?>?, int>(new MethodSpecs(method), objGetter, 0));
        }