|
Ultralight C API 2.0.0
|
Text-editing interface for a View.
#include <Ultralight/CAPI/CAPI_Editor.h>
The C editor functions run editing commands and manage composition state for the focused element in a View.
Standard keyboard shortcuts like Ctrl+C and Ctrl+V run automatically when you dispatch key events to a View. You use the editor functions to connect native controls like Edit menus and on-screen keyboards directly to the page, or to relay text from an OS input method.
This example updates native Edit menu items before display and runs the command the user picks:
Call ulViewGetEditor() with a ULView handle to obtain its editor. The returned ULEditor is borrowed (it's never NULL), so you don't destroy it yourself. It belongs to the handle you passed and stays valid until you destroy that handle with ulDestroyView().
When you host a View directly, register the editing callbacks in <Ultralight/CAPI/CAPI_View.h> to coordinate an OS input method with the page:
For the complete input method lifecycle and candidate window placement rules, see <Ultralight/Editor.h>.
When styling composition clauses for ulEditorSetComposition(), zero-initialize each ULCompositionSegment struct. A zero-initialized ULColor represents an unset color.
This function updates the in-progress composition text and styles the active clause with a thick underline:
Classes | |
| struct | ULCompositionRange |
| A range of a composition's text, in UTF-16 code units (see ulEditorSetComposition()). More... | |
| struct | ULCompositionSegment |
| Underline style for part of a composition's text (see ulEditorSetComposition()). More... | |
| struct | ULEditableState |
| The conditions that decide whether an input method should be active. More... | |
Functions | |
| ULEditor | ulViewGetEditor (ULView view) |
| Get the editor for a View. | |
| bool | ulEditorExecute (ULEditor editor, ULEditorCommand command) |
| Run an editing command. | |
| bool | ulEditorCanExecute (ULEditor editor, ULEditorCommand command) |
| Whether or not a command would do anything right now. | |
| bool | ulEditorInsertText (ULEditor editor, ULString text) |
| Insert text at the caret, replacing the selection (the same as typing it). | |
| ULRect | ulEditorGetCaretBounds (ULEditor editor) |
| Get the bounds of the caret. | |
| bool | ulEditorSetComposition (ULEditor editor, ULString text, const ULCompositionSegment *segments, size_t num_segments, ULCompositionRange selection) |
| Set or update the in-progress text of an input method's composition. | |
| bool | ulEditorCommitComposition (ULEditor editor, ULString text) |
| Replace the active composition with the input method's final text. | |
| bool | ulEditorFinishComposition (ULEditor editor) |
| Keep the active composition's in-progress text as final text. | |
| bool | ulEditorCancelComposition (ULEditor editor) |
| Cancel the active composition and remove its text. | |
| bool | ulEditorHasComposition (ULEditor editor) |
| Whether or not a composition is active. | |
| ULRect | ulEditorGetCompositionBounds (ULEditor editor) |
| Get the bounds of the active composition's text, in viewport CSS pixels. | |
| unsigned int | ulEditorGetCompositionCharacterCount (ULEditor editor) |
| Get the length of the active composition's text, in UTF-16 code units. | |
| ULRect | ulEditorGetCompositionCharacterBounds (ULEditor editor, unsigned int index) |
| Get the bounds of one character of the active composition's text, in viewport CSS pixels. | |
| bool | ulEditorGetSelectionOffsets (ULEditor editor, unsigned int *start, unsigned int *end) |
| Get the selection's offsets within the focused element's text. | |
| ULString | ulEditorGetTextInRange (ULEditor editor, unsigned int start, unsigned int end) |
| Get part of the focused element's text (see ulEditorGetSelectionOffsets() for the offsets). | |
| bool | ulEditorReplaceTextInRange (ULEditor editor, unsigned int start, unsigned int end, ULString text) |
| Replace part of the focused element's text (see ulEditorGetSelectionOffsets() for the offsets). | |
| bool | ulEditorGetCompositionOffsets (ULEditor editor, unsigned int *start, unsigned int *end) |
| Get the active composition's offsets within the focused element's text (see ulEditorGetSelectionOffsets() for the offsets). | |
| bool ulEditorCancelComposition | ( | ULEditor | editor | ) |
Cancel the active composition and remove its text.
| editor | The editor. |
| bool ulEditorCanExecute | ( | ULEditor | editor, |
| ULEditorCommand | command ) |
Whether or not a command would do anything right now.
You can use this to grey out items in a native menu.
| editor | The editor. |
| command | The command to check. |
Replace the active composition with the input method's final text.
With no active composition, this inserts text at the caret.
| editor | The editor. |
| text | The final text. |
| bool ulEditorExecute | ( | ULEditor | editor, |
| ULEditorCommand | command ) |
Run an editing command.
| editor | The editor. |
| command | The command to run. |
| bool ulEditorFinishComposition | ( | ULEditor | editor | ) |
Keep the active composition's in-progress text as final text.
Call this when the input method closes without committing or cancelling (eg, focus moves away mid-composition).
| editor | The editor. |
Get the bounds of the caret.
The rect is in viewport CSS pixels (the same space as ulViewFireMouseEvent()). Multiply by ulViewGetDeviceScale() for device pixels.
| editor | The editor. |
Get the bounds of the active composition's text, in viewport CSS pixels.
You can use this as the area a candidate window shouldn't cover.
| editor | The editor. |
Get the bounds of one character of the active composition's text, in viewport CSS pixels.
You can use this to place a candidate window. Anchor it on the composition's first character (index 0) so it doesn't move as the candidates change.
| editor | The editor. |
| index | The character's offset within the composition's text, in UTF-16 code units. |
| unsigned int ulEditorGetCompositionCharacterCount | ( | ULEditor | editor | ) |
Get the length of the active composition's text, in UTF-16 code units.
| editor | The editor. |
| bool ulEditorGetCompositionOffsets | ( | ULEditor | editor, |
| unsigned int * | start, | ||
| unsigned int * | end ) |
Get the active composition's offsets within the focused element's text (see ulEditorGetSelectionOffsets() for the offsets).
You can use this to report the input method's marked range.
| editor | The editor. |
| start | Set to the composition's start. |
| end | Set to the composition's end (exclusive). |
| bool ulEditorGetSelectionOffsets | ( | ULEditor | editor, |
| unsigned int * | start, | ||
| unsigned int * | end ) |
Get the selection's offsets within the focused element's text.
The offset functions (this, ulEditorGetTextInRange(), ulEditorReplaceTextInRange(), and ulEditorGetCompositionOffsets()) use UTF-16 code units into the text of the focused text field or editable region. For <input> and <textarea>, they match the element's selectionStart and selectionEnd.
| editor | The editor. |
| start | Set to the selection's start. |
| end | Set to the selection's end (the same as start for a caret). |
Get part of the focused element's text (see ulEditorGetSelectionOffsets() for the offsets).
Offsets past the end of the text are clamped to it.
| editor | The editor. |
| start | The start offset. |
| end | The end offset (exclusive). |
| bool ulEditorHasComposition | ( | ULEditor | editor | ) |
Whether or not a composition is active.
| editor | The editor. |
Insert text at the caret, replacing the selection (the same as typing it).
| editor | The editor. |
| text | The text to insert. |
| bool ulEditorReplaceTextInRange | ( | ULEditor | editor, |
| unsigned int | start, | ||
| unsigned int | end, | ||
| ULString | text ) |
Replace part of the focused element's text (see ulEditorGetSelectionOffsets() for the offsets).
This edits the same way typing does. The edit is one undo step, and the caret ends up after the new text. You can use this for an input method's replacement ranges (eg, the macOS accent picker replaces the character it targets).
Offsets past the end of the text are clamped to it.
| editor | The editor. |
| start | The start offset. |
| end | The end offset (exclusive). |
| text | The new text (an empty string deletes the range). |
| bool ulEditorSetComposition | ( | ULEditor | editor, |
| ULString | text, | ||
| const ULCompositionSegment * | segments, | ||
| size_t | num_segments, | ||
| ULCompositionRange | selection ) |
Set or update the in-progress text of an input method's composition.
The first call starts a composition and replaces the selection. Later calls replace the previous in-progress text.
| editor | The editor. |
| text | The full in-progress text. Pass an empty string to remove it (the same as ulEditorCancelComposition()). |
| segments | Underline styles for parts of the text (eg, one per clause). Pass NULL to underline all of it. |
| num_segments | The number of entries in segments. |
| selection | The caret or selection within text, in UTF-16 code units. |
Get the editor for a View.
| view | The View. |
| enum ULEditableType |
The kind of element that holds keyboard focus (see ULEditableState).
| enum ULEditorCommand |
The editing commands you can run with ulEditorExecute().
Most commands act on editable text (a text field or an editable region). Copy, SelectAll, and the selection commands (the AndModifySelection forms, SelectWord, SelectLine, SelectParagraph, and Unselect) also work on a selection in regular page content.
Every caret motion has an AndModifySelection form that extends the selection instead of moving the caret (the Shift-key behavior).
| enum ULEnterKeyHint |
| enum ULInputMode |