Skip to content

feat(qt): Qt 终端接入 IME 组合/提交/取消 (#155) - #205

Merged
JavaZeroo merged 1 commit into
mainfrom
feat/qt-ime-composition
Oct 29, 2026
Merged

JavaZeroo merged 1 commit into
mainfrom
feat/qt-ime-composition

Conversation

@JavaZeroo

Copy link
Copy Markdown
Owner

内容

#155 的第一个产品切片:让 Qt 终端接入输入法的组合、提交与取消。

  • 打开 Qt::WA_InputMethodEnabled(此前显式关闭);
  • 实现 inputMethodQuery:返回光标格矩形(供候选窗定位)、空 surrounding text/selection;
  • 实现 inputMethodEvent:
    • preeditString() 只作为界面预览(在光标处带下划线绘制),不写入会话;
    • commitString() 以 UTF-8 发送给会话,随后清空 preedit;
    • 取消即"空 preedit",因此不会有半截文本被写入。

边界

  • 只做提交/取消语义与光标定位,不做候选窗自绘(候选窗仍由系统 IME 提供);
  • 不做 Ctrl-C/ESC 等按键与 IME 的交互仲裁([R2][输入验收] Qt IME 候选窗与固定拼音交叉验证 #155 的后续项);
  • 行为验证需要固定拼音 + 真实 IME 的 VM 实验,本 PR 只交付代码路径;hosted 的 qt-cpp-windows 作业负责编译验证。

测试

本地无 Qt SDK 构建路径(configure 未找到 Qt),因此本 PR 的编译验证依赖 CI 的 Qt 作业;运行期验证列在 #155 的下一步。

Refs #155

… refs #155

Enables WA_InputMethodEnabled, answers the ime cursor rectangle query, previews the preedit with an underline and sends only the committed UTF-8 text, so cancelling writes nothing.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T20:37:08.601282Z dea6065 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dea60655db

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const QString commit = event->commitString();
if (!commit.isEmpty()) {
model_.send(commit.toUtf8());
preedit_.clear();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the new preedit when an event also commits text

When an IME commits part of a composition while continuing the remainder, a single event can contain both a nonempty commitString() and a nonempty preeditString(). This handler first stores the new preedit, then unconditionally clears it, making the ongoing composition disappear until another preedit event arrives. Qt's event contract treats the commit and replacement preedit as separate operations. Forward the committed text while retaining the event's new preedit; an empty preedit already handles composition completion or cancellation.

Useful? React with 👍 / 👎.

Comment on lines +129 to +131
if (query == Qt::ImCursorRectangle && grid_ready_) {
const auto& screen = model_.screen();
return QRect(margin + screen.column * cell_width_, margin + screen.row * cell_height_, cell_width_, cell_height_);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Notify the input method when the caret rectangle changes

During an active composition, shell output or a resize/font change can move the terminal caret, but refresh_session() only schedules painting and no code calls QGuiApplication::inputMethod()->update(...). Returning the latest rectangle from this query does not notify the platform that it changed: Qt requires input items to report query changes, and the pinned Qt 6.10.3 Windows implementation repositions the native candidate window through cursorRectangleChanged. Consequently, the preview can move while the candidate window remains at its previous position. Notify the input method with Qt::ImCursorRectangle when the focused terminal's caret geometry changes.

Useful? React with 👍 / 👎.

@JavaZeroo
JavaZeroo merged commit f84dd01 into main Oct 29, 2026
6 checks passed
JavaZeroo added a commit that referenced this pull request Oct 31, 2026
#165 的实现已被 #205/#230 取代(main 上已有组合/提交/取消),但两份计划文档在 main 缺失:
qt-ime-integration-plan.md、qt-ime-native-observation-plan.md。
仍为纯新增,不修改 main 已有文件。
JavaZeroo added a commit that referenced this pull request Oct 31, 2026
#165 的实现已被 #205/#230 取代(main 上已有组合/提交/取消),但两份计划文档在 main 缺失:
qt-ime-integration-plan.md、qt-ime-native-observation-plan.md。
仍为纯新增,不修改 main 已有文件。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant