Skip to content

Commit

Permalink
feat(tsf): support user defined preedit display type
Browse files Browse the repository at this point in the history
- add config option `style/preedit_type(composition|preview)`
  • Loading branch information
nameoverflow authored and Prcuvu committed Feb 25, 2018
1 parent cba4935 commit f76379b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
36 changes: 30 additions & 6 deletions RimeWithWeasel/RimeWithWeasel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,20 +458,36 @@ bool RimeWithWeaselHandler::_Respond(UINT session_id, EatLine eat)
if (is_composing)
{
actions.insert("ctx");
messages.push_back(std::string("ctx.preedit=") + ctx.composition.preedit + '\n');
if (ctx.composition.sel_start <= ctx.composition.sel_end)
switch (m_ui->style().preedit_type)
{
messages.push_back(std::string("ctx.preedit.cursor=") +
std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start)) + ',' +
std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end)) + '\n');
case weasel::PREVIEW:
if (ctx.menu.num_candidates > 0)
{
std::string first = ctx.menu.candidates[0].text;
messages.push_back(std::string("ctx.preedit=") + first + '\n');
messages.push_back(std::string("ctx.preedit.cursor=") +
std::to_string(utf8towcslen(first.c_str(), 0)) + ',' +
std::to_string(utf8towcslen(first.c_str(), first.size())) + '\n');
break;
}
// no candidates, fall back to composition
case weasel::COMPOSITION:
messages.push_back(std::string("ctx.preedit=") + ctx.composition.preedit + '\n');
if (ctx.composition.sel_start <= ctx.composition.sel_end)
{
messages.push_back(std::string("ctx.preedit.cursor=") +
std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start)) + ',' +
std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end)) + '\n');
}
break;
}
}
RimeFreeContext(&ctx);
}

// configuration information
actions.insert("config");
messages.push_back(std::string("config.inline_preedit=") + std::to_string((int) m_ui->style().inline_preedit) + '\n');
messages.push_back(std::string("config.inline_preedit=") + std::to_string((int)m_ui->style().inline_preedit) + '\n');

// summarize

Expand Down Expand Up @@ -520,6 +536,14 @@ static void _UpdateUIStyle(RimeConfig* config, weasel::UI* ui, bool initialize)
{
style.inline_preedit = !!inline_preedit;
}
char preedit_type[20] = { 0 };
if (RimeConfigGetString(config, "style/preedit_type", preedit_type, sizeof(preedit_type) - 1))
{
if (!std::strcmp(preedit_type, "composition"))
style.preedit_type = weasel::COMPOSITION;
else if (!std::strcmp(preedit_type, "preview"))
style.preedit_type = weasel::PREVIEW;
}
Bool display_tray_icon = False;
if (RimeConfigGetBool(config, "style/display_tray_icon", &display_tray_icon) || initialize)
{
Expand Down
14 changes: 7 additions & 7 deletions WeaselTSF/Composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ void WeaselTSF::_UpdateComposition(ITfContext *pContext)

if (ok)
{
bool composing = _IsComposing();
if (!commit.empty())
{
// 修复顶字上屏的吞字问题:
Expand All @@ -289,13 +288,12 @@ void WeaselTSF::_UpdateComposition(ITfContext *pContext)
// 此时由于第五码的输入,composition 应是开启的,同时也要在输入处插入顶字。
// 这里先关闭上一个字的 composition,然后为后续输入开启一个新 composition。
// 有点 dirty 但是 it works ...
if (composing) {
if (_IsComposing()) {

This comment has been minimized.

Copy link
@lotem

lotem Feb 25, 2018

Member

@nameoverflow This is part of your previous work-around. Is the issue resolved without the hack?

This comment has been minimized.

Copy link
@nameoverflow

nameoverflow Feb 25, 2018

Author Member

Well in fact it could be split into another fix.
I think i mixed a debug branch with a develop branch, which have same name (

_EndComposition(pContext);
composing = false;
}
_InsertText(pContext, commit);
}
if (status.composing && !composing)
if (status.composing && !_IsComposing())
{
if (!_fCUASWorkaroundTested)
{
Expand All @@ -309,12 +307,14 @@ void WeaselTSF::_UpdateComposition(ITfContext *pContext)
}
_StartComposition(pContext, _fCUASWorkaroundEnabled && !config.inline_preedit);
}
else if (!status.composing && composing) {
else if (!status.composing && _IsComposing())
{
_EndComposition(pContext);
composing = false;
}
if (composing && config.inline_preedit)
if (_IsComposing() && config.inline_preedit)
{
_ShowInlinePreedit(pContext, context);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions include/WeaselUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ namespace weasel
INLINE_PREEDIT_CAPABLE = 1,
};

enum PreeditType
{
COMPOSITION,
PREVIEW
};

struct UIStyle
{
std::wstring font_face;
int font_point;
bool inline_preedit;
PreeditType preedit_type;
bool display_tray_icon;
// layout
LayoutType layout_type;
Expand Down Expand Up @@ -55,6 +62,7 @@ namespace weasel
UIStyle() : font_face(),
font_point(0),
inline_preedit(false),
preedit_type(COMPOSITION),
display_tray_icon(false),
layout_type(LAYOUT_VERTICAL),
min_width(0),
Expand Down
1 change: 1 addition & 0 deletions output/data/weasel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ style:
horizontal: false
fullscreen: false
inline_preedit: false
preedit_type: composition
display_tray_icon: false
layout:
min_width: 160
Expand Down

0 comments on commit f76379b

Please sign in to comment.