diff --git a/src/dev/impl/DevToys.MonacoEditor/CodeEditorControl/CodeEditorCore.cs b/src/dev/impl/DevToys.MonacoEditor/CodeEditorControl/CodeEditorCore.cs index 56814bab33..a1e42d87a0 100644 --- a/src/dev/impl/DevToys.MonacoEditor/CodeEditorControl/CodeEditorCore.cs +++ b/src/dev/impl/DevToys.MonacoEditor/CodeEditorControl/CodeEditorCore.cs @@ -1069,6 +1069,11 @@ public IAsyncAction SetPositionAsync(IPosition position) return SendScriptAsync("editor.setPosition(" + JsonConvert.SerializeObject(position) + ");").AsAsyncAction(); } + public void RegisterDateHoverProvider() + { + _ = InvokeScriptAsync("registerDateHoverProvider", "json"); + } + /// /// https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.icommoncodeeditor.html#deltadecorations /// diff --git a/src/dev/impl/DevToys.MonacoEditor/ts-helpermethods/otherScriptsToBeOrganized.ts b/src/dev/impl/DevToys.MonacoEditor/ts-helpermethods/otherScriptsToBeOrganized.ts index 2677c50435..d4c5d4faa3 100644 --- a/src/dev/impl/DevToys.MonacoEditor/ts-helpermethods/otherScriptsToBeOrganized.ts +++ b/src/dev/impl/DevToys.MonacoEditor/ts-helpermethods/otherScriptsToBeOrganized.ts @@ -20,6 +20,32 @@ var registerHoverProvider = function (languageId: string) { }); } +var registerDateHoverProvider = function (languageId: string) { + return monaco.languages.registerHoverProvider(languageId, { + provideHover: function (model, position) { + var wordAtPosition = model.getWordAtPosition(position); + if (wordAtPosition === null) { + return null; + } + var date = new Date(Number(wordAtPosition.word) * 1000); + if (isNaN(date.getTime())) { + return null; + } + return { + range: new monaco.Range( + position.lineNumber, + wordAtPosition.startColumn, + position.lineNumber, + wordAtPosition.endColumn + ), + contents: [ + { value: date.toString() }, + ], + }; + } + }); +} + var addAction = function (action: monaco.editor.IActionDescriptor) { action.run = function (ed) { Parent.callAction("Action" + action.id) diff --git a/src/dev/impl/DevToys/UI/Controls/CodeEditor.xaml.cs b/src/dev/impl/DevToys/UI/Controls/CodeEditor.xaml.cs index 66418f10b5..e5d96f0b8f 100644 --- a/src/dev/impl/DevToys/UI/Controls/CodeEditor.xaml.cs +++ b/src/dev/impl/DevToys/UI/Controls/CodeEditor.xaml.cs @@ -189,6 +189,19 @@ public bool InlineDiffViewMode set => SetValue(InlineDiffViewModeProperty, value); } + public static readonly DependencyProperty ShowDatesHoverProperty + = DependencyProperty.Register( + nameof(ShowDatesHover), + typeof(bool), + typeof(CodeEditor), + new PropertyMetadata(false)); + + public bool ShowDatesHover + { + get => (bool)GetValue(ShowDatesHoverProperty); + set => SetValue(ShowDatesHoverProperty, value); + } + public CodeEditor() { SettingsProvider = MefComposer.Provider.Import(); @@ -251,9 +264,14 @@ private void CodeEditorCore_Loading(object sender, RoutedEventArgs e) }; _codeEditorCore.Options.Hover = new EditorHoverOptions() { - Enabled = false + Enabled = ShowDatesHover }; + if (ShowDatesHover) + { + _codeEditorCore.RegisterDateHoverProvider(); + } + _codeEditorCore.DiffOptions.GlyphMargin = false; _codeEditorCore.DiffOptions.MouseWheelZoom = false; _codeEditorCore.DiffOptions.OverviewRulerBorder = false; diff --git a/src/dev/impl/DevToys/Views/Tools/EncodersDecoders/JwtDecoderEncoder/JwtDecoderControl.xaml b/src/dev/impl/DevToys/Views/Tools/EncodersDecoders/JwtDecoderEncoder/JwtDecoderControl.xaml index bd5eb23520..807a15bd2e 100644 --- a/src/dev/impl/DevToys/Views/Tools/EncodersDecoders/JwtDecoderEncoder/JwtDecoderControl.xaml +++ b/src/dev/impl/DevToys/Views/Tools/EncodersDecoders/JwtDecoderEncoder/JwtDecoderControl.xaml @@ -175,6 +175,7 @@ Header="{x:Bind ViewModel.LocalizedStrings.JwtPayloadLabel}" Text="{x:Bind ViewModel.Payload, Mode=OneWay}" CodeLanguage="json" + ShowDatesHover="True" IsReadOnly="True"/>