public static void GetSelectionBounds(this TextArea textArea, out int startLine, out int endLine)
        {
            startLine = textArea.Selection.StartPosition.Line;
            ICSharpCode.AvalonEdit.TextViewPosition endPosition = textArea.Selection.EndPosition;
            endLine = endPosition.Line;

            if (endLine < startLine)              // Swap
            {
                int saveEndLine = endLine;
                endLine     = startLine;
                startLine   = saveEndLine;
                endPosition = textArea.Selection.StartPosition;
            }

            TextDocument document = textArea.Document;

            string lineLeft = null;

            if (endPosition.Location.Line != 0 || endPosition.Location.Column != 0)
            {
                lineLeft = document.GetLineLeftOf(document.GetOffset(endPosition.Location));
            }
            if (string.IsNullOrWhiteSpace(lineLeft))
            {
                endLine--;
            }
        }
Пример #2
0
        /*public void UpdatePosition(){
         *  Main main = Main.Get();
         *
         *  //this.SetPosition();
         * }*/

        /*protected void SetPosition(TextViewPosition position)
         * {
         *  TextView textView = this.TextArea.TextView;
         *
         *
         *  UpdatePosition();
         * }*/

        public void UpdatePosition()
        {
            Main main = Main.Get();

            ICSharpCode.AvalonEdit.Rendering.TextView textView = main.editor.TextArea.TextView;
            ICSharpCode.AvalonEdit.TextViewPosition   position = new ICSharpCode.AvalonEdit.TextViewPosition(main.editor.Document.GetLocation(main.completionStartPosition));

            Point visualLocation    = textView.GetVisualPosition(position, ICSharpCode.AvalonEdit.Rendering.VisualYPosition.LineBottom);
            Point visualLocationTop = textView.GetVisualPosition(position, ICSharpCode.AvalonEdit.Rendering.VisualYPosition.LineTop);

            // PointToScreen returns device dependent units (physical pixels)
            Point location    = textView.PointToScreen(visualLocation - textView.ScrollOffset);
            Point locationTop = textView.PointToScreen(visualLocationTop - textView.ScrollOffset);

            // Let's use device dependent units for everything
            //Size completionWindowSize = new Size(this.Width, this.Height).TransformToDevice(textView);
            Rect bounds = new Rect(location, new Size(this.Width, this.Height));

            System.Drawing.Rectangle systemRect = System.Windows.Forms.Screen.GetWorkingArea(new System.Drawing.Point((int)location.X, (int)location.Y));
            Rect workingScreen = new Rect(new Point(systemRect.Location.X, systemRect.Location.Y), new Size(systemRect.Size.Width, systemRect.Size.Height));//.ToWpf();

            if (!workingScreen.Contains(bounds))
            {
                if (bounds.Left < workingScreen.Left)
                {
                    bounds.X = workingScreen.Left;
                }
                else if (bounds.Right > workingScreen.Right)
                {
                    bounds.X = workingScreen.Right - bounds.Width;
                }
                if (bounds.Bottom > workingScreen.Bottom)
                {
                    bounds.Y = locationTop.Y - bounds.Height;
                }
                if (bounds.Y < workingScreen.Top)
                {
                    bounds.Y = workingScreen.Top;
                }
            }
            // Convert the window bounds to device independent units

            Matrix matrix = PresentationSource.FromVisual(textView).CompositionTarget.TransformFromDevice;

            bounds    = Rect.Transform(bounds, matrix);
            this.Left = (int)bounds.X - 29 - main.Left;
            this.Top  = (int)bounds.Y - 30 - main.Top;
        }