Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adapt to mobile, backspace to hide the menu, generally mobile does not have esc key. #987

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/rime/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ bool Context::IsComposing() const {
return !input_.empty() || !composition_.empty();
}

bool Context::IsPredicting() const {
return !composition_.empty() && composition_.back().HasTag("prediction");
}

bool Context::HasMenu() const {
if (composition_.empty())
return false;
Expand Down
1 change: 1 addition & 0 deletions src/rime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RIME_API Context {
string GetScriptText() const;
Preedit GetPreedit() const;
bool IsComposing() const;
bool IsPredicting() const;
bool HasMenu() const;
an<Candidate> GetSelectedCandidate() const;

Expand Down
2 changes: 1 addition & 1 deletion src/rime/switcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ProcessResult Switcher::ProcessKeyEvent(const KeyEvent& key_event) {
int ch = key_event.keycode();
if (ch == XK_space || ch == XK_Return) {
context_->ConfirmCurrentSelection();
} else if (ch == XK_Escape) {
} else if (ch == XK_Escape || ch == XK_BackSpace) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems not reasonable. Your frontend should have the ability to hide itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前端确实有功能隐藏,就是比较麻烦。得先判断switcher已经显示,再手动发送XK_Escape按键。在switcher.cc直接添加,我觉是得更好的办法。一,不破坏原本逻辑。二,对所有移动端友好。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得没道理。

退格键是删除的意思但是这里没有输入。
他跟取消的含义不同,有时候能达到同样的结果那是因为正好删掉了当前状态显示的内容。

编辑之外这两个键也可能代表不同操作,比如用退格键回退到流程的上一层界面,ESC键可能是取消整个流程。

switcher 我设想中要允许输入命令。退格键现在没用,可留待今后扩展。现在弄混,就被动了。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,我理解的输入是用户要激活switcher需要向rime发送一个hotkey,然后Rime的向用户返回了结果,且结果是以candidate展现的,同时preedit也被修改了。这时再输入退格键,其实是用户取消了。
假如后续添加多层界面,用退格键做返回感觉也不冲突。

现在遇到问题是rime现在没有一个状态显示switcher已经激活。所以一般移动端的做法是。先读取一下hotkey-》监控用户是否输入hotkey-》switcher激活-》如果要取消的话就向rime发送esc键。上面的逻辑在没有配置esc的移动端都需要写一遍。正常移动端来讲都不会配置esc键。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在遇到问题是rime现在没有一个状态显示switcher已经激活。

这个确实有必要。粗看了一下实现,貌似不太容易加。

所以一般移动端的做法是。先读取一下hotkey-》监控用户是否输入hotkey-》switcher激活-》如果要取消的话就向rime发送esc键。上面的逻辑在没有配置esc的移动端都需要写一遍。正常移动端来讲都不会配置esc键。

没做过,不理解。
如果说前端能打开方案选单,那么关闭比打开还要简单吧。
还是说,用户得自己按快捷键打开方案选单?用户能按出打开方案选单的键,但是按不出 esc?
键盘是自己开发的吗,能加上 esc 键吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,用户一般是按快捷键来调出方案选单的。一般来说移动端的虚拟键盘都不会配置esc键的,因为esc键用处不大,还占地方。
如果能加一个状态标识那更好了。用户能根据当前状态做选择,且在虚拟键盘上有UI上的变化。比如当前是激活状态,那么虚拟键盘上的退格键就显示取消菜单。用户点击取消菜单按钮会向rime发送esc的键值。

Deactivate();
}
return kAccepted;
Expand Down
1 change: 1 addition & 0 deletions src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ typedef struct RIME_FLAVORED(rime_status_t) {
Bool is_simplified;
Bool is_traditional;
Bool is_ascii_punct;
Bool is_predicting;
} RIME_FLAVORED(RimeStatus);

typedef struct rime_candidate_list_iterator_t {
Expand Down
1 change: 1 addition & 0 deletions src/rime_api_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ RIME_DEPRECATED Bool RimeGetStatus(RimeSessionId session_id,
std::strcpy(status->schema_name, schema->schema_name().c_str());
status->is_disabled = Bool(Service::instance().disabled());
status->is_composing = Bool(ctx->IsComposing());
status->is_predicting = Bool(ctx->IsPredicting());
status->is_ascii_mode = Bool(ctx->get_option("ascii_mode"));
status->is_full_shape = Bool(ctx->get_option("full_shape"));
status->is_simplified = Bool(ctx->get_option("simplification"));
Expand Down