Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump mac editor and implement CocoaTextBufferVisibilityTracker #65568

Conversation

Therzok
Copy link
Contributor

@Therzok Therzok commented Nov 22, 2022

This should help reduce the number classification marks triggering in the editor in VSMac.

Uses newly added API in VS-Platform, 0f93736f636b83a30c3a0b393b89afbe882de5e3.

Fixes https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1689011

@ghost ghost added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Nov 22, 2022
@Therzok
Copy link
Contributor Author

Therzok commented Nov 25, 2022

I tried multiple ways of fixing the duplication, but I end up with an issue where IsVisibleChanged is a plain EventHandler, and DependencyPropertyChangedEventArgs is a struct. Can't wrap the delegates into a compatible one, because there's no conversion that can be done.

Can we take this as-is for now?

This should help reduce the number classification marks triggering in
the editor in VSMac.

Fixes https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1654358
@Therzok Therzok force-pushed the dev/therzok/cocoa-text-buffer-visibility-tracker branch 2 times, most recently from aa12f5a to 60505e5 Compare November 25, 2022 16:52
@CyrusNajmabadi
Copy link
Member

@Therzok Sorry, i should have been more clear on how to do it. I've made the changed and pushed to your branch. Let me know how it looks for you.

@@ -28,7 +28,7 @@
<VisualStudioEditorPackagesVersion>17.5.42-preview</VisualStudioEditorPackagesVersion>
<!-- This should generally be set to $(VisualStudioEditorPackagesVersion),
but sometimes EditorFeatures.Cocoa specifically requires a newer editor build. -->
<VisualStudioMacEditorPackagesVersion>17.3.133-preview</VisualStudioMacEditorPackagesVersion>
<VisualStudioMacEditorPackagesVersion>17.5.152-preview-g356e9d7141</VisualStudioMacEditorPackagesVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@genlu @allisonchou what branch should this go into? main-vs-deps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to bump this to a standard daily build version, yes (won't have a commit hash suffix)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a package from a PR build. Let's change this to 17.5.157-preview (or 17.5.170-preview if we want latest).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually VisualStudioEditorPackagesVersion should be bumped and this property's value should be changed to $(VisualStudioEditorPackagesVersion). But that can happen in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this (hopefully?) only affects Mac we shouldn't need to worry about vs-deps. If we did bump VisualStudioEditorPackagesVersion then we might

{
private readonly ITextBufferAssociatedViewService _associatedViewService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this moved to abstract base class.

where TTextView : ITextView
where TVisibilityChangedCallback : System.Delegate
{
private readonly ITextBufferAssociatedViewService _associatedViewService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all this state and logic is the same. just pulled up into base class. i have marked where they differ.

protected abstract bool IsVisible(TTextView view);
protected abstract TVisibilityChangedCallback GetVisiblityChangeCallback(VisibleTrackerData visibleTrackerData);
protected abstract void AddVisibilityChangedCallback(TTextView view, TVisibilityChangedCallback visibilityChangedCallback);
protected abstract void RemoveVisibilityChangedCallback(TTextView view, TVisibilityChangedCallback visibilityChangedCallback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstract functionality for where wpf and cocoa need to specialize.

if (views.Any(static v => v is not TTextView))
return true;

return views.OfType<TTextView>().Any(v => IsVisible(v));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer to IsVisible here to do platform specific determination.

{
_tracker = tracker;
_subjectBuffer = subjectBuffer;
_visibilityChangedCallback = tracker.GetVisiblityChangeCallback(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer to platform specific code to get the callback with which to register to visibility changed event.

foreach (var addedView in addedViews)
{
if (addedView is TTextView genericView)
_tracker.AddVisibilityChangedCallback(genericView, _visibilityChangedCallback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer to platform specific code to attach/detach the visibility changed listener.

@CyrusNajmabadi
Copy link
Member

@jasonmalinowski ptal.

{
_tracker._threadingContext.ThrowIfNotOnUIThread();
protected override EventHandler GetVisiblityChangeCallback(VisibleTrackerData visibleTrackerData)
=> (sender, args) => visibleTrackerData.TriggerCallbacks();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, heh, I didn't think of wrapping in the derived impl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

@Therzok
Copy link
Contributor Author

Therzok commented Nov 27, 2022

@Therzok Sorry, i should have been more clear on how to do it. I've made the changed and pushed to your branch. Let me know how it looks for you.

No worries! The problem I was having is that I didn't have a plain EventHandler. My WIP work was similar to this, except that I was doing generic work over the event args, rather than the eventhandler delegate itself.
https://gist.github.com/Therzok/29f7a0a73958414008beb909acf121ea

Thanks for fixing it up.

@Therzok Therzok marked this pull request as ready for review November 28, 2022 15:43
@Therzok Therzok requested review from a team as code owners November 28, 2022 15:43
Copy link
Member

@sandyarmstrong sandyarmstrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, should just probably bump the editor package to a standard build instead of a PR build. 17.5.157-preview is the first that has the necessary changes. 17.5.170-preview is the latest that currently exists.

@Therzok
Copy link
Contributor Author

Therzok commented Nov 28, 2022

Yeah, sorry, I was using a PR build to be able to validate the changes first.

sandyarmstrong added a commit that referenced this pull request Nov 28, 2022
This should help reduce the number classification marks triggering in
the editor in VSMac.

Fixes https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1654358

Backport of #65568 without
the refactoring.
@sandyarmstrong
Copy link
Member

@CyrusNajmabadi @davidwengier can we merge this now?

@CyrusNajmabadi
Copy link
Member

yup yup!

@CyrusNajmabadi CyrusNajmabadi merged commit cca3a6b into dotnet:main Dec 13, 2022
@ghost ghost added this to the Next milestone Dec 13, 2022
@Therzok Therzok deleted the dev/therzok/cocoa-text-buffer-visibility-tracker branch December 14, 2022 09:47
@Cosifne Cosifne modified the milestones: Next, 17.5 P3 Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants