/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/UserControls/FilePreviews/CodePreview.xaml.cs
57 строк
1 KB
yair100
Fix: Fixed issue with previewing CSS files (#18384)
20 апр 2026, 00:42
Не верифицирован
20 апр 2026, 00:42
30bad6e
Код
Авторство
О чём код?
using ColorCode; using Files.App.ViewModels.Previews; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 namespace Files.App.UserControls.FilePreviews { public sealed partial class CodePreview : UserControl { private RichTextBlockFormatter formatter; private CodePreviewViewModel ViewModel { get; set; } public CodePreview(CodePreviewViewModel model) { ViewModel = model; InitializeComponent(); } private void RenderDocument() { if (codeView is not null) { codeView.Blocks?.Clear(); if (ViewModel.Item.FileExtension is ".css" or ".scss") { // Some complex CSS files can make ColorCode parsing very slow and freeze the preview pane. // Use our lightweight renderer for CSS/SCSS to keep preview responsive while preserving highlighting. CssPreviewRenderer.Render(codeView, ViewModel.TextValue ?? string.Empty, ActualTheme == ElementTheme.Dark); return; } formatter = new RichTextBlockFormatter(ActualTheme); formatter.FormatRichTextBlock(ViewModel.TextValue, ViewModel.CodeLanguage, codeView); } } private void UserControl_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { RenderDocument(); } private void UserControl_ActualThemeChanged(Microsoft.UI.Xaml.FrameworkElement sender, object args) { try { RenderDocument(); } catch (Exception) { } } } }