Ejemplo n.º 1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            var mouse = e.GetSpecialKey();

            if (e.Button == MouseButtons.Left)
            {
                var mlist = Locations.FindMargin(e.Location);

                if (mlist != null)
                {
                    mlist.CallMarginMethod(MarginMethod.MouseDown, e.Location);
                }
                else
                {
                    var pos = Locations.LocationToPosition(e.Location);
                    Caret = pos.IsEmpty ? default(Pos) : pos;
                    RunCommand(new KeyInput(ModifierKeys.ToModifiers(), mouse));
                    var idx = Buffer.Selections.IndexOfCaret(pos);

                    if (idx != -1)
                    {
                        var sca = Buffer.Selections[idx].Caret;
                        Buffer.Selections[idx].SetToRestore(
                            Document.Lines[sca.Line].GetStripeCol(sca.Col));
                    }

                    if (Lines[pos.Line].Length == pos.Col && Folding.IsCollapsedHeader(pos.Line))
                    {
                        Folding.ToggleExpand(pos.Line);
                        Scroll.InvalidateLines();
                        Redraw();
                    }

                    if (!Focused)
                    {
                        Focus();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (Buffer == null)
            {
                return;
            }

            if (mouseThief != null)
            {
                mouseThief.MouseMove(e.Location);
                return;
            }

            var mlist = Locations.FindMargin(e.Location);

            if (mlist != null)
            {
                mlist.CallMarginMethod(MarginMethod.MouseMove, e.Location);
                Cursor = Cursors.Arrow;
            }

            var leftMouseDown = e.Button == MouseButtons.Left;
            var p             = Locations.LocationToPosition(e.Location);

            if (leftMouseDown && p.IsEmpty)
            {
                if (e.Y - Scroll.ScrollPosition.Y > Info.TextIntegralHeight && Scroll.LastVisibleLine < Lines.Count - 1)
                {
                    p = new Pos(Scroll.LastVisibleLine + 1, Lines[Scroll.LastVisibleLine + 1].Length);
                }
                else if (e.Y < Info.TextTop && Scroll.FirstVisibleLine > 0)
                {
                    p = new Pos(Scroll.FirstVisibleLine - 1, 0);
                }
            }

            if (!p.IsEmpty && Lines[p.Line].Length == p.Col && Folding.IsCollapsedHeader(p.Line))
            {
                Cursor = Cursors.Arrow;
            }
            else if (mlist == null)
            {
                Cursor = Cursors.IBeam;
            }

            mousePosition = e.Location;
            movePosition  = p;
            Caret         = p;

            if (!p.IsEmpty)
            {
                var keys  = ModifierKeys.ToModifiers();
                var mouse = e.GetSpecialKey();

                if (mouse != SpecialKey.None || keys != Modifiers.None)
                {
                    RunCommand(new KeyInput(keys | Modifiers.Move, mouse));
                }

                timer.Start();
            }
        }