/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/EditorFeatures/Core/IWpfTextViewExtensions.cs
46 строк
2 KB
Cyrus Najmabadi
Move files
25 апр 2025, 01:10
25 апр 2025, 01:10
46f9987
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.VisualStudio.Text.Editor; namespace Microsoft.CodeAnalysis.Editor.Shared.Extensions; internal static class IWpfTextViewExtensions { public static void SizeToFit(this IWpfTextView view, IThreadingContext threadingContext) { void firstLayout(object sender, TextViewLayoutChangedEventArgs args) { threadingContext.JoinableTaskFactory.RunAsync(async () => { await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield: true); var newHeight = view.LineHeight * view.TextBuffer.CurrentSnapshot.LineCount; if (IsGreater(newHeight, view.VisualElement.Height)) { view.VisualElement.Height = newHeight; } var newWidth = view.MaxTextRightCoordinate; if (IsGreater(newWidth, view.VisualElement.Width)) { view.VisualElement.Width = newWidth; } }); view.LayoutChanged -= firstLayout; } view.LayoutChanged += firstLayout; static bool IsGreater(double value, double other) => IsNormal(value) && (!IsNormal(other) || value > other); static bool IsNormal(double value) => !double.IsNaN(value) && !double.IsInfinity(value); } }