Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 3b6d99c

Browse files
David Karlašmrward
authored andcommitted
Fix 822175: Exception adornment scrolled outside of view
Only reasonable fix is to follow VS Windows way of displaying it as window because things get tricky with wrapped view where you can't just expand text view scrollable width...
1 parent 7ff7452 commit 3b6d99c

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/ExceptionCaught/ExceptionCaughtAdornmentManager.cs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class ExceptionCaughtAdornmentManager : IDisposable
4343
private readonly string filePath;
4444
readonly IXPlatAdornmentLayer _exceptionCaughtLayer;
4545
FileLineExtension extension;
46+
NSWindow exceptionCaughtButtonWindow;
4647

4748
public ExceptionCaughtAdornmentManager (ICocoaViewFactory cocoaViewFactory, ICocoaTextView textView)
4849
{
@@ -68,6 +69,10 @@ private void FileExtensionRemoved (object sender, FileExtensionEventArgs e)
6869
if (e.Extension == extension) {
6970
extension = null;
7071
_exceptionCaughtLayer.RemoveAllAdornments ();
72+
if (exceptionCaughtButtonWindow != null) {
73+
exceptionCaughtButtonWindow.Close ();
74+
exceptionCaughtButtonWindow = null;
75+
}
7176
}
7277
}
7378

@@ -81,11 +86,14 @@ private void FileExtensionAdded (object sender, FileExtensionEventArgs e)
8186
private void RenderAdornment (FileLineExtension fileLineExtension)
8287
{
8388
NSView view;
84-
if (fileLineExtension is ExceptionCaughtButton button)
89+
bool mini;
90+
if (fileLineExtension is ExceptionCaughtButton button) {
91+
mini = false;
8592
view = CreateButton (cocoaViewFactory, button);
86-
else if (fileLineExtension is ExceptionCaughtMiniButton miniButton)
93+
} else if (fileLineExtension is ExceptionCaughtMiniButton miniButton) {
94+
mini = true;
8795
view = CreateMiniButton (cocoaViewFactory, miniButton);
88-
else
96+
} else
8997
return;
9098
if (extension != fileLineExtension) {
9199
extension = fileLineExtension;
@@ -97,17 +105,37 @@ private void RenderAdornment (FileLineExtension fileLineExtension)
97105
return;
98106
if (!textView.TextViewLines.FormattedSpan.Contains (span.End))
99107
return;
100-
try {
101-
var charBound = textView.TextViewLines.GetCharacterBounds (span.End);
102-
view.SetFrameOrigin (new CGPoint (
108+
_exceptionCaughtLayer.RemoveAllAdornments ();
109+
if (exceptionCaughtButtonWindow != null) {
110+
exceptionCaughtButtonWindow.Close ();
111+
exceptionCaughtButtonWindow = null;
112+
}
113+
var charBound = textView.TextViewLines.GetCharacterBounds (span.End);
114+
if (mini) {
115+
try {
116+
view.SetFrameOrigin (new CGPoint (
103117
Math.Round (charBound.Left),
104-
Math.Round (charBound.TextTop + charBound.TextHeight / 2 - view.Frame.Height / 2)));
105-
} catch (Exception e) {
106-
view.SetFrameOrigin (default);
107-
LoggingService.LogInternalError ("https://vsmac.dev/923058", e);
118+
Math.Round (charBound.TextTop - charBound.TextHeight / 2 - view.Frame.Height / 2)));
119+
} catch (Exception e) {
120+
view.SetFrameOrigin (default);
121+
LoggingService.LogInternalError ("https://vsmac.dev/923058", e);
122+
}
123+
_exceptionCaughtLayer.AddAdornment (XPlatAdornmentPositioningBehavior.TextRelative, span, null, view, null);
124+
} else {
125+
var editorWindow = textView.VisualElement.Window;
126+
var pointOnScreen = editorWindow.ConvertPointToScreen (textView.VisualElement.ConvertPointToView (new CGPoint (charBound.Left, charBound.TextTop), null));
127+
exceptionCaughtButtonWindow = new NSWindow (CGRect.Empty, NSWindowStyle.Borderless, NSBackingStore.Buffered, false);
128+
editorWindow.AddChildWindow (exceptionCaughtButtonWindow, NSWindowOrderingMode.Above);
129+
exceptionCaughtButtonWindow.IsOpaque = false;
130+
exceptionCaughtButtonWindow.BackgroundColor = NSColor.Clear;
131+
exceptionCaughtButtonWindow.HasShadow = true;
132+
exceptionCaughtButtonWindow.ContentView = view;
133+
var fittingSize = view.FittingSize;
134+
var x = Math.Min (editorWindow.Screen.VisibleFrame.Width - fittingSize.Width, pointOnScreen.X);
135+
var y = Math.Max (0, pointOnScreen.Y - fittingSize.Height / 2);
136+
exceptionCaughtButtonWindow.SetFrame (new CGRect (x, y, fittingSize.Width, fittingSize.Height), true);
137+
exceptionCaughtButtonWindow.MakeKeyAndOrderFront (null);
108138
}
109-
_exceptionCaughtLayer.RemoveAllAdornments ();
110-
_exceptionCaughtLayer.AddAdornment (XPlatAdornmentPositioningBehavior.TextRelative, span, null, view, null);
111139
}
112140

113141
private void TextView_LayoutChanged (object sender, TextViewLayoutChangedEventArgs e)

0 commit comments

Comments
 (0)