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 Nov 13, 2025
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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.EmptyandIsEmptyextension 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
uinttype)
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow on with #31