You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I'm making an extension that smoothly scrolls a text view and records video (now gif animation).
But there is one problem, line numbers are not repainted when scrolling.
The text is scrolled, but line numbers are frozen.
Please tell me how I can solve this problem?
[VisualStudioContribution]
internal class TakeSnapshotCommand : Microsoft.VisualStudio.Extensibility.Commands.Command {
private TraceSource Logger { get; }
private AsyncServiceProviderInjection<DTE, DTE2> DTE { get; }
private MefInjection<IVsEditorAdaptersFactoryService> EditorAdaptersFactoryService { get; }
private AsyncServiceProviderInjection<SVsTextManager, IVsTextManager> TextManager { get; }
public override CommandConfiguration CommandConfiguration => new CommandConfiguration( "%Snapshot.Pro.TakeSnapshotCommand.DisplayName%" ) {
Icon = new CommandIconConfiguration( ImageMoniker.KnownValues.Extension, IconSettings.IconAndText ),
Placements = [ CommandPlacement.KnownPlacements.ToolsMenu ],
};
public TakeSnapshotCommand(
VisualStudioExtensibility extensibility,
TraceSource logger,
AsyncServiceProviderInjection<DTE, DTE2> dte,
MefInjection<IVsEditorAdaptersFactoryService> editorAdaptersFactoryService,
AsyncServiceProviderInjection<SVsTextManager, IVsTextManager> textManager
) : base( extensibility ) {
Logger = logger;
DTE = dte;
EditorAdaptersFactoryService = editorAdaptersFactoryService;
TextManager = textManager;
}
public override Task InitializeAsync(CancellationToken cancellationToken) {
return base.InitializeAsync( cancellationToken );
}
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken) {
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
try {
var textViewSnapshot = await context.GetActiveTextViewAsync( cancellationToken ) ?? throw new NullReferenceException( "ITextViewSnapshot is null" );
//var textDocumentSnapshot = view.Document ?? throw new NullReferenceException( "ITextDocumentSnapshot is null" );
var editorAdaptersFactoryService = await EditorAdaptersFactoryService.GetServiceAsync();
var textManager = await TextManager.GetServiceAsync();
ErrorHandler.ThrowOnFailure( textManager.GetActiveView( 1, null, out var activeTextView ) );
var wpfTextViewHost = editorAdaptersFactoryService.GetWpfTextViewHost( activeTextView ) ?? throw new NullReferenceException( "IWpfTextViewHost is null" );
var wpfTextView = wpfTextViewHost.TextView ?? throw new NullReferenceException( "IwpfTextView is null" );
var wpfTextViewMargin = wpfTextViewHost.GetTextViewMargin( PredefinedMarginNames.LineNumber ) ?? throw new NullReferenceException( "IWpfTextViewMargin is null" );
var path = $"D:/Snapshots/{DateTime.UtcNow.Ticks}-{Path.GetFileNameWithoutExtension( textViewSnapshot.FilePath ).Replace( ".", "_" )}.gif";
TakeSnapshot( path, wpfTextView, wpfTextViewMargin );
await Extensibility.Shell().ShowPromptAsync( $"Snapshot was saved: " + path, PromptOptions.OK, cancellationToken );
} catch (Exception ex) {
Logger.TraceInformation( "Can not save snapshot: " + ex );
}
}
The text was updated successfully, but these errors were encountered:
Denis535
changed the title
How to force line numbers margin to repaint?
How to force line numbers IWpfTextViewMargin to repaint?
Dec 11, 2024
Denis535
changed the title
How to force line numbers IWpfTextViewMargin to repaint?
How to force line numbers IWpfTextViewMargin (WpfLineNumberMargin) to repaint?
Dec 11, 2024
Hi!
I'm making an extension that smoothly scrolls a text view and records video (now gif animation).
But there is one problem, line numbers are not repainted when scrolling.
The text is scrolled, but line numbers are frozen.
Please tell me how I can solve this problem?
Unfortunately,
margin.VisualElement.UpdateLayout();
doesn't work!!!The text was updated successfully, but these errors were encountered: