Ejemplo n.º 1
0
        public void ResetSelection()
        {
            SelectionStart = null;
            SelectionEnd   = null;

            UpdateSelectionPolygon();
        }
Ejemplo n.º 2
0
        PolygonFigure[] CreateSelectionPolygons(SelectionAnchorCaret start, SelectionAnchorCaret end, out Rect bounds)
        {
            bounds = default;

            if (start == null || end == null)
            {
                return(null);
            }
            if (start.Anchor.Equals(end.Anchor))
            {
                return(null);
            }

            if (start.Anchor.CompareTo(end.Anchor) > 0) // swap when start > end
            {
                var _ = start;
                start = end;
                end   = _;
            }

            var content = Owner.Content;

            return(FilledFragment.CreatePolygons(
                       start.Bounds.TopLeft, end.Bounds.TopLeft, content.LineHeight,
                       content.SnapToPixelsX(content.Metrics.Viewport.Width - content.DpiScale.X), out bounds));
        }
Ejemplo n.º 3
0
        public void AdjustSelectionAnchors()
        {
            bool updated = false;

            SelectionStart = UpdateCaret(Owner.Content.SelectionStart, SelectionStart, ref updated);
            SelectionEnd   = UpdateCaret(Owner.Content.SelectionEnd, SelectionEnd, ref updated);

            if (updated)
            {
                UpdateSelectionPolygon();
            }
        }
Ejemplo n.º 4
0
        public void SetSelection(SelectionAnchorCaret start, SelectionAnchorCaret end)
        {
            if (start != null)
            {
                SelectionStart = start;
                Owner.Content.SelectionStart = start.Anchor;
            }

            SelectionEnd = end;
            Owner.Content.SelectionEnd = end.Anchor;

            UpdateSelectionPolygon();
        }
Ejemplo n.º 5
0
        public void SetSelection(SelectionAnchorCaret caret)
        {
            var content = Owner.Content;

            if (content.SelectionStart == null)
            {
                SetSelection(caret, caret);
            }
            else
            {
                SetSelection(null, caret);
            }
        }
Ejemplo n.º 6
0
        public bool TrySetSelection(Fragment fragment)
        {
            if (fragment.IsSelectable)
            {
                var caret = new SelectionAnchorCaret()
                {
                    Fragment = fragment
                };
                fragment.Source.PrepareSelectionAnchor(caret);
                SetSelection(caret);

                if (Owner.Mouse.SelectWholeChunks)
                {
                    SelectionStart = null;
                    SelectionEnd   = null;

                    var content = Owner.Content;

                    if (content.SelectionStart.CompareTo(content.SelectionEnd) > 0)
                    {
                        if (Owner.Content.SelectionStart.Chunk is Packet startPacket)
                        {
                            content.SelectionStart = new SelectionAnchor()
                            {
                                Chunk = content.SelectionStart.Chunk, Offset = startPacket.Payload.Length
                            };;
                            content.SelectionEnd.Offset = 0;
                        }
                    }
                    else
                    {
                        if (Owner.Content.SelectionEnd.Chunk is Packet endPacket)
                        {
                            content.SelectionStart.Offset = 0;
                            content.SelectionEnd          = new SelectionAnchor()
                            {
                                Chunk = content.SelectionEnd.Chunk, Offset = endPacket.Payload.Length
                            };
                        }
                    }

                    AdjustSelectionAnchors();
                }

                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        SelectionAnchorCaret UpdateCaret(SelectionAnchor anchor, SelectionAnchorCaret caret, ref bool updated)
        {
            if (anchor != null && caret == null)
            {
                updated = true;
                caret   = new SelectionAnchorCaret()
                {
                    Anchor = anchor
                };

                var content = Owner.Content;
                if (anchor.Chunk.SequenceNumber < content.TextLayer.Items.FirstOrDefault()?.Source.BaseChunk.SequenceNumber)
                {
                    caret.Bounds = new Rect(0, -content.LineHeight, 0, 0);
                }
                else if (anchor.Chunk.SequenceNumber > content.TextLayer.Items.LastOrDefault()?.Source.BaseChunk.SequenceNumber)
                {
                    caret.Bounds = new Rect(0, Math.Max(content.Metrics.Viewport.Height, content.TextLayer.Height) + content.LineHeight, 0, 0);
                }
                else
                {
                    var chunkView = content.TryGetChunkView(anchor.Chunk.SequenceNumber);
                    if (chunkView != null)
                    {
                        if (chunkView.FirstFragmentIndex != -1 && chunkView.LastFragmentIndex != -1)
                        {
                            chunkView.PrepareSelectionAnchor(caret);
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                    }
                }
            }

            return(caret);
        }