diff --git a/src/DotNetPad/DotNetPad.Applications/Controllers/WorkspaceController.cs b/src/DotNetPad/DotNetPad.Applications/Controllers/WorkspaceController.cs index 4bf94b0..1123ef4 100644 --- a/src/DotNetPad/DotNetPad.Applications/Controllers/WorkspaceController.cs +++ b/src/DotNetPad/DotNetPad.Applications/Controllers/WorkspaceController.cs @@ -166,9 +166,9 @@ private void DocumentsCollectionChanged(object? sender, NotifyCollectionChangedE { foreach (DocumentFile x in e.OldItems!) RemoveProject(x); } - else if (e.Action == NotifyCollectionChangedAction.Reset) + else if (e.Action == NotifyCollectionChangedAction.Reset && !documentService.DocumentFiles.Any()) // Clear { - if (!documentService.DocumentFiles.Any()) foreach (var x in documentIds.Keys.ToArray()) RemoveProject(x); + foreach (var x in documentIds.Keys.ToArray()) RemoveProject(x); } else throw new NotSupportedException("Collection modification is not supported!"); } diff --git a/src/DotNetPad/DotNetPad.Presentation/Controls/CodeEditor.cs b/src/DotNetPad/DotNetPad.Presentation/Controls/CodeEditor.cs index 31b7c32..d804cfa 100644 --- a/src/DotNetPad/DotNetPad.Presentation/Controls/CodeEditor.cs +++ b/src/DotNetPad/DotNetPad.Presentation/Controls/CodeEditor.cs @@ -151,8 +151,8 @@ private void UpdateErrorMarkers() errorMarkerService.Clear(); foreach (var errorListItem in DocumentFile.Content?.ErrorList ?? Array.Empty()) { - var startOffset = Document.GetOffset(new TextLocation(errorListItem.StartLine + 1, errorListItem.StartColumn + 1)); - var endOffset = Document.GetOffset(new TextLocation(errorListItem.EndLine + 1, errorListItem.EndColumn + 1)); + var startOffset = Document.GetOffset(new(errorListItem.StartLine + 1, errorListItem.StartColumn + 1)); + var endOffset = Document.GetOffset(new(errorListItem.EndLine + 1, errorListItem.EndColumn + 1)); errorMarkerService.Create(startOffset, endOffset - startOffset, errorListItem.Description); } } diff --git a/src/DotNetPad/DotNetPad.Presentation/Controls/CodeHighlighter.cs b/src/DotNetPad/DotNetPad.Presentation/Controls/CodeHighlighter.cs index dacefb5..357504b 100644 --- a/src/DotNetPad/DotNetPad.Presentation/Controls/CodeHighlighter.cs +++ b/src/DotNetPad/DotNetPad.Presentation/Controls/CodeHighlighter.cs @@ -151,7 +151,7 @@ public VersionedHighlightedLine(IDocument document, IDocumentLine documentLine, { if (IsOutsideLine(documentLine, oldSection.Offset, oldSection.Length)) continue; - Sections.Add(new HighlightedSection + Sections.Add(new() { Color = oldSection.Color, Offset = oldSection.Offset, @@ -170,7 +170,7 @@ public VersionedHighlightedLine(IDocument document, IDocumentLine documentLine, private sealed class HighlightedSectionComparer : IEqualityComparer { - public static HighlightedSectionComparer Default { get; } = new HighlightedSectionComparer(); + public static HighlightedSectionComparer Default { get; } = new(); public bool Equals(HighlightedSection? x, HighlightedSection? y) { diff --git a/src/DotNetPad/DotNetPad.Presentation/Controls/ErrorTextMarkerService.cs b/src/DotNetPad/DotNetPad.Presentation/Controls/ErrorTextMarkerService.cs index ff73b07..12ce3d5 100644 --- a/src/DotNetPad/DotNetPad.Presentation/Controls/ErrorTextMarkerService.cs +++ b/src/DotNetPad/DotNetPad.Presentation/Controls/ErrorTextMarkerService.cs @@ -19,7 +19,7 @@ public ErrorTextMarkerService(TextEditor textEditor) this.textEditor = textEditor; markers = new(textEditor.Document); - TextView textView = textEditor.TextArea.TextView; + var textView = textEditor.TextArea.TextView; textView.BackgroundRenderers.Add(this); textView.LineTransformers.Add(this); textView.Services.AddService(typeof(ErrorTextMarkerService), this); diff --git a/src/DotNetPad/DotNetPad.Presentation/DesignData/MockShellService.cs b/src/DotNetPad/DotNetPad.Presentation/DesignData/MockShellService.cs index ee733b1..2347a8b 100644 --- a/src/DotNetPad/DotNetPad.Presentation/DesignData/MockShellService.cs +++ b/src/DotNetPad/DotNetPad.Presentation/DesignData/MockShellService.cs @@ -5,12 +5,7 @@ namespace Waf.DotNetPad.Presentation.DesignData; public class MockShellService : Model, IShellService { - public MockShellService() - { - Settings = new AppSettings(); - } - - public AppSettings Settings { get; set; } = null!; + public AppSettings Settings { get; set; } = new AppSettings(); public object ShellView { get; set; } = null!; diff --git a/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleCodeEditorViewModel.cs b/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleCodeEditorViewModel.cs index 8305195..add1f12 100644 --- a/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleCodeEditorViewModel.cs +++ b/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleCodeEditorViewModel.cs @@ -21,7 +21,7 @@ internal static void Main() } } }"; - DocumentFile = new DocumentFile(DocumentType.CSharp, "Script 1.cs", code); + DocumentFile = new(DocumentType.CSharp, "Script 1.cs", code); } diff --git a/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleErrorListViewModel.cs b/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleErrorListViewModel.cs index 34b911e..3366f1c 100644 --- a/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleErrorListViewModel.cs +++ b/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleErrorListViewModel.cs @@ -9,12 +9,11 @@ public class SampleErrorListViewModel : ErrorListViewModel public SampleErrorListViewModel() : base(new MockErrorListView(), new MockDocumentService(), null!, null!) { var documentFile = new DocumentFile(DocumentType.CSharp, "Script 1.cs", ""); - documentFile.Content!.ErrorList = new[] - { - new ErrorListItem(ErrorSeverity.Info, "Info", 0, 0, 0, 0), - new ErrorListItem(ErrorSeverity.Warning, "Warning", 3, 13, 3, 13), - new ErrorListItem(ErrorSeverity.Error, "Error", 20, 8, 20, 8) - }; + documentFile.Content!.ErrorList = [ + new(ErrorSeverity.Info, "Info", 0, 0, 0, 0), + new(ErrorSeverity.Warning, "Warning", 3, 13, 3, 13), + new(ErrorSeverity.Error, "Error", 20, 8, 20, 8) + ]; DocumentService.ActiveDocumentFile = documentFile; } diff --git a/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleSaveChangesViewModel.cs b/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleSaveChangesViewModel.cs index c44496d..5709f07 100644 --- a/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleSaveChangesViewModel.cs +++ b/src/DotNetPad/DotNetPad.Presentation/DesignData/SampleSaveChangesViewModel.cs @@ -8,12 +8,11 @@ public class SampleSaveChangesViewModel : SaveChangesViewModel { public SampleSaveChangesViewModel() : base(new MockSaveChangesView()) { - DocumentFiles = new[] - { - new DocumentFile(DocumentType.CSharp, null!) { FileName = "Script 1.cs" }, - new DocumentFile(DocumentType.CSharp, null!) { FileName = "Script 2.cs" }, - new DocumentFile(DocumentType.VisualBasic, null!) { FileName = @"C:\Users\Luke\Documents\Waf DotNetPad\Script 3.vb" }, - }; + DocumentFiles = [ + new(DocumentType.CSharp, null!) { FileName = "Script 1.cs" }, + new(DocumentType.CSharp, null!) { FileName = "Script 2.cs" }, + new(DocumentType.VisualBasic, null!) { FileName = @"C:\Users\Luke\Documents\Waf DotNetPad\Script 3.vb" }, + ]; } diff --git a/src/DotNetPad/DotNetPad.Presentation/Views/CodeEditorView.xaml.cs b/src/DotNetPad/DotNetPad.Presentation/Views/CodeEditorView.xaml.cs index dda9d90..4f26715 100644 --- a/src/DotNetPad/DotNetPad.Presentation/Views/CodeEditorView.xaml.cs +++ b/src/DotNetPad/DotNetPad.Presentation/Views/CodeEditorView.xaml.cs @@ -1,5 +1,4 @@ -using ICSharpCode.AvalonEdit.Document; -using System.ComponentModel.Composition; +using System.ComponentModel.Composition; using System.Waf.Applications; using System.Windows; using Waf.DotNetPad.Applications.Services; @@ -58,7 +57,7 @@ private async void UpdateCaretPosition() private void CodeEditorServiceRequestSetCaret(object? sender, SetCaretEventArgs e) { if (e.DocumentFile != ViewModel.DocumentFile) return; - var offset = codeEditor.Document.GetOffset(new TextLocation(e.Line + 1, e.Column + 1)); + var offset = codeEditor.Document.GetOffset(new(e.Line + 1, e.Column + 1)); codeEditor.TextArea.Caret.Offset = offset; codeEditor.Focus(); } diff --git a/src/DotNetPad/DotNetPad.Presentation/Views/OutputView.xaml.cs b/src/DotNetPad/DotNetPad.Presentation/Views/OutputView.xaml.cs index d667088..5fa9094 100644 --- a/src/DotNetPad/DotNetPad.Presentation/Views/OutputView.xaml.cs +++ b/src/DotNetPad/DotNetPad.Presentation/Views/OutputView.xaml.cs @@ -59,9 +59,9 @@ private void DocumentsCollectionChanged(object? sender, NotifyCollectionChangedE { foreach (DocumentFile x in e.OldItems!) outputParagraphs.Remove(x); } - else if (e.Action == NotifyCollectionChangedAction.Reset) - { - if (!ViewModel.DocumentService.DocumentFiles.Any()) outputParagraphs.Clear(); + else if (e.Action == NotifyCollectionChangedAction.Reset && !ViewModel.DocumentService.DocumentFiles.Any()) // Clear + { + outputParagraphs.Clear(); } else throw new NotSupportedException("Collection modification is not supported!"); }