-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Show input method composition in text fields #10195
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,6 +289,25 @@ function EditClass:Draw(viewPort, noTooltip) | |
| local marginL = textX - x - 2 | ||
| local marginR = self.controls.scrollBarV:IsShown() and 14 or 0 | ||
| local marginB = self.controls.scrollBarH:IsShown() and 14 or 0 | ||
| -- Focusing a single-line field selects all of it. Typing would replace | ||
| -- that selection, so drop it as soon as an input method starts composing, | ||
| -- which also puts the caret where the composition belongs. | ||
| if self.hasFocus and main.imePreedit and main.imePreedit ~= "" and self.sel and self.sel ~= self.caret then | ||
| -- Collapse to the end of the selection: composed text is appended | ||
| -- there, so the caret and the candidate window belong there too. | ||
| self.caret = m_max(self.caret, self.sel) | ||
| self.sel = nil | ||
| end | ||
| local viewOriginX, viewOriginY = textX, textY | ||
| if self.hasFocus and SetIMECaretRect and not self.lineHeight then | ||
| -- Keep the input method informed even before composing starts, | ||
| -- otherwise the candidate window opens at a stale position. A | ||
| -- selection collapses to its end, which is where typing continues. | ||
| local caretPos = self.sel and m_max(self.caret, self.sel) or self.caret | ||
| local head = self.buf:sub(1, caretPos - 1) | ||
| SetIMECaretRect(viewOriginX + DrawStringWidth(textHeight, self.font, head) - self.controls.scrollBarH.offset, | ||
| viewOriginY, 1, textHeight) | ||
| end | ||
| SetViewport(textX, textY, width - 4 - marginL - marginR, height - 4 - marginB) | ||
| if not self.hasFocus then | ||
| if self.buf == '' and self.placeholder then | ||
|
|
@@ -413,6 +432,22 @@ function EditClass:Draw(viewPort, noTooltip) | |
| DrawString(textX, textY, "LEFT", textHeight, self.font, pre) | ||
| end | ||
| textX = textX + DrawStringWidth(textHeight, self.font, pre) | ||
| if self.hasFocus then | ||
| -- Text the input method is still composing sits at the caret, | ||
| -- underlined to show it isn't committed yet. | ||
| local preedit = main.imePreedit | ||
| if preedit and preedit ~= "" then | ||
| local preeditWidth = DrawStringWidth(textHeight, self.font, preedit) | ||
| DrawString(textX, textY, "LEFT", textHeight, self.font, self.textCol .. preedit) | ||
| SetDrawColor(self.textCol) | ||
| DrawImage(nil, textX, textY + textHeight - 1, preeditWidth, 1) | ||
| textX = textX + preeditWidth | ||
| end | ||
| if SetIMECaretRect then | ||
| -- Refine the position now that the composition width is known. | ||
| SetIMECaretRect(viewOriginX + textX, viewOriginY + textY, 1, textHeight) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Native macOS IME behavior was not exercised in this review. AI-assisted review disclosure: This finding was identified during a review using OpenAI Codex. |
||
| end | ||
| end | ||
| if self.protected and #post > 0 then | ||
| DrawString(textX, textY, "LEFT", textHeight, self.font, string.rep(protected_replace, #post)) | ||
| else | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IME composition is still skipped in multiline editors such as Notes.
NotesTabsetslineHeight = 16, so this guard disables caret reporting and the preedit-rendering block below is bypassed. Users therefore still compose blindly in Notes, with no current caret rectangle for the candidate window. Could the multiline draw path receive equivalent preedit rendering and caret positioning?Native macOS IME behavior was not exercised in this review.
AI-assisted review disclosure: This finding was identified during a review using OpenAI Codex.