Ejemplo n.º 1
0
        /// <summary>
        /// Retrieves the bounding rectangle that encompasses the text range
        /// with position measured from the top left of the <see cref="RichSuggestBox"/> control.
        /// </summary>
        /// <param name="range">Text range to retrieve the bounding box from.</param>
        /// <returns>The bounding rectangle.</returns>
        public Rect GetRectFromRange(ITextRange range)
        {
            var padding = _richEditBox.Padding;

            range.GetRect(PointOptions.None, out var rect, out var hit);
            rect.X += padding.Left - HorizontalOffset;
            rect.Y += padding.Top - VerticalOffset;
            var transform = _richEditBox.TransformToVisual(this);

            return(transform.TransformBounds(rect));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets up a breakpoint when the user taps on the breakpoints area
        /// </summary>
        /// <param name="sender">The <see cref="Canvas"/> instance in use</param>
        /// <param name="e">The <see cref="TappedRoutedEventArgs"/> instance for the event</param>
        private void BreakpointsCanvas_Tapped(object sender, TappedRoutedEventArgs e)
        {
            // Calculate the target vertical offset for the tap
            double yOffset =
                e.GetPosition((Border)sender).Y - 8 -         // Tap Y offset and adjustment
                CodeEditBox.VerticalScrollBarMargin.Top +     // Top internal padding
                CodeEditBox.ContentScroller !.VerticalOffset; // Vertical scroll offset

            // Get the range aligned to the left edge of the tapped line
            ITextRange range = CodeEditBox.Document.GetRangeFromPoint(new Point(0, yOffset), PointOptions.ClientCoordinates);

            range.GetRect(PointOptions.Transform, out Rect line, out _);

            // Get the line number
            int lineNumber = CodeEditBox.Text.AsSpan(0, range.StartPosition).Count(Characters.CarriageReturn) + 1;

            if (lineNumber == 1)
            {
                return;
            }

            // Store or remove the breakpoint
            if (BreakpointIndicators.ContainsKey(lineNumber))
            {
                BreakpointIndicators.Remove(lineNumber);

                if (BreakpointIndicators.Count == 0)
                {
                    BreakpointsBorder.ContextFlyout = null;
                }

                BreakpointRemoved?.Invoke(this, new BreakpointToggleEventArgs(lineNumber, BreakpointIndicators.Count));
            }
            else
            {
                if (BreakpointIndicators.Count == 0)
                {
                    BreakpointsBorder.ContextFlyout = BreakpointsMenuFlyout;
                }

                BreakpointIndicators.GetOrAddValueRef(lineNumber) = (float)line.Top;

                BreakpointAdded?.Invoke(this, new BreakpointToggleEventArgs(lineNumber, BreakpointIndicators.Count));
            }

            UpdateBreakpointsInfo();

            IdeOverlaysCanvas.Invalidate();
            CodeEditBox.InvalidateOverlays();
        }