Skip to content

Commit

Permalink
Update code to reflect changes from microsoft#33845
Browse files Browse the repository at this point in the history
  • Loading branch information
PesBandi committed Aug 23, 2024
1 parent 4a937da commit 55bcde4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
36 changes: 14 additions & 22 deletions src/common/FilePreviewCommon/Assets/Monaco/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@
// `minimap` if the minimap is shown

var theme = ("[[PT_THEME]]" == "dark") ? "vs-dark" : "vs";
var lang = "[[PT_LANG]]";
var wrap = ([[PT_WRAP]] == 1) ? true : false;
var wrap = [[PT_WRAP]];
var minimap = [[PT_MINIMAP]];

var base64code = "[[PT_CODE]]";

var stickyScroll = ([[PT_STICKY_SCROLL]] == 1) ? true : false;

var stickyScroll = [[PT_STICKY_SCROLL]];
var fontSize = [[PT_FONT_SIZE]];
var contextMenu = ([[PT_CONTEXTMENU]] == 1) ? true : false;
var contextMenu = [[PT_CONTEXTMENU]];

var lang = "[[PT_LANG]]";
var base64code = "[[PT_CODE]]";

var editor;

Expand All @@ -31,12 +29,13 @@
}).join(''));

function runToggleTextWrapCommand() {
if (wrap) {
editor.updateOptions({ wordWrap: 'off' })
} else {
editor.updateOptions({ wordWrap: 'on' })
}
wrap = !wrap;
editor.updateOptions({ wordWrap: wrap ? 'on' : 'off' });
}

function runToggleMinimap() {
minimap = !minimap;
editor.updateOptions({minimap: {enabled: minimap}});
}

function runCopyCommand() {
Expand Down Expand Up @@ -137,10 +136,7 @@
contextMenuOrder: 100,

// Method that will be executed when the action is triggered.
// @param editor The editor instance is passed in as a convenience
run: function (ed) {
runToggleTextWrapCommand();
}
run: runToggleTextWrapCommand
});

editor.addAction({
Expand All @@ -153,11 +149,7 @@
contextMenuOrder: 100,

// Method that will be executed when the action is triggered.
// @param editor The editor instance is passed in as a convenience
run: editor => {
editor.updateOptions({minimap: {enabled: !minimap}});
minimap = !minimap;
}
run: runToggleMinimap
});

onContextMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ MenuItem CreateCommandMenuItem(string resourceId, string commandName)
CreateCommandMenuItem("ContextMenu_Copy", "runCopyCommand"),
new Separator(),
CreateCommandMenuItem("ContextMenu_ToggleTextWrapping", "runToggleTextWrapCommand"),
CreateCommandMenuItem("ContextMenu_ToggleMinimap", "runToggleMinimap")
];
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ private static string InitializeIndexFileAndSelectedFile(string fileContent, str
string html = Microsoft.PowerToys.FilePreviewCommon.MonacoHelper.ReadIndexHtml();

html = html.Replace("[[PT_LANG]]", vsCodeLangSet, StringComparison.InvariantCulture);
html = html.Replace("[[PT_WRAP]]", wrapText ? "1" : "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_CONTEXTMENU]]", "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_STICKY_SCROLL]]", stickyScroll ? "1" : "0", StringComparison.InvariantCulture);
html = html.Replace("[[PT_WRAP]]", wrapText ? "true" : "false", StringComparison.InvariantCulture);
html = html.Replace("[[PT_CONTEXTMENU]]", "false", StringComparison.InvariantCulture);
html = html.Replace("[[PT_STICKY_SCROLL]]", stickyScroll ? "true" : "false", StringComparison.InvariantCulture);
html = html.Replace("[[PT_THEME]]", theme, StringComparison.InvariantCulture);
html = html.Replace("[[PT_FONT_SIZE]]", fontSize.ToString(CultureInfo.InvariantCulture), StringComparison.InvariantCulture);
html = html.Replace("[[PT_CODE]]", base64FileCode, StringComparison.InvariantCulture);
Expand Down
3 changes: 3 additions & 0 deletions src/modules/peek/Peek.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,7 @@
<value>Toggle text wrapping</value>
<comment>Toggle whether text in pane is word-wrapped</comment>
</data>
<data name="ContextMenu_ToggleMinimap" xml:space="preserve">
<value>Toggle minimap</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ private void InitializeIndexFileAndSelectedFile(string filePath)
// prepping index html to load in
_html = FilePreviewCommon.MonacoHelper.ReadIndexHtml();
_html = _html.Replace("[[PT_LANG]]", _vsCodeLangSet, StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_WRAP]]", _settings.Wrap ? "1" : "0", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_CONTEXTMENU]]", "1", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_WRAP]]", _settings.Wrap ? "true" : "false", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_CONTEXTMENU]]", "true", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_THEME]]", Settings.GetTheme(), StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_STICKY_SCROLL]]", _settings.StickyScroll ? "1" : "0", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_STICKY_SCROLL]]", _settings.StickyScroll ? "true" : "false", StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_FONT_SIZE]]", _settings.FontSize.ToString(CultureInfo.InvariantCulture), StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_CODE]]", _base64FileCode, StringComparison.InvariantCulture);
_html = _html.Replace("[[PT_URL]]", FilePreviewCommon.MonacoHelper.VirtualHostName, StringComparison.InvariantCulture);
Expand Down

0 comments on commit 55bcde4

Please sign in to comment.