Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Find best way to open diff view without scrolling to first diff #1631

Open
@jcansdale

Description

@jcansdale

How diff viewer gets created

We currently use OpenComparisonWindow2 of:
Name: Microsoft.VisualStudio.Shell.Interop.IVsDifferenceService
Assembly: Microsoft.VisualStudio.Shell.Interop.11.0

Which is implemented in:
Name: Microsoft.VisualStudio.Differencing.Package.DiffPackage
Assembly: Microsoft.VisualStudio.Diff

Which opens DiffViewerCodeWindow via IVsUIShellOpenDocument.OpenDocumentViaProjectWithSpecific.

Name: Microsoft.VisualStudio.Differencing.Package.DiffViewerCodeWindow
Assembly: Microsoft.VisualStudio.Diff
.ctor calls _viewer = factory.WpfDifferenceViewerFactoryService.CreateUninitializedDifferenceView();
InitializeViewer calls _viewer.Initialize(differenceBuffer, createTextViewHost, null);
NOTE: The null passed in here is parentOptions below.

Name: Microsoft.VisualStudio.Text.Differencing.IWpfDifferenceViewerFactoryService
Assembly: Microsoft.VisualStudio.Text.UI.Wpf

public interface IWpfDifferenceViewerFactoryService
{
   IWpfDifferenceViewer CreateDifferenceView(IDifferenceBuffer buffer, [Optional, DefaultParameterValue(null)] IEditorOptions parentOptions);
   IWpfDifferenceViewer CreateDifferenceView(IDifferenceBuffer buffer, CreateTextViewHostCallback callback, [Optional, DefaultParameterValue(null)] IEditorOptions parentOptions);
   IWpfDifferenceViewer CreateDifferenceView(IDifferenceBuffer buffer, ITextViewRoleSet roles, [Optional, DefaultParameterValue(null)] IEditorOptions parentOptions);
   IWpfDifferenceViewer CreateUninitializedDifferenceView();     IWpfDifferenceViewer TryGetViewerForTextView(ITextView textView);
}

Implemented in:
Name: Microsoft.VisualStudio.Text.Differencing.Implementation.DifferenceViewerFactoryService
Assembly: Microsoft.VisualStudio.Platform.VSEditor

Initialize calls:

// OptionsFactory is IEditorOptionsFactoryService
this.Options = this._factory.OptionsFactory.GetOptions(this);
if (parentOptions != null)
{
    this.Options.Parent = parentOptions;
}

...

if (this.Options.GetOptionValue<bool>(DifferenceViewerOptions.ScrollToFirstDiffId))
{
   if (this.DifferenceBuffer.CurrentSnapshotDifference != null)
   {
        this.ScrollToFirstChange();
   }
}

Summary

We really need to be able to pass in parentOptions, but this gets set to null using the IVsDifferenceService / DiffViewerCodeWindow.

The best alternative solution I can think of is to temporarily set DifferenceViewerOptions.ScrollToFirstDiffId to false via a global option.
This is what I'm doing here: 84a5e93

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions