/// <summary> /// Clears all the existing breakpoints /// </summary> /// <param name="sender">The <see cref="MenuFlyoutItem"/> that was clicked</param> /// <param name="e">The <see cref="RoutedEventArgs"/> for the current event</param> private void RemoveAllBreakpointsButton_Clicked(object sender, RoutedEventArgs e) { BreakpointsCleared?.Invoke(this, BreakpointIndicators.Count); BreakpointIndicators.Clear(); UpdateBreakpointsInfo(); IdeOverlaysCanvas.Invalidate(); CodeEditBox.InvalidateOverlays(); }
/// <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(); }