Exemplo n.º 1
0
        internal void RaiseChangedEvent(bool emptyBefore, bool emptyAfter, bool moved)
        {
            if (moved || (emptyBefore != emptyAfter))
            {
                //Force the selected spans to be recomputed (if needed).
                _virtualSelectedSpans = null;
                _selectedSpans        = null;
            }

            if (moved || !(emptyBefore && emptyAfter))
            {
                // Inform listeners of this change
                _guardedOperations.RaiseEvent(this, SelectionChanged);
            }
        }
Exemplo n.º 2
0
        private void InternalMoveCaret(VirtualSnapshotPoint bufferPosition, PositionAffinity caretAffinity, ITextViewLine textLine, bool captureHorizontalPosition, bool captureVerticalPosition, bool raiseEvent)
        {
            CaretPosition oldPosition = this.Position;

            _caretAffinity     = caretAffinity;
            _insertionPoint    = bufferPosition;
            _forceVirtualSpace = _insertionPoint.IsInVirtualSpace && !this.IsVirtualSpaceOrBoxSelectionEnabled;

            _emptySelection    = _wpfTextView.Selection.IsEmpty;
            _isContainedByView = (textLine.VisibilityState != VisibilityState.Unattached);

            double xCoordinate;
            double width;

            if (bufferPosition.IsInVirtualSpace || textLine.End == bufferPosition.Position)
            {
                //Never show overwrite caret when at the physical end of a line.
                this.OverwriteMode = false;
            }
            else
            {
                //Position is in the interior of the line ... preferred position is based strictly on the bufferPosition.
                this.OverwriteMode = _wpfTextView.Options.IsOverwriteModeEnabled() && _emptySelection;
            }

            // if we're in overwrite mode, draw a rectangle covering the text element, otherwise, just
            // draw a thin line
            if (_overwriteMode)
            {
                Microsoft.VisualStudio.Text.Formatting.TextBounds bounds = textLine.GetExtendedCharacterBounds(bufferPosition);
                xCoordinate = bounds.Left;
                width       = bounds.Width;
            }
            else
            {
                xCoordinate = GetXCoordinateFromVirtualBufferPosition(textLine, bufferPosition);

                width = 10;//TODO: SystemParameters.CaretWidth;
            }

            _bounds = new SKRect((float)xCoordinate, (float)textLine.TextTop, (float)(xCoordinate + width), (float)textLine.TextBottom);
            CapturePreferredPositions(captureHorizontalPosition, captureVerticalPosition);

            CaretPosition newPosition = this.Position;

            if (newPosition != oldPosition)
            {
                this.UpdateBlinkTimer();

                if (raiseEvent)
                {
                    if (_selection.IsEmpty)
                    {
                        //Empty selections are logically located at the caret position, so force a selection changed event to be raised
                        //before any of the caret position changed events.
                        _selection.RaiseChangedEvent(emptyBefore: true, emptyAfter: true, moved: true);
                    }

                    // Inform this change to interested parties
                    EventHandler <CaretPositionChangedEventArgs> positionChanged = this.PositionChanged;
                    if (positionChanged != null)
                    {
                        _guardedOperations.RaiseEvent <CaretPositionChangedEventArgs>(this, positionChanged, new CaretPositionChangedEventArgs(_wpfTextView, oldPosition, newPosition));
                    }
                }
            }

            this.InvalidateVisual();
            _updateNeeded = true;
        }