diff options
author | Sandy Armstrong <sandy@xamarin.com> | 2019-10-28 21:37:04 +0300 |
---|---|---|
committer | Sandy Armstrong <sandy@xamarin.com> | 2019-10-28 21:37:04 +0300 |
commit | 9af1a3da98db6f2bfa8a5f996057029c38d7afb5 (patch) | |
tree | 8abb1af98a0549952c2f4dc600bc1a838c5444a8 /main | |
parent | 8fb14379479e2dfdea726e3821157bbd5f184fc6 (diff) |
[Debugger] Prevent pinned watches from disappearing during scroll/etc
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/999608
Diffstat (limited to 'main')
-rw-r--r-- | main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/PinnedWatches/PinnedWatchAdornmentManager.cs | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/PinnedWatches/PinnedWatchAdornmentManager.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/PinnedWatches/PinnedWatchAdornmentManager.cs index 51539ac2cc..1789894109 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/PinnedWatches/PinnedWatchAdornmentManager.cs +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.VSTextView/PinnedWatches/PinnedWatchAdornmentManager.cs @@ -64,7 +64,7 @@ namespace MonoDevelop.Debugger.VSTextView.PinnedWatches this.cocoaViewFactory = cocoaViewFactory; this.textView = textView; - //this.textView.LayoutChanged += OnTextViewLayoutChanged; + this.textView.LayoutChanged += OnTextViewLayoutChanged; if (DebuggingService.IsDebugging) { RenderAllAdornments (); @@ -102,11 +102,16 @@ namespace MonoDevelop.Debugger.VSTextView.PinnedWatches adornments.Remove (e.Watch); } - void RenderAdornment (PinnedWatch watch) + SnapshotSpan GetSnapshotSpan (PinnedWatch watch) { var newSpan = textView.TextSnapshot.SpanFromMDColumnAndLine (watch.Line, watch.Column, watch.EndLine, watch.EndColumn); var trackingSpan = textView.TextSnapshot.CreateTrackingSpan (newSpan, SpanTrackingMode.EdgeInclusive); - var span = trackingSpan.GetSpan (textView.TextSnapshot); + return trackingSpan.GetSpan (textView.TextSnapshot); + } + + void RenderAdornment (PinnedWatch watch) + { + var span = GetSnapshotSpan (watch); if (textView.TextViewLines == null) return; @@ -123,19 +128,31 @@ namespace MonoDevelop.Debugger.VSTextView.PinnedWatches var view = (NSView) materialView; view.WantsLayer = true; + UpdateAdornmentLayout (watch, view, span); + + adornments [watch] = view; + } + + void UpdateAdornmentLayout (PinnedWatch watch, NSView view, SnapshotSpan span) + { try { + if (!textView.TextViewLines.IntersectsBufferSpan (span)) { + layer.RemoveAdornmentsByTag (watch); + return; + } + var charBound = textView.TextViewLines.GetCharacterBounds (span.End); var origin = new CGPoint ( Math.Round (charBound.Left), Math.Round (charBound.TextTop + charBound.TextHeight / 2 - view.Frame.Height / 2)); view.SetFrameOrigin (origin); + + if (view.Superview == null) + layer.AddAdornment (XPlatAdornmentPositioningBehavior.TextRelative, span, watch, view, null); } catch (Exception ex) { view.SetFrameOrigin (default); LoggingService.LogInternalError ("https://vsmac.dev/923058", ex); } - - layer.AddAdornment (XPlatAdornmentPositioningBehavior.TextRelative, span, watch, view, null); - adornments[watch] = view; } void RenderAllAdornments () @@ -163,16 +180,14 @@ namespace MonoDevelop.Debugger.VSTextView.PinnedWatches debugging = false; } - //void OnTextViewLayoutChanged (object sender, TextViewLayoutChangedEventArgs e) - //{ - // if (!DebuggingService.IsDebugging) - // return; - - // layer.RemoveAllAdornments (); - // adornments.Clear (); + void OnTextViewLayoutChanged (object sender, TextViewLayoutChangedEventArgs e) + { + if (!DebuggingService.IsDebugging) + return; - // RenderAllAdornments (); - //} + foreach (var adornmentPair in adornments) + UpdateAdornmentLayout (adornmentPair.Key, adornmentPair.Value, GetSnapshotSpan(adornmentPair.Key)); + } public void Dispose () { @@ -184,7 +199,7 @@ namespace MonoDevelop.Debugger.VSTextView.PinnedWatches DebuggingService.PinnedWatches.WatchRemoved -= OnWatchRemoved; DebuggingService.DebugSessionStarted -= OnDebugSessionStarted; DebuggingService.StoppedEvent -= OnDebuggingSessionStopped; - //textView.LayoutChanged -= OnTextViewLayoutChanged; + textView.LayoutChanged -= OnTextViewLayoutChanged; } } } |