Skip to content

A Swiss Army knife for developers.

Fixed bugs

Etienne Baudouxf407627ee4cd
diff --git a/src/app/dev/DevToys.Blazor/Assets/javascript/monacoEditor.ts b/src/app/dev/DevToys.Blazor/Assets/javascript/monacoEditor.ts
index 804022304..c24752f40 100644
--- a/src/app/dev/DevToys.Blazor/Assets/javascript/monacoEditor.ts
+++ b/src/app/dev/DevToys.Blazor/Assets/javascript/monacoEditor.ts
@@ -518,7 +518,7 @@ class MonacoEditor {
const eStrong = e as monaco.editor.ConfigurationChangedEvent;
eventJson = JSON.stringify((eStrong as any)._values);
}
- dotNetObjRef.invokeMethodAsync("EventCallback", eventName, eventJson);
+ dotNetObjRef.invokeMethodAsync("EventCallbackAsync", eventName, eventJson);
};
switch (eventName) {
diff --git a/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorDiff.razor.cs b/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorDiff.razor.cs
index 3eb16a9f8..8e8d4db58 100644
--- a/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorDiff.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/Text/MonacoEditor/MonacoEditorDiff.razor.cs
@@ -57,7 +57,6 @@ public partial class MonacoEditorDiff : RicherMonacoEditorDiffBase
options.BracketPairColorization = new BracketPairColorizationOptions { Enabled = true };
options.RenderLineHighlightOnlyWhenFocus = true;
- options.OriginalEditable = false;
options.DiffCodeLens = false;
options.RenderOverviewRuler = true;
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIDiffTextInputPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UIDiffTextInputPresenter.razor.cs
index 165953e57..18b46906e 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIDiffTextInputPresenter.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIDiffTextInputPresenter.razor.cs
@@ -16,9 +16,16 @@ public partial class UIDiffTextInputPresenter : JSStyledComponentBase, IDisposab
protected string ExtendedId => UIDiffTextInput.Id + "-" + Id;
+ private string _originalModelName = string.Empty;
+ private string _modifiedModelName = string.Empty;
+
protected override void OnInitialized()
{
base.OnInitialized();
+
+ _originalModelName = ExtendedId + "-originalModel";
+ _modifiedModelName = ExtendedId + "-modifiedModel";
+
UIDiffTextInput.TextChanged += UIMultiLineTextInput_TextChanged;
UIDiffTextInput.ModifiedTextChanged += UIDiffTextInput_RightTextChanged;
UIDiffTextInput.IsReadOnlyChanged += UIMultiLineTextInput_IsReadOnlyChanged;
@@ -37,17 +44,27 @@ public partial class UIDiffTextInputPresenter : JSStyledComponentBase, IDisposab
private async Task OnMonacoEditorInitializedAsync()
{
// Get or create the original model
- TextModel original_model = await MonacoEditorHelper.GetModelAsync(JSRuntime, "sample-diff-editor-originalModel");
+ TextModel original_model = await MonacoEditorHelper.GetModelAsync(JSRuntime, uri: _originalModelName);
if (original_model == null)
{
- original_model = await MonacoEditorHelper.CreateModelAsync(JSRuntime, UIDiffTextInput.Text, "javascript", "sample-diff-editor-originalModel");
+ original_model
+ = await MonacoEditorHelper.CreateModelAsync(
+ JSRuntime,
+ UIDiffTextInput.Text,
+ language: null,
+ uri: _originalModelName);
}
// Get or create the modified model
- TextModel modified_model = await MonacoEditorHelper.GetModelAsync(JSRuntime, "sample-diff-editor-modifiedModel");
+ TextModel modified_model = await MonacoEditorHelper.GetModelAsync(JSRuntime, uri: _modifiedModelName);
if (modified_model == null)
{
- modified_model = await MonacoEditorHelper.CreateModelAsync(JSRuntime, UIDiffTextInput.ModifiedText, "javascript", "sample-diff-editor-modifiedModel");
+ modified_model
+ = await MonacoEditorHelper.CreateModelAsync(
+ JSRuntime,
+ UIDiffTextInput.ModifiedText,
+ language: null,
+ uri: _modifiedModelName);
}
// Set the editor model
@@ -56,6 +73,13 @@ public partial class UIDiffTextInputPresenter : JSStyledComponentBase, IDisposab
Original = original_model,
Modified = modified_model
});
+
+ Guard.IsNotNull(_monacoEditor.ModifiedEditor);
+ await _monacoEditor.ModifiedEditor.UpdateOptionsAsync(
+ new EditorUpdateOptions
+ {
+ ReadOnly = UIDiffTextInput.IsReadOnly
+ });
}
private async void UIMultiLineTextInput_TextChanged(object? sender, EventArgs e)
@@ -72,18 +96,28 @@ public partial class UIDiffTextInputPresenter : JSStyledComponentBase, IDisposab
private async void UIMultiLineTextInput_IsReadOnlyChanged(object? sender, EventArgs e)
{
- await _monacoEditor.UpdateOptionsAsync(new DiffEditorOptions
- {
- ReadOnly = UIDiffTextInput.IsReadOnly
- });
+ Guard.IsNotNull(_monacoEditor.ModifiedEditor);
+ await _monacoEditor.UpdateOptionsAsync(
+ new DiffEditorOptions
+ {
+ ReadOnly = UIDiffTextInput.IsReadOnly,
+ OriginalEditable = !UIDiffTextInput.IsReadOnly
+ });
+ await _monacoEditor.ModifiedEditor.UpdateOptionsAsync(
+ new EditorUpdateOptions
+ {
+ ReadOnly = UIDiffTextInput.IsReadOnly
+ });
}
private async void UIDiffTextInput_InlineModeChanged(object? sender, EventArgs e)
{
- await _monacoEditor.UpdateOptionsAsync(new DiffEditorOptions
- {
- EnableSplitViewResizing = !UIDiffTextInput.InlineMode
- });
+ await _monacoEditor.UpdateOptionsAsync(
+ new DiffEditorOptions
+ {
+ EnableSplitViewResizing = !UIDiffTextInput.InlineMode,
+ RenderSideBySide = !UIDiffTextInput.InlineMode
+ });
}
private async Task OnToggleFullScreenButtonClickAsync()
@@ -98,7 +132,10 @@ public partial class UIDiffTextInputPresenter : JSStyledComponentBase, IDisposab
return new StandaloneDiffEditorConstructionOptions
{
ReadOnly = UIDiffTextInput.IsReadOnly,
- EnableSplitViewResizing = !UIDiffTextInput.InlineMode
+ OriginalEditable = !UIDiffTextInput.IsReadOnly,
+ EnableSplitViewResizing = !UIDiffTextInput.InlineMode,
+ RenderSideBySide = !UIDiffTextInput.InlineMode,
+ AutomaticLayout = true
};
}
}
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor b/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor
index df28ee7a8..be34c652b 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor
@@ -1,6 +1,6 @@
@namespace DevToys.Blazor.Components.UIElements
@using DevToys.Api;
-@inherits StyledComponentBase
+@inherits JSStyledComponentBase
<UITextInputWrapper @ref="_textInputWrapper"
UITextInput="@UIMultiLineTextInput"
@@ -9,6 +9,7 @@
IsVisible="@UIMultiLineTextInput.IsVisible"
IsEnabled="@UIMultiLineTextInput.IsEnabled"
ConstructionOptions="@OnMonacoConstructionOptions"
- OnDidChangeModelContent="OnTextChangedAsync"
+ OnDidChangeModelContent="OnMonacoEditorTextChangedAsync"
+ OnDidInit="OnMonacoEditorInitializedAsync"
ParentComponent="_textInputWrapper" />
</UITextInputWrapper>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor.cs b/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor.cs
index cfc581a7b..bdbd38982 100644
--- a/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor.cs
+++ b/src/app/dev/DevToys.Blazor/Components/UIElements/UIMultiLineTextInputPresenter.razor.cs
@@ -1,11 +1,14 @@
-using DevToys.Blazor.Components.Monaco.Editor;
+using DevToys.Blazor.Components.Monaco;
+using DevToys.Blazor.Components.Monaco.Editor;
namespace DevToys.Blazor.Components.UIElements;
-public partial class UIMultiLineTextInputPresenter : StyledComponentBase, IDisposable
+public partial class UIMultiLineTextInputPresenter : JSStyledComponentBase, IDisposable
{
private MonacoEditor _monacoEditor = default!;
private UITextInputWrapper _textInputWrapper = default!;
+ private bool _ignoreChangeComingFromUIMultiLineTextInput;
+ private string _modelName = string.Empty;
[Parameter]
public IUIMultiLineTextInput UIMultiLineTextInput { get; set; } = default!;
@@ -13,6 +16,7 @@ public partial class UIMultiLineTextInputPresenter : StyledComponentBase, IDispo
protected override void OnInitialized()
{
base.OnInitialized();
+ _modelName = Id + "-text-model";
UIMultiLineTextInput.SyntaxColorizationLanguageNameChanged += UIMultiLineTextInput_SyntaxColorizationLanguageNameChanged;
UIMultiLineTextInput.TextChanged += UIMultiLineTextInput_TextChanged;
UIMultiLineTextInput.IsReadOnlyChanged += UIMultiLineTextInput_IsReadOnlyChanged;
@@ -26,9 +30,12 @@ public partial class UIMultiLineTextInputPresenter : StyledComponentBase, IDispo
GC.SuppressFinalize(this);
}
- private async void UIMultiLineTextInput_TextChanged(object? sender, EventArgs e)
+ private void UIMultiLineTextInput_TextChanged(object? sender, EventArgs e)
{
- await _monacoEditor.SetValueAsync(UIMultiLineTextInput.Text);
+ if (!_ignoreChangeComingFromUIMultiLineTextInput)
+ {
+ _ = _monacoEditor.SetValueAsync(UIMultiLineTextInput.Text);
+ }
}
private async void UIMultiLineTextInput_SyntaxColorizationLanguageNameChanged(object? sender, EventArgs e)
@@ -44,9 +51,32 @@ public partial class UIMultiLineTextInputPresenter : StyledComponentBase, IDispo
});
}
- private async Task OnTextChangedAsync(ModelContentChangedEvent ev)
+ private async Task OnMonacoEditorTextChangedAsync(ModelContentChangedEvent ev)
{
+ _ignoreChangeComingFromUIMultiLineTextInput = true;
UIMultiLineTextInput.Text(await _monacoEditor.GetValueAsync(preserveBOM: null, lineEnding: null));
+ _ignoreChangeComingFromUIMultiLineTextInput = false;
+ }
+
+ private async Task OnMonacoEditorInitializedAsync()
+ {
+ // Get or create the text model
+ TextModel textModel = await MonacoEditorHelper.GetModelAsync(JSRuntime, uri: _modelName);
+ if (textModel == null)
+ {
+ textModel
+ = await MonacoEditorHelper.CreateModelAsync(
+ JSRuntime,
+ UIMultiLineTextInput.Text,
+ language: UIMultiLineTextInput.SyntaxColorizationLanguageName,
+ uri: _modelName);
+
+ // Set the editor model
+ await _monacoEditor.SetModelAsync(textModel);
+ }
+
+ // Set the text of model
+ await textModel.SetValueAsync(JSRuntime, UIMultiLineTextInput.Text);
}
private StandaloneEditorConstructionOptions OnMonacoConstructionOptions(MonacoEditor monacoEditor)
diff --git a/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj b/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj
index f677d9048..dc17ab0e1 100644
--- a/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj
+++ b/src/app/dev/DevToys.Blazor/DevToys.Blazor.csproj
@@ -31,11 +31,6 @@
<ConfigFiles Include="tsconfig.json" />
<Content Update="tsconfig.json" PublishFolderType="None" />
<Content Update="package.json" PublishFolderType="None" ExcludeFromBundleResources="true" />
- <Compile Remove="%2a%2a\**" />
- <Content Remove="%2a%2a\**" />
- <EmbeddedResource Remove="%2a%2a\**" />
- <TypeScriptCompile Remove="%2a%2a\**" />
- <TypeScriptCompile Remove="**\*.ts" />
</ItemGroup>
<ItemGroup>
diff --git a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
index 83c96a12c..fc3ed29d7 100644
--- a/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
+++ b/src/app/dev/DevToys.Tools/Tools/Settings/SettingsGuiTool.cs
@@ -99,6 +99,7 @@ internal sealed class SettingsGuiTool : IGuiTool
.Title("Difference")
.OriginalText("hello")
.Extendable()
+ .ReadOnly()
.ModifiedText("hello world")),
isScrollable: true);