Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Improve Avalonia Code Quality#36

Merged
Jack251970 merged 6 commits intomasterfrom
dev
Nov 13, 2025
Merged

Improve Avalonia Code Quality#36
Jack251970 merged 6 commits intomasterfrom
dev

Conversation

@Jack251970
Copy link
Copy Markdown
Owner

Follow on with #31

Added a `finally` block in `EquationRoot.cs` to ensure the
`bitmap` object is disposed of properly, improving resource
management.

Corrected a typo in `en.axaml` by updating the string
resource `MainWindow_AllFile` from "All File" to "All Files"
for grammatical accuracy.

Simplified logic in `CodepointWindowViewModel` by removing
unnecessary checks for negative values and ensuring `Number`
is capped at `MaxUnicodeValue` when applicable.
Added `using System.Threading;` to enable threading-related functionality. Updated the `catch` block in the `Main` method to re-throw critical exceptions (`StackOverflowException`, `OutOfMemoryException`, and `ThreadAbortException`) to prevent suppressing these unrecoverable errors.
Updated code to use the Rect.IsEmpty property instead of
comparing with Rect.Empty in EquationRow.cs and TextEquation.cs.
This change improves code clarity, aligns with best practices,
and ensures compatibility with the current framework.
Enabled C# preview features by adding `<LangVersion>preview</LangVersion>` to `Editor.csproj`.

Refactored `Rect` handling across the codebase:
- Introduced `RectExtensions` with `Empty` and `IsEmpty` properties.
- Updated `GetSelectionBounds` methods to return `Rect.Empty` instead of `default`.
- Replaced `default` checks with `IsEmpty` for improved clarity and consistency.

These changes improve code readability and maintainability.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves code quality in the Avalonia-based Math Editor application by fixing grammatical issues, improving resource management, refactoring code for better semantics, and adding modern C# features.

Key Changes

  • Fixed localization key from "All File" to "All Files" for grammatical correctness
  • Introduced Rect.Empty and IsEmpty extension members for more semantic null/empty checking
  • Added bitmap disposal in a finally block to prevent resource leaks
  • Removed unnecessary negative number validation (already handled by uint type)

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Editor/ViewModels/MainWindowViewModel.cs Updated localization key references from MainWindow_AllFile to MainWindow_AllFiles
Editor/ViewModels/CodepointWindowViewModel.cs Removed redundant negative number check (impossible for uint type)
Editor/Languages/zh-cn.axaml Updated Chinese localization key from MainWindow_AllFile to MainWindow_AllFiles
Editor/Languages/en.axaml Fixed grammatical error in English localization from "All File" to "All Files"
Editor/Extensions/RectExtensions.cs Added new extension type for Rect with Empty and IsEmpty members using C# preview features
Editor/Equations/TextEquation.cs Replaced default with more semantic Rect.Empty and IsEmpty checks
Editor/Equations/RowContainer.cs Replaced explicit width/height checks with IsEmpty property
Editor/Equations/EquationRow.cs Replaced default comparisons with IsEmpty checks for better readability
Editor/Equations/EquationRoot.cs Added finally block to ensure bitmap disposal and prevent resource leaks
Editor/Equations/EquationBase.cs Updated default return value from default to Rect.Empty
Editor/Editor.csproj Enabled preview language features with <LangVersion>preview</LangVersion>
Editor.Desktop/Program.cs Added critical exception filtering to prevent catching unrecoverable exceptions
Comments suppressed due to low confidence (1)

Editor/Equations/EquationRoot.cs:332

  • This variable is manually disposed in a finally block - consider a C# using statement as a preferable resource management technique.
            var bitmap = new RenderTargetBitmap(new PixelSize(bmpWidth, bmpHeight), new Vector(96, 96));

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Editor/Extensions/RectExtensions.cs
Comment thread Editor.Desktop/Program.cs
@Jack251970 Jack251970 merged commit a9a5d41 into master Nov 13, 2025
7 checks passed
@Jack251970 Jack251970 deleted the dev branch November 13, 2025 02:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants