// Token: 0x06003C07 RID: 15367 RVA: 0x0011500C File Offset: 0x0011320C
 internal TextSegment(ITextPointer startPosition, ITextPointer endPosition, bool preserveLogicalDirection)
 {
     ValidationHelper.VerifyPositionPair(startPosition, endPosition);
     if (startPosition.CompareTo(endPosition) == 0)
     {
         this._start = startPosition.GetFrozenPointer(startPosition.LogicalDirection);
         this._end   = this._start;
         return;
     }
     Invariant.Assert(startPosition.CompareTo(endPosition) < 0);
     this._start = startPosition.GetFrozenPointer(preserveLogicalDirection ? startPosition.LogicalDirection : LogicalDirection.Backward);
     this._end   = endPosition.GetFrozenPointer(preserveLogicalDirection ? endPosition.LogicalDirection : LogicalDirection.Forward);
 }
 // Token: 0x06005B55 RID: 23381 RVA: 0x0019C11A File Offset: 0x0019A31A
 internal SpellingError(Speller speller, ITextPointer start, ITextPointer end)
 {
     Invariant.Assert(start.CompareTo(end) < 0);
     this._speller = speller;
     this._start   = start.GetFrozenPointer(LogicalDirection.Forward);
     this._end     = end.GetFrozenPointer(LogicalDirection.Backward);
 }
Exemplo n.º 3
0
        //-----------------------------------------------------
        //
        //  Constructors 
        //
        //----------------------------------------------------- 
 
        #region Constructors
 
        // Creates a new instance.
        internal SpellingError(Speller speller, ITextPointer start, ITextPointer end)
        {
            Invariant.Assert(start.CompareTo(end) < 0); 

            _speller = speller; 
            _start = start.GetFrozenPointer(LogicalDirection.Forward); 
            _end = end.GetFrozenPointer(LogicalDirection.Backward);
        } 
 // Token: 0x060037C2 RID: 14274 RVA: 0x000F9046 File Offset: 0x000F7246
 internal TextContainerChangeEventArgs(ITextPointer textPosition, int count, int charCount, TextChangeType textChange, DependencyProperty property, bool affectsRenderOnly)
 {
     this._textPosition      = textPosition.GetFrozenPointer(LogicalDirection.Forward);
     this._count             = count;
     this._charCount         = charCount;
     this._textChange        = textChange;
     this._property          = property;
     this._affectsRenderOnly = affectsRenderOnly;
 }
 internal TextContainerChangeEventArgs(ITextPointer textPosition, int count, int charCount, TextChangeType textChange, DependencyProperty property, bool affectsRenderOnly) 
 {
     _textPosition = textPosition.GetFrozenPointer(LogicalDirection.Forward); 
     _count = count; 
     _charCount = charCount;
     _textChange = textChange; 
     _property = property;
     _affectsRenderOnly = affectsRenderOnly;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="startPosition">
        /// Position preceeding the TextSegment's content.
        /// </param>
        /// <param name="endPosition">
        /// Position following the TextSegment's content.
        /// </param>
        /// <param name="preserveLogicalDirection">
        /// Whether preserves LogicalDirection of start and end positions.
        /// </param>
        internal TextSegment(ITextPointer startPosition, ITextPointer endPosition, bool preserveLogicalDirection)
        {
            ValidationHelper.VerifyPositionPair(startPosition, endPosition);

            if (startPosition.CompareTo(endPosition) == 0)
            {
                // To preserve segment emptiness
                // we use the same instance of a pointer
                // for both segment ends.
                _start = startPosition.GetFrozenPointer(startPosition.LogicalDirection);
                _end   = _start;
            }
            else
            {
                Invariant.Assert(startPosition.CompareTo(endPosition) < 0);
                _start = startPosition.GetFrozenPointer(preserveLogicalDirection ? startPosition.LogicalDirection : LogicalDirection.Backward);
                _end   = endPosition.GetFrozenPointer(preserveLogicalDirection ? endPosition.LogicalDirection : LogicalDirection.Forward);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="startPosition">
        /// Position preceeding the TextSegment's content.
        /// </param>
        /// <param name="endPosition">
        /// Position following the TextSegment's content.
        /// </param>
        /// <param name="preserveLogicalDirection">
        /// Whether preserves LogicalDirection of start and end positions.
        /// </param>
        internal TextSegment(ITextPointer startPosition, ITextPointer endPosition, bool preserveLogicalDirection)
        {
            ValidationHelper.VerifyPositionPair(startPosition, endPosition);

            if (startPosition.CompareTo(endPosition) == 0)
            {
                // To preserve segment emptiness
                // we use the same instance of a pointer
                // for both segment ends.
                _start = startPosition.GetFrozenPointer(startPosition.LogicalDirection);
                _end = _start;
            }
            else
            {
                Invariant.Assert(startPosition.CompareTo(endPosition) < 0);
                _start = startPosition.GetFrozenPointer(preserveLogicalDirection ? startPosition.LogicalDirection : LogicalDirection.Backward);
                _end = endPosition.GetFrozenPointer(preserveLogicalDirection ? endPosition.LogicalDirection : LogicalDirection.Forward);
            }
        }
 // Token: 0x06002FC0 RID: 12224 RVA: 0x000D6E30 File Offset: 0x000D5030
 internal void SetCompositionPositions(ITextPointer start, ITextPointer end, string text)
 {
     Invariant.Assert(start != null);
     Invariant.Assert(end != null);
     Invariant.Assert(text != null);
     this._compositionStart = start.GetFrozenPointer(LogicalDirection.Backward);
     this._compositionEnd   = end.GetFrozenPointer(LogicalDirection.Forward);
     this._resultStart      = null;
     this._resultEnd        = null;
     base.Text            = string.Empty;
     base.CompositionText = text;
     this._offset         = ((this._compositionStart == null) ? -1 : this._compositionStart.Offset);
     this._length         = ((this._compositionStart == null) ? -1 : this._compositionStart.GetOffsetToPosition(this._compositionEnd));
 }
Exemplo n.º 9
0
        // Set composition string to TextComposition.
        internal void SetCompositionPositions(ITextPointer start, ITextPointer end, string text)
        {
            Invariant.Assert(start != null);
            Invariant.Assert(end != null);
            Invariant.Assert(text != null);

            // We need to have another instances of TextPointer since we don't want to
            // freeze original TextPointers.
            _compositionStart = start.GetFrozenPointer(LogicalDirection.Backward);
            _compositionEnd   = end.GetFrozenPointer(LogicalDirection.Forward);

            _resultStart = null;
            _resultEnd   = null;

            this.Text            = String.Empty;
            this.CompositionText = text;

            // We must cache integer offsets -- public listeners won't expect
            // them to float like TextPointers if the document changes.
            _offset = (_compositionStart == null) ? -1 : _compositionStart.Offset;
            _length = (_compositionStart == null) ? -1 : _compositionStart.GetOffsetToPosition(_compositionEnd);
        }
Exemplo n.º 10
0
        /// <summary>
        /// <see cref="ITextView.GetPositionAtNextLine"/>
        /// </summary>
        ITextPointer ITextView.GetPositionAtNextLine(ITextPointer position, double suggestedX, int count, out double newSuggestedX, out int linesMoved)
        {
            Invariant.Assert(this.IsLayoutValid);
            Invariant.Assert(Contains(position));

            newSuggestedX = suggestedX;
            int lineIndex = GetLineIndexFromPosition(position);
            int nextLineIndex = Math.Max(0, Math.Min(_lineMetrics.Count - 1, lineIndex + count));
            linesMoved = nextLineIndex - lineIndex;

            ITextPointer nextLinePosition;
            if (linesMoved == 0)
            {
                nextLinePosition = position.GetFrozenPointer(position.LogicalDirection);
            }
            else if (DoubleUtil.IsNaN(suggestedX))
            {
                nextLinePosition = _host.TextContainer.CreatePointerAtOffset(_lineMetrics[lineIndex + linesMoved].Offset, LogicalDirection.Forward);
            }
            else
            {
                suggestedX -= GetTextAlignmentCorrection(this.CalculatedTextAlignment, GetWrappingWidth(this.RenderSize.Width));
                nextLinePosition = GetTextPositionFromDistance(nextLineIndex, suggestedX);
            }

            nextLinePosition.Freeze();
            return nextLinePosition;
        }
 internal Run(ITextPointer position, RunType runType)
 {
     _position = position.GetFrozenPointer(LogicalDirection.Backward);
     _runType = runType;
 }
Exemplo n.º 12
0
            // Creates a new instance. 
            // contextStart/End refer to the whole run of text.
            // contentStart/End are a subset of the text, which is what
            // the engine will actually tag with errors.
            // The space between context and content is used by the engine 
            // to correctly analyze multiple word phrase like "Los Angeles"
            // that could otherwise be truncated and incorrectly tagged. 
            internal TextMap(ITextPointer contextStart, ITextPointer contextEnd, 
                ITextPointer contentStart, ITextPointer contentEnd)
            { 
                ITextPointer position;
                int maxChars;
                int inlineCount;
                int runCount; 
                int i;
                int distance; 
 
                Invariant.Assert(contextStart.CompareTo(contentStart) <= 0);
                Invariant.Assert(contextEnd.CompareTo(contentEnd) >= 0); 

                _basePosition = contextStart.GetFrozenPointer(LogicalDirection.Backward);

                position = contextStart.CreatePointer(); 
                maxChars = contextStart.GetOffsetToPosition(contextEnd);
 
                _text = new char[maxChars]; 
                _positionMap = new int[maxChars+1];
 
                _textLength = 0;
                inlineCount = 0;

                _contentStartOffset = 0; 
                _contentEndOffset = 0;
 
                // Iterate over the run, building up a matching plain text buffer 
                // and a table that tells us how to map back to the original text.
                while (position.CompareTo(contextEnd) < 0) 
                {
                    if (position.CompareTo(contentStart) == 0)
                    {
                        _contentStartOffset = _textLength; 
                    }
                    if (position.CompareTo(contentEnd) == 0) 
                    { 
                        _contentEndOffset = _textLength;
                    } 

                    switch (position.GetPointerContext(LogicalDirection.Forward))
                    {
                        case TextPointerContext.Text: 
                            runCount = position.GetTextRunLength(LogicalDirection.Forward);
                            runCount = Math.Min(runCount, _text.Length - _textLength); 
                            runCount = Math.Min(runCount, position.GetOffsetToPosition(contextEnd)); 

                            position.GetTextInRun(LogicalDirection.Forward, _text, _textLength, runCount); 

                            for (i = _textLength; i < _textLength + runCount; i++)
                            {
                                _positionMap[i] = i + inlineCount; 
                            }
 
                            distance = position.GetOffsetToPosition(contentStart); 
                            if (distance >= 0 && distance <= runCount)
                            { 
                                _contentStartOffset = _textLength + position.GetOffsetToPosition(contentStart);
                            }
                            distance = position.GetOffsetToPosition(contentEnd);
                            if (distance >= 0 && distance <= runCount) 
                            {
                                _contentEndOffset = _textLength + position.GetOffsetToPosition(contentEnd); 
                            } 

                            position.MoveByOffset(runCount); 
                            _textLength += runCount;
                            break;

                        case TextPointerContext.ElementStart: 
                        case TextPointerContext.ElementEnd:
                            if (IsAdjacentToFormatElement(position)) 
                            { 
                                // Filter out formatting tags from the plain text.
                                inlineCount++; 
                            }
                            else
                            {
                                // Stick in a word break to account for the block element. 
                                _text[_textLength] = ' ';
                                _positionMap[_textLength] = _textLength + inlineCount; 
                                _textLength++; 
                            }
                            position.MoveToNextContextPosition(LogicalDirection.Forward); 
                            break;

                        case TextPointerContext.EmbeddedElement:
                            _text[_textLength] = '\xf8ff'; // Unicode private use. 
                            _positionMap[_textLength] = _textLength + inlineCount;
                            _textLength++; 
 
                            position.MoveToNextContextPosition(LogicalDirection.Forward);
                            break; 
                    }
                }

                if (position.CompareTo(contentEnd) == 0) 
                {
                    _contentEndOffset = _textLength; 
                } 

                if (_textLength > 0) 
                {
                    _positionMap[_textLength] = _positionMap[_textLength - 1] + 1;
                }
                else 
                {
                    _positionMap[0] = 0; 
                } 

                Invariant.Assert(_contentStartOffset <= _contentEndOffset); 
            }
Exemplo n.º 13
0
        /// <summary>
        /// <see cref="ITextView.GetBackspaceCaretUnitPosition"/>
        /// </summary>
        ITextPointer ITextView.GetBackspaceCaretUnitPosition(ITextPointer position)
        {
            Invariant.Assert(this.IsLayoutValid);
            Invariant.Assert(Contains(position));

            // Special case document start.
            if (position.Offset == 0)
            {
                return position.GetFrozenPointer(LogicalDirection.Forward);
            }

            int lineIndex = GetLineIndexFromPosition(position, LogicalDirection.Backward);

            CharacterHit sourceCharacterHit = new CharacterHit(position.Offset, 0);
            CharacterHit backspaceCharacterHit;

            using (TextBoxLine line = GetFormattedLine(lineIndex))
            {
                backspaceCharacterHit = line.GetBackspaceCaretCharacterHit(sourceCharacterHit);
            }

            LogicalDirection logicalDirection;
            if (backspaceCharacterHit.FirstCharacterIndex + backspaceCharacterHit.TrailingLength == _lineMetrics[lineIndex].Offset)
            {
                // Going backward brought us to the start of a line, context must be backward for previous line
                if (lineIndex == 0)
                {
                    // First line, so we will stay forward.
                    logicalDirection = LogicalDirection.Forward;
                }
                else
                {
                    logicalDirection = LogicalDirection.Backward;
                }
            }
            else
            {
                logicalDirection = (backspaceCharacterHit.TrailingLength > 0) ? LogicalDirection.Backward : LogicalDirection.Forward;
            }

            ITextPointer backspaceUnitPosition = _host.TextContainer.CreatePointerAtOffset(backspaceCharacterHit.FirstCharacterIndex + backspaceCharacterHit.TrailingLength, logicalDirection);
            backspaceUnitPosition.Freeze();
            return backspaceUnitPosition;
        }
Exemplo n.º 14
0
        /// <summary>
        /// <see cref="ITextView.GetNextCaretUnitPosition"/>
        /// </summary>
        ITextPointer ITextView.GetNextCaretUnitPosition(ITextPointer position, LogicalDirection direction)
        {
            Invariant.Assert(this.IsLayoutValid);
            Invariant.Assert(Contains(position));

            // Special case document start/end.
            if (position.Offset == 0 && direction == LogicalDirection.Backward)
            {
                return position.GetFrozenPointer(LogicalDirection.Forward);
            }
            else if (position.Offset == _host.TextContainer.SymbolCount && direction == LogicalDirection.Forward)
            {
                return position.GetFrozenPointer(LogicalDirection.Backward);
            }

            int lineIndex = GetLineIndexFromPosition(position);

            CharacterHit sourceCharacterHit = new CharacterHit(position.Offset, 0);
            CharacterHit nextCharacterHit;

            using (TextBoxLine line = GetFormattedLine(lineIndex))
            {
                if (direction == LogicalDirection.Forward)
                {
                    // Get the next caret position from the line
                    nextCharacterHit = line.GetNextCaretCharacterHit(sourceCharacterHit);
                }
                else
                {
                    // Get previous caret position from the line
                    nextCharacterHit = line.GetPreviousCaretCharacterHit(sourceCharacterHit);
                }
            }

            // Determine logical direction for next caret index and create TextPointer from it.
            LogicalDirection logicalDirection;
            if (nextCharacterHit.FirstCharacterIndex + nextCharacterHit.TrailingLength == _lineMetrics[lineIndex].EndOffset &&
                direction == LogicalDirection.Forward)
            {
                // Going forward brought us to the end of a line, context must be forward for next line.
                if (lineIndex == _lineMetrics.Count - 1)
                {
                    // Last line so context must stay backward.
                    logicalDirection = LogicalDirection.Backward;
                }
                else
                {
                    logicalDirection = LogicalDirection.Forward;
                }
            }
            else if (nextCharacterHit.FirstCharacterIndex + nextCharacterHit.TrailingLength == _lineMetrics[lineIndex].Offset &&
                     direction == LogicalDirection.Backward)
            {
                // Going backward brought us to the start of a line, context must be backward for previous line.
                if (lineIndex == 0)
                {
                    // First line, so we will stay forward.
                    logicalDirection = LogicalDirection.Forward;
                }
                else
                {
                    logicalDirection = LogicalDirection.Backward;
                }
            }
            else
            {
                logicalDirection = (nextCharacterHit.TrailingLength > 0) ? LogicalDirection.Backward : LogicalDirection.Forward;
            }

            ITextPointer nextCaretUnitPosition = _host.TextContainer.CreatePointerAtOffset(nextCharacterHit.FirstCharacterIndex + nextCharacterHit.TrailingLength, logicalDirection);
            nextCaretUnitPosition.Freeze();
            return nextCaretUnitPosition;
        }
Exemplo n.º 15
0
 // Token: 0x06008593 RID: 34195 RVA: 0x00249D84 File Offset: 0x00247F84
 internal Run(ITextPointer position, SpellerStatusTable.RunType runType)
 {
     this._position = position.GetFrozenPointer(LogicalDirection.Backward);
     this._runType  = runType;
 }
        // Helper for OnSelectDownByLine.  Updates the selection moving position
        // during select down by line.
        private static void AdjustMovingPositionForSelectDownByLine(TextEditor This, ITextPointer newMovingPosition, ITextPointer originalMovingPosition, double suggestedX)
        {
            int newComparedToOld = newMovingPosition.CompareTo(originalMovingPosition);

            // Note: we compare orientations of equal positions to handle a case
            // when original position was at the end of line (after its linebreak with backward orientation)
            // as a result of Shift+End selection; and the new position is in the beginning of the next line,
            // which is essentially the same position but oriented differently.
            // In such a case the new position is good enough to go there.
            // We certainly don't want to go to the end of the document in this case.
            if (newComparedToOld > 0 || newComparedToOld == 0 && newMovingPosition.LogicalDirection != originalMovingPosition.LogicalDirection)
            {
                // We have another line in a given direction; move to it

                // If the destination exactly preceeds a line break, expand to include
                // the line break if we haven't reached our desired suggestedX.
                if (TextPointerBase.IsNextToAnyBreak(newMovingPosition, LogicalDirection.Forward) ||
                    newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null)
                {
                    double newPositionX = GetAbsoluteXOffset(This.TextView, newMovingPosition);
                    FlowDirection paragraphFlowDirection = GetScopingParagraphFlowDirection(newMovingPosition);
                    FlowDirection controlFlowDirection = This.UiScope.FlowDirection;

                    if ((paragraphFlowDirection == controlFlowDirection && newPositionX < suggestedX) ||
                        (paragraphFlowDirection != controlFlowDirection && newPositionX > suggestedX))
                    {
                        newMovingPosition = newMovingPosition.GetInsertionPosition(LogicalDirection.Forward);
                        newMovingPosition = newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward);

                        // If we're at the last Paragraph, move to document end to include
                        // the final paragraph break.
                        if (newMovingPosition == null)
                        {
                            newMovingPosition = originalMovingPosition.TextContainer.End;
                        }

                        newMovingPosition = newMovingPosition.GetFrozenPointer(LogicalDirection.Backward);
                    }
                }

                ExtendSelectionAndBringIntoView(newMovingPosition, This);
            }
            else
            {
                // Remember where we were so that we can return if a line up follows.
                if (This._NextLineAdvanceMovingPosition == null)
                {
                    This._NextLineAdvanceMovingPosition = originalMovingPosition;
                    This._IsNextLineAdvanceMovingPositionAtDocumentHead = false;
                }

                // No more lines in this direction. Move to end of current line.
                newMovingPosition = GetPositionAtLineEnd(originalMovingPosition);

                if (newMovingPosition.GetNextInsertionPosition(LogicalDirection.Forward) == null)
                {
                    // Move to the final implicit line at end-of-doc.
                    newMovingPosition = newMovingPosition.TextContainer.End;
                }

                ExtendSelectionAndBringIntoView(newMovingPosition, This);
            }
        }
Exemplo n.º 17
0
        // Set composition string to TextComposition.
        internal void SetCompositionPositions(ITextPointer start, ITextPointer end, string text)
        {
            Invariant.Assert(start != null);
            Invariant.Assert(end != null);
            Invariant.Assert(text != null);

            // We need to have another instances of TextPointer since we don't want to
            // freeze original TextPointers.
            _compositionStart = start.GetFrozenPointer(LogicalDirection.Backward);
            _compositionEnd = end.GetFrozenPointer(LogicalDirection.Forward);

            _resultStart = null;
            _resultEnd = null;

            this.Text = String.Empty;
            this.CompositionText = text;

            // We must cache integer offsets -- public listeners won't expect
            // them to float like TextPointers if the document changes.
            _offset = (_compositionStart == null) ? -1 : _compositionStart.Offset;
            _length = (_compositionStart == null) ? -1 : _compositionStart.GetOffsetToPosition(_compositionEnd);
        }
 internal Run(ITextPointer position, RunType runType)
 {
     _position = position.GetFrozenPointer(LogicalDirection.Backward);
     _runType  = runType;
 }