@@ -43,6 +43,7 @@ public class ExceptionCaughtAdornmentManager : IDisposable
43
43
private readonly string filePath ;
44
44
readonly IXPlatAdornmentLayer _exceptionCaughtLayer ;
45
45
FileLineExtension extension ;
46
+ NSPanel exceptionCaughtButtonWindow ;
46
47
47
48
public ExceptionCaughtAdornmentManager ( ICocoaViewFactory cocoaViewFactory , ICocoaTextView textView )
48
49
{
@@ -68,6 +69,10 @@ private void FileExtensionRemoved (object sender, FileExtensionEventArgs e)
68
69
if ( e . Extension == extension ) {
69
70
extension = null ;
70
71
_exceptionCaughtLayer . RemoveAllAdornments ( ) ;
72
+ if ( exceptionCaughtButtonWindow != null ) {
73
+ exceptionCaughtButtonWindow . Close ( ) ;
74
+ exceptionCaughtButtonWindow = null ;
75
+ }
71
76
}
72
77
}
73
78
@@ -81,11 +86,14 @@ private void FileExtensionAdded (object sender, FileExtensionEventArgs e)
81
86
private void RenderAdornment ( FileLineExtension fileLineExtension )
82
87
{
83
88
NSView view ;
84
- if ( fileLineExtension is ExceptionCaughtButton button )
89
+ bool mini ;
90
+ if ( fileLineExtension is ExceptionCaughtButton button ) {
91
+ mini = false ;
85
92
view = CreateButton ( cocoaViewFactory , button ) ;
86
- else if ( fileLineExtension is ExceptionCaughtMiniButton miniButton )
93
+ } else if ( fileLineExtension is ExceptionCaughtMiniButton miniButton ) {
94
+ mini = true ;
87
95
view = CreateMiniButton ( cocoaViewFactory , miniButton ) ;
88
- else
96
+ } else
89
97
return ;
90
98
if ( extension != fileLineExtension ) {
91
99
extension = fileLineExtension ;
@@ -97,17 +105,38 @@ private void RenderAdornment (FileLineExtension fileLineExtension)
97
105
return ;
98
106
if ( ! textView . TextViewLines . FormattedSpan . Contains ( span . End ) )
99
107
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 (
103
117
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 NSPanel ( CGRect . Empty , NSWindowStyle . Borderless , NSBackingStore . Buffered , false ) ;
128
+ exceptionCaughtButtonWindow . AccessibilityRole = NSAccessibilityRoles . PopoverRole ;
129
+ editorWindow . AddChildWindow ( exceptionCaughtButtonWindow , NSWindowOrderingMode . Above ) ;
130
+ exceptionCaughtButtonWindow . IsOpaque = false ;
131
+ exceptionCaughtButtonWindow . BackgroundColor = NSColor . Clear ;
132
+ exceptionCaughtButtonWindow . HasShadow = true ;
133
+ exceptionCaughtButtonWindow . ContentView = view ;
134
+ var fittingSize = view . FittingSize ;
135
+ var x = Math . Min ( editorWindow . Screen . VisibleFrame . Width - fittingSize . Width , pointOnScreen . X ) ;
136
+ var y = Math . Max ( 0 , pointOnScreen . Y - fittingSize . Height / 2 ) ;
137
+ exceptionCaughtButtonWindow . SetFrame ( new CGRect ( x , y , fittingSize . Width , fittingSize . Height ) , true ) ;
138
+ exceptionCaughtButtonWindow . MakeKeyAndOrderFront ( null ) ;
108
139
}
109
- _exceptionCaughtLayer . RemoveAllAdornments ( ) ;
110
- _exceptionCaughtLayer . AddAdornment ( XPlatAdornmentPositioningBehavior . TextRelative , span , null , view , null ) ;
111
140
}
112
141
113
142
private void TextView_LayoutChanged ( object sender , TextViewLayoutChangedEventArgs e )
0 commit comments