fcitx/fcitx5-chinese-addons

Feature request: Option for table engine to allow matching substrings.

Opened this issue · 7 comments

Right now, the only two options are prefix matching and exact matching.

But it would be quite handy for a table that I'm working on (emoticons) if we could optionally match anywhere in the key.

Looking at the code, this doesn't look entirely trivial, but if there is interest I'd be willing to take a crack at trying to implement it.

The table engine is not designed to be used with fuzzy segmentation. I'm not sure what you try to do with this, but what about you just put multiple key for the same value?

Is there another engine that would be better suited for tables with this use case?

Don't get me wrong, I could write a new one I suppose, but I'm still wrapping my head around the IM API.

@zelch you need to explain what you exactly want to do.

@wengxt My apologies.

The end goal is a decent interface for entering emoticons.

As an example, you have 💜, which has the name 'purple_heart'.

This really should come up for both starting to enter 'purple', and starting to enter 'heart', or even something silly like 'ple_hea'.

While some options exist, currently there doesn't seem to be anything which is configurable to be specific to emoticons (as opposed to general unicode for example), and which uses the fcitx5 user interface.

Perhaps the closest is im-emoji-picker, but the lack of properly using the fcitx5 UI is... Painful on wayland.

On the other hand, this is a case where the list of emoticon name/character sequences is just a table. And not even all that huge of a table.

@zelch I suggest you check quickphrase, which can be used globally everywhere with meta + ` by default.

Theres builtin configuration that has emoji already, with the emoji alpha code.
https://github.com/fcitx/fcitx5/blob/master/src/modules/quickphrase/quickphrase.d/emoji-eac.mb

While this is also prefix matching, you can extend with either lua or c++ to do whatever you want.

@wengxt I don't suppose you have an examples of extending quickphrase?

Example of extending quickphrase in C++

https://github.com/fcitx/fcitx5/blob/307d40802469ce8ef4d42ae85467907b575e0fac/src/modules/quickphrase/quickphrase_public.h#L48

https://github.com/fcitx/fcitx5-lua/blob/4c6b48631af963a63f81e6b03c9d73320c538ea0/src/addonloader/luaaddonstate.cpp#L380

See https://codedocs.xyz/fcitx/fcitx5/classfcitx_1_1AddonInstance.html on how to call the exported addon function.

Example of extending quickphrase in lua
https://github.com/fcitx/fcitx5-lua/blob/4c6b48631af963a63f81e6b03c9d73320c538ea0/src/imeapi/imeapi.lua#L132

Also if you use "keyboard" engine, you may already use the keyboard engine's language to query emoji

图片

图片

This is query using fcitx's built-in emoji db https://github.com/fcitx/fcitx5/blob/307d40802469ce8ef4d42ae85467907b575e0fac/src/modules/emoji/emoji_public.h#L24 which is derived from unicode cldr.

While API is Emoji::prefix, it's prefix on keyword. So apple should match any word that is a part of the keyword.

Though one thing to note is that keyboard engine tries to filter out the based on input and result length. If you have a better idea on this you may also improve the code here instead?
https://github.com/fcitx/fcitx5/blob/307d40802469ce8ef4d42ae85467907b575e0fac/src/im/keyboard/keyboard.cpp#L621