Getting IME composition right in a native editor
How we handle marked text, candidate changes, and the moment a phrase is accepted.

When you write Chinese with Pinyin, the first text on screen is often still a proposal. You keep typing, change a candidate, or choose a different phrase before accepting the result.
We built Phrase's editor to preserve that distinction. Visible text can still be in progress. On iOS, we use UITextInput's marked-text support to work with the input method while it revises a composition.
Letting a phrase remain unfinished
An input method editor, or IME, turns a sequence of input into the text you want to write. During that process, the input system can ask the editor to display provisional text. Apple's marked-text interface lets it update that text before the composition is committed.
We keep provisional composition separate from committed document edits. The current candidate can appear on the page without every revision becoming another ordinary entry in the document's history.
A composition can change candidates before acceptance. This architectural animation shows the state transition, using schematic labels rather than a particular keyboard.
Consider composing in the middle of a sentence. The candidate may get longer, shorter, or change entirely. The words around it need to survive each update. The input method may also be working on a selection within the provisional text itself.
Our editor has to preserve all of that context until the composition finishes or is canceled. Accepting a phrase and abandoning it lead to different results.
The page keeps moving around it
A longer candidate can push text onto a new line. Its marked range and cursor need to move with it. The system may ask about the writing position during those updates.
We connect composition to the same layout and selection behavior used for ordinary editing. A candidate should fit into the paragraph where you are writing, including when the line wraps or the keyboard changes the space on screen.
Commands need that context too. A key can belong to the input method while it is choosing a candidate. If we treat it as a document command too early, we interrupt the phrase before you have finished it.
This is why we treat IME composition as part of the editor's behavior, alongside cursor placement and keyboard editing.
Keeping undo about the writing
Several candidate updates can lead to one accepted phrase. We keep those provisional updates out of ordinary edit history so the history reflects the writing you committed.
Composition can also replace a selection that already contains text. Cancellation then has to preserve the surrounding document, and committing has to leave a sensible place for the next edit. We handle those transitions as part of the same editing operation.
After acceptance, you can continue the sentence, revise it, or undo the committed edit. The intermediate candidates belong to the composition that produced it.
Testing the part before acceptance
Pasting a finished sentence skips the interaction we need to test. It shows text display and insertion, but never exercises a candidate changing while the sentence is in progress.
Our composition checks focus on the transitions: updating provisional text, replacing a selection, committing, canceling, and continuing afterward. Those are the points where the input method and the document have to agree.
Try it with your everyday keyboard in Phrase for iPhone. Change a candidate in the middle of a paragraph, accept it, and carry on. The surrounding sentence stays part of the same editing session.
Our technical overview explains where UITextInput fits on iOS and how our Mac editor connects through NSTextInputClient.