GHSoftware.Avalonia.SpellChecker 0.3.0

dotnet add package GHSoftware.Avalonia.SpellChecker --version 0.3.0                
NuGet\Install-Package GHSoftware.Avalonia.SpellChecker -Version 0.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GHSoftware.Avalonia.SpellChecker" Version="0.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GHSoftware.Avalonia.SpellChecker --version 0.3.0                
#r "nuget: GHSoftware.Avalonia.SpellChecker, 0.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GHSoftware.Avalonia.SpellChecker as a Cake Addin
#addin nuget:?package=GHSoftware.Avalonia.SpellChecker&version=0.3.0

// Install GHSoftware.Avalonia.SpellChecker as a Cake Tool
#tool nuget:?package=GHSoftware.Avalonia.SpellChecker&version=0.3.0                

Avalonia Spell Checker for TextBox

Avalonia Spell Checker adds real-time spell-checking to Avalonia TextBox controls without replacing or changing their behavior. It uses the WeCantSpell.Hunspell library for spell-checking and allows you to manage custom dictionaries. The extension integrates with existing TextBox elements and provides suggestions for misspelled words through a context menu.

<p float="left">

Demonstration screenshot Ignore demonstration screenshot Demonstration screenshot

</p>

Features

  • Real-time Spell Checking: Misspelled words are highlighted as the user types.
  • Custom Dictionaries: Add (or manage WIP) custom words for specific languages.
  • Context Menu Integration: Provides suggestions for misspelled words in a context menu.
  • Customization: Developers can modify styles for underlining and other text decorations for incorrect words.
  • Works with native Avalonia TextBox: The library is minimally intrusive, integrating seamlessly with text control.
  • Support for Multiple Languages: Allows the use of different language dictionaries simultaneously.

Getting Started

Prerequisites

Installation

  1. Clone this repository (there is also a Nuget package):

    git clone https://github.com/GustavoHennig/Avalonia.SpellChecker.git
    
  2. Install the required packages:

    dotnet restore
    
  3. Ensure the dictionary files (.aff and .dic) are placed in the Dictionaries folder, as specified in SpellCheckerConfig.

Usage

To enable spell checking for a TextBox control, initialize TextBoxSpellChecker with the required configuration:

public partial class MainWindow : Window
{
    private readonly TextBoxSpellChecker textBoxSpellChecker;

    public MainWindow()
    {
        InitializeComponent();

        // Initialize the spell checker
        // * default dictionaries directory is Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Dictionaries"))
        textBoxSpellChecker = new TextBoxSpellChecker(SpellCheckerConfig.Create("pt_BR", "en_GB"));

        var textBox = this.FindControl<TextBox>("tbDescription");
        textBoxSpellChecker.Initialize(textBox);
    }
}

The TextBoxSpellChecker automatically begins spell-checking the TextBox control. Misspelled words are underlined, and suggestions are provided in a context menu when the user right-clicks on the word.
When the TextBox control is detached from the view, the spell checker automatically removes its event handlers, and the reference to the TextBox is cleared.

Dictionary Files

According to ChatGPT, these are the most reliable and updated sources for downloading Hunspell dictionary files (ok, it seems that the first one is the easiest choice):

  1. LibreOffice Dictionaries Repository: The LibreOffice project maintains updated Hunspell dictionaries for a variety of languages. You can find them here:

    This is one of the best places to find dictionaries that are actively maintained and used by large communities.

  2. Mozilla Add-ons: Mozilla also uses Hunspell dictionaries for spell checking in Firefox, and they maintain a large collection of dictionaries available for download:

  3. Apache OpenOffice: OpenOffice also provides Hunspell-compatible dictionaries that you can download:

  4. Hunspell Dictionaries Collection: The Hunspell project itself hosts a repository of dictionaries: - Hunspell Dictionaries on GitHub 404

These sources are widely trusted and offer dictionaries that are kept up-to-date by large communities and projects.

Known Issues

  • Works only with Fluent theme
  • Keyboard context menu is not showing the suggestions
  • Only tested on Windows

Customization

You can customize the behavior and appearance of the spell checker by modifying:

  • Text Styles: Define how misspelled words are underlined or styled in SpellCheckerTextPresenter.cs. (WIP)
  • Custom Dictionaries: Add or remove custom words for specific languages through DictionaryManager.cs.

TODO

  • Implement custom word management (add/remove custom words).
  • Allow dynamic enabling/disabling of spell checking.
  • Improve performance for larger text inputs.
  • Include dictionary files for multiple languages.

Contributing

Feel free to contribute by submitting pull requests, reporting issues, or suggesting features.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.0 164 9/24/2024
0.2.0 123 9/17/2024
0.1.0 111 9/16/2024