ueno / libskk

Japanese SKK input method library
GNU General Public License v3.0
78 stars 27 forks source link

Add Customizable Completion Order Feature #91

Closed takaeda closed 3 weeks ago

takaeda commented 1 month ago

Overview

This PR introduces a feature to libskk that allows customization of the completion candidate order from various sources, including user dictionary and system dictionary.

Implementation Details

  1. Added CompletionSource abstract class:

    • Includes get_completions method and priority property
  2. Added DictCompletionSource class:

    • Implements CompletionSource to provide completion candidates from dictionaries
  3. Added CompletionService class:

    • Manages multiple CompletionSource instances
    • Provides completion candidates in order of priority
  4. Added new method to the Context class:

    • set_completion_order: Allows customization of completion order for normal and abbreviation modes
  5. Updated the State class:

    • Modified to use CompletionService for retrieving completion candidates

Default Completion Order

The default completion order for both normal mode and abbreviation mode is set to prioritize user dictionary completions over system dictionary completions.

How to Change Completion Order

Users can change the completion order by using the set_completion_order method of the Context class. For example:

var context = new Skk.Context(dictionaries);

CompletionSource[] sources = {
    new DictCompletionSource(user_dict, 20),
    new DictCompletionSource(system_dict, 10)
};

context.set_completion_order("normal", sources);
context.set_completion_order("abbrev", sources);

In this example, completion candidates from the user dictionary (priority 20) will be shown before those from the system dictionary (priority 10).

Testing Environment and Procedure

Environment

Test Procedure

The feature was tested using the following procedure:

  1. Obtain the source code:

    apt-get source libskk0

    This expands to libskk-1.0.5.

  2. Update the modified files: Copy the modified state.vala, context.vala, completion.vala and Makefile.am in libskk to libskk-1.0.5/libskk/.

  3. Build the package:

    cd libskk-1.0.5
    debuild -us -uc -b
  4. Install the built packages:

    cd ..
    sudo dpkg -i libskk*.deb gir1.2-skk-1.0_1.0.5-2_arm64.deb
  5. Restart fcitx5 to apply the changes.

This testing procedure ensures that the changes are properly integrated into the existing libskk package and work correctly with fcitx5-skk.

Related Issue

74

Acknowledgements

Thanks to the original author and maintainers of libskk for their great work.

Your review and feedback are appreciated.

takaeda commented 3 weeks ago

@ueno Thanks for the feedback! I believe I've reworked the implementation based on your suggestion.

The new implementation uses an array of "completion sources," which eliminates the need for predefined ordering combinations and makes it easier to add non-dictionary sources in the future.

Main updates:

  1. New CompletionSource and DictCompletionSource classes
  2. Added CompletionService to manage multiple completion sources
  3. New set_completion_order method in Context
  4. State class now uses the new completion service

I've updated the PR description. Please let me know if you have any further feedback or suggestions.

takaeda commented 3 weeks ago

@ueno Thank you for your positive feedback and for merging the changes. I'd be happy to work on adding unit tests for the new API in the near future.