chewing / libchewing

libchewing - The intelligent phonetic input method library
https://chewing.im/
GNU Lesser General Public License v2.1
357 stars 89 forks source link

Rust version: chewing_handle_Left should not be absorbed when there's nothing in the buffer. #514

Closed wengxt closed 2 months ago

wengxt commented 2 months ago

To Reproduce

#include <chewing.h>
#include <iostream>
#include <string>
#include <cstdarg>
#include <vector>

void logger(void * /*context*/, int /*level*/, const char *fmt, ...) {
    std::va_list argp;
    va_start(argp, fmt);
    char onechar[1];
    int len = std::vsnprintf(onechar, 1, fmt, argp);
    va_end(argp);
    if (len < 1) {
        return;
    }
    std::vector<char> buf;
    buf.resize(len + 1);
    buf.back() = 0;
    va_start(argp, fmt);
    std::vsnprintf(buf.data(), len, fmt, argp);
    va_end(argp);
    std::cerr << buf.data() << std::endl;
}

int main() {
    auto *c = chewing_new();
    // chewing_set_logger(c, logger, nullptr);
    chewing_set_maxChiSymbolLen(c, 18);
    chewing_set_ChiEngMode(c, CHINESE_MODE);
    int selkey[10];
    for (size_t i = 0; i < 10; i++) {
        selkey[i] = '0' + (i + 1) % 10;
    }

    chewing_set_selKey(c, selkey, 10);
    chewing_set_candPerPage(c, 10);
    chewing_set_addPhraseDirection(c, 1);
    chewing_set_phraseChoiceRearward(c, 1);
    chewing_set_autoShiftCur(c, 1);
    chewing_set_spaceAsSelection(c, 1);
    chewing_set_escCleanAllBuf(c, 1);
    chewing_set_KBType(c, chewing_KBStr2Num("KB_DEFAULT"));
    chewing_handle_Left(c);
    std::cout << "CheckIgnore: " << chewing_keystroke_CheckIgnore(c) << std::endl;
    std::cout << "CheckAbsorb: " << chewing_keystroke_CheckAbsorb(c) << std::endl;
    std::cout << "commit_Check: " << chewing_commit_Check(c) << std::endl;

    return 0;
}

Expected behavior CheckIgnore: 1 CheckAbsorb: 0 commit_Check: 0

While it prints: CheckIgnore: 0 CheckAbsorb: 1 commit_Check: 0

Platform (please complete the following information):