diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2020-01-10 11:48:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-10 11:48:15 +0300 |
commit | 392e5dc052f736377508dfca985f2296fc5ebbe8 (patch) | |
tree | 5b2181b3411f89a4760a0a0fca221e0525dc1545 | |
parent | 899a87b2c7778989a1f47de6b4f4a97ca6913eec (diff) | |
parent | bb85e62dd98ef4f8c23033063e135bf3e6a454e0 (diff) |
Merge pull request #7706 from mono/pr-david-fix822175
Fix 822175: Exception adornment scrolled outside of view
-rw-r--r-- | main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/ExceptionCaught/ExceptionCaughtAdornmentManager.cs | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/ExceptionCaught/ExceptionCaughtAdornmentManager.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/ExceptionCaught/ExceptionCaughtAdornmentManager.cs index 6a633f99d0..490fbc6754 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/ExceptionCaught/ExceptionCaughtAdornmentManager.cs +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/ExceptionCaught/ExceptionCaughtAdornmentManager.cs @@ -43,6 +43,7 @@ namespace MonoDevelop.Debugger.VSTextView.ExceptionCaught private readonly string filePath; readonly IXPlatAdornmentLayer _exceptionCaughtLayer; FileLineExtension extension; + NSPanel exceptionCaughtButtonWindow; public ExceptionCaughtAdornmentManager (ICocoaViewFactory cocoaViewFactory, ICocoaTextView textView) { @@ -68,6 +69,10 @@ namespace MonoDevelop.Debugger.VSTextView.ExceptionCaught if (e.Extension == extension) { extension = null; _exceptionCaughtLayer.RemoveAllAdornments (); + if (exceptionCaughtButtonWindow != null) { + exceptionCaughtButtonWindow.Close (); + exceptionCaughtButtonWindow = null; + } } } @@ -81,11 +86,14 @@ namespace MonoDevelop.Debugger.VSTextView.ExceptionCaught private void RenderAdornment (FileLineExtension fileLineExtension) { NSView view; - if (fileLineExtension is ExceptionCaughtButton button) + bool mini; + if (fileLineExtension is ExceptionCaughtButton button) { + mini = false; view = CreateButton (cocoaViewFactory, button); - else if (fileLineExtension is ExceptionCaughtMiniButton miniButton) + } else if (fileLineExtension is ExceptionCaughtMiniButton miniButton) { + mini = true; view = CreateMiniButton (cocoaViewFactory, miniButton); - else + } else return; if (extension != fileLineExtension) { extension = fileLineExtension; @@ -97,17 +105,38 @@ namespace MonoDevelop.Debugger.VSTextView.ExceptionCaught return; if (!textView.TextViewLines.FormattedSpan.Contains (span.End)) return; - try { - var charBound = textView.TextViewLines.GetCharacterBounds (span.End); - view.SetFrameOrigin (new CGPoint ( + _exceptionCaughtLayer.RemoveAllAdornments (); + if (exceptionCaughtButtonWindow != null) { + exceptionCaughtButtonWindow.Close (); + exceptionCaughtButtonWindow = null; + } + var charBound = textView.TextViewLines.GetCharacterBounds (span.End); + if (mini) { + try { + view.SetFrameOrigin (new CGPoint ( Math.Round (charBound.Left), - Math.Round (charBound.TextTop + charBound.TextHeight / 2 - view.Frame.Height / 2))); - } catch (Exception e) { - view.SetFrameOrigin (default); - LoggingService.LogInternalError ("https://vsmac.dev/923058", e); + Math.Round (charBound.TextTop - charBound.TextHeight / 2 - view.Frame.Height / 2))); + } catch (Exception e) { + view.SetFrameOrigin (default); + LoggingService.LogInternalError ("https://vsmac.dev/923058", e); + } + _exceptionCaughtLayer.AddAdornment (XPlatAdornmentPositioningBehavior.TextRelative, span, null, view, null); + } else { + var editorWindow = textView.VisualElement.Window; + var pointOnScreen = editorWindow.ConvertPointToScreen (textView.VisualElement.ConvertPointToView (new CGPoint (charBound.Left, charBound.TextTop), null)); + exceptionCaughtButtonWindow = new NSPanel (CGRect.Empty, NSWindowStyle.Borderless, NSBackingStore.Buffered, false); + exceptionCaughtButtonWindow.AccessibilityRole = NSAccessibilityRoles.PopoverRole; + editorWindow.AddChildWindow (exceptionCaughtButtonWindow, NSWindowOrderingMode.Above); + exceptionCaughtButtonWindow.IsOpaque = false; + exceptionCaughtButtonWindow.BackgroundColor = NSColor.Clear; + exceptionCaughtButtonWindow.HasShadow = true; + exceptionCaughtButtonWindow.ContentView = view; + var fittingSize = view.FittingSize; + var x = Math.Min (editorWindow.Screen.VisibleFrame.Width - fittingSize.Width, pointOnScreen.X); + var y = Math.Max (0, pointOnScreen.Y - fittingSize.Height / 2); + exceptionCaughtButtonWindow.SetFrame (new CGRect (x, y, fittingSize.Width, fittingSize.Height), true); + exceptionCaughtButtonWindow.MakeKeyAndOrderFront (null); } - _exceptionCaughtLayer.RemoveAllAdornments (); - _exceptionCaughtLayer.AddAdornment (XPlatAdornmentPositioningBehavior.TextRelative, span, null, view, null); } private void TextView_LayoutChanged (object sender, TextViewLayoutChangedEventArgs e) |