[DevFiles]Update Monaco dependency to 0.47, new sticky scroll setting (#32410)

* Update Monaco dependency to 0.47

* Add setting to enable/disable it and add Peek support

* Fix Xaml styling
This commit is contained in:
Aaron Junker-Wildi
2024-04-19 15:09:46 +02:00
committed by GitHub
parent af5293cfb4
commit 05249ac432
128 changed files with 832 additions and 874 deletions

View File

@@ -9,5 +9,7 @@ namespace Peek.FilePreviewer.Models
public bool SourceCodeWrapText { get; }
public bool SourceCodeTryFormat { get; }
public bool SourceCodeStickyScroll { get; }
}
}

View File

@@ -25,11 +25,14 @@ namespace Peek.FilePreviewer.Models
public bool SourceCodeTryFormat { get; private set; }
public bool SourceCodeStickyScroll { get; private set; }
public PreviewSettings()
{
_settingsUtils = new SettingsUtils();
SourceCodeWrapText = false;
SourceCodeTryFormat = false;
SourceCodeStickyScroll = true;
LoadSettingsFromJson();
@@ -61,6 +64,7 @@ namespace Peek.FilePreviewer.Models
{
SourceCodeWrapText = settings.SourceCodeWrapText.Value;
SourceCodeTryFormat = settings.SourceCodeTryFormat.Value;
SourceCodeStickyScroll = settings.SourceCodeStickyScroll.Value;
}
retry = false;

View File

@@ -45,13 +45,13 @@ namespace Peek.FilePreviewer.Previewers
/// <summary>
/// Prepares temp html for the previewing
/// </summary>
public static string PreviewTempFile(string fileText, string extension, string tempFolder, bool tryFormat, bool wrapText)
public static string PreviewTempFile(string fileText, string extension, string tempFolder, bool tryFormat, bool wrapText, bool stickyScroll)
{
// TODO: check if file is too big, add MaxFileSize to settings
return InitializeIndexFileAndSelectedFile(fileText, extension, tempFolder, tryFormat, wrapText);
return InitializeIndexFileAndSelectedFile(fileText, extension, tempFolder, tryFormat, wrapText, stickyScroll);
}
private static string InitializeIndexFileAndSelectedFile(string fileContent, string extension, string tempFolder, bool tryFormat, bool wrapText)
private static string InitializeIndexFileAndSelectedFile(string fileContent, string extension, string tempFolder, bool tryFormat, bool wrapText, bool stickyScroll)
{
string vsCodeLangSet = Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.GetLanguage(extension);
@@ -79,6 +79,7 @@ namespace Peek.FilePreviewer.Previewers
html = html.Replace("[[PT_LANG]]", vsCodeLangSet, StringComparison.InvariantCulture);
html = html.Replace("[[PT_WRAP]]", wrapText ? "1" : "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_STICKY_SCROLL]]", stickyScroll ? "1" : "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_THEME]]", theme, StringComparison.InvariantCulture);
html = html.Replace("[[PT_CODE]]", base64FileCode, StringComparison.InvariantCulture);
html = html.Replace("[[PT_URL]]", Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.VirtualHostName, StringComparison.InvariantCulture);

View File

@@ -112,7 +112,7 @@ namespace Peek.FilePreviewer.Previewers
if (IsDevFilePreview && !isHtml && !isMarkdown)
{
var raw = await ReadHelper.Read(File.Path.ToString());
Preview = new Uri(MonacoHelper.PreviewTempFile(raw, File.Extension, TempFolderPath.Path, _previewSettings.SourceCodeTryFormat, _previewSettings.SourceCodeWrapText));
Preview = new Uri(MonacoHelper.PreviewTempFile(raw, File.Extension, TempFolderPath.Path, _previewSettings.SourceCodeTryFormat, _previewSettings.SourceCodeWrapText, _previewSettings.SourceCodeStickyScroll));
}
else if (isMarkdown)
{

View File

@@ -398,6 +398,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
_html = _html.Replace("[[PT_WRAP]]", _settings.Wrap ? "1" : "0", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_THEME]]", Settings.GetTheme(), StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_CODE]]", _base64FileCode, StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_STICKY_SCROLL]]", _settings.StickyScroll ? "1" : "0", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_URL]]", FilePreviewCommon.MonacoHelper.VirtualHostName, StringComparison.InvariantCulture);
}

View File

@@ -77,6 +77,26 @@ namespace Microsoft.PowerToys.PreviewHandler.Monaco
}
}
/// <summary>
/// Gets a value indicating whether sticky scroll should be enabled. Set by PT settings.
/// </summary>
public bool StickyScroll
{
get
{
try
{
return moduleSettings.GetSettings<PowerPreviewSettings>(PowerPreviewSettings.ModuleName).Properties.MonacoPreviewStickyScroll;
}
catch (FileNotFoundException)
{
// Couldn't read the settings.
// Assume default of true.
return true;
}
}
}
/// <summary>
/// Gets the color of the window background.
/// </summary>