fcitx/fcitx5

Let CommonCandidateList to be able to accept alternative selection key

Closed this issue · 2 comments

Summary

Currently a developer can only set one set of selection keys to the CommonCandidateList by calling setSelectionKey. However, lots of users in Taiwan are expecting that they can use not only the number keys on the top of the keyboard but also the keys on the num pad, and it looks like we cannot let the users to do so with existing API.

Currently we can use the following code to set the selection keys

auto selectionKeys = fcitx::Key::keyListFromString("1 2 3 4 5 6 7 8 9");
candidateList->setSelectionKey(selectionKeys);

I wish fcitx could provide API like:

auto selectionKeys = fcitx::Key::keyListFromString("1 2 3 4 5 6 7 8 9");
candidateList->setSelectionKey(selectionKeys);
auto alternativeSelectionKeys = fcitx::Key::keyListFromString("NUM_1 NUM_2 NUM_3 NUM_4 NUM_5 NUM_6 NUM_7 NUM_8 NUM_9");
candidateList->setAlternativeSelectionKey(alternativeSelectionKeys);

I believe you have some misunderstanding on what this API does.

This API has nothing to do with how the key is handled. This API is used as a convenient helper to convert the key into the "Label" of candidate. The reason why this API is provided, is simply because it behaves differently from Key::toString, in order to produce a compact string for display candidates (E.g. Alt+1 will generate A-1).

If you want to implement the feature you describe, just simple write the code to handle it. You are looking for Key::keyListIndex.

        int idx = event.key().keyListIndex(selectionKeys);
        if (idx == -1) {
            idx = event.key().keyListIndex(numpadSelectionKeys);
        }

        if (idx >= 0) {
             .......
        }

Thanks for your help. I did misunderstand the API.