We’ve been using the TextInputCanvas to implement a text editor for the past few years. Its been a while since I looked at this code but here is some info that might help:
• TextRanges
I think these are 0 based.
• Incomplete Text Events
These are related to inline input such as CJK text entry. I think they may also be triggered for long key presses when the character can have an accent. We track when inline input starts and ends also also track which characters in our buffer are related to inline input.
• BaselineAtIndex
We just return 0 here.
• DiscardIncompleteText
We use this to remove text from our buffer which we flagged as belonging to inline input.
• DoCommand
We use this to handle commands such as:
a) CmdMoveLeft, CmdMoveLeftAndModifySelection, CmdMoveRight, CmdMoveRightAndModifySelection, CmdMoveUp, CmdMoveUpAndModifySelection, CmdMoveDown, CmdMoveDownAndModifySelection, CmdMoveToBeginningOfDocument, CmdMoveToBeginningOfDocumentAndModifySelection, CmdScrollToBeginningOfDocument, CmdMoveToEndOfDocument, CmdMoveToEndOfDocumentAndModifySelection, CmdScrollToEndOfDocument, CmdScrollPageUp, CmdScrollPageDown to move our internal cursor position.
b) CmdDeleteBackward & CmdDeleteForward to delete text.
c) CmdInsertNewline, CmdInsertLineBreak to insert a line break.
• FontNameAtLocation
We just return the string System.
• FontSizeAtLocation
We just return 0.
• GotFocus
We use this event to notify our text editor that it has received focus. We store the current focus state as a property in the class.
• IncompleteTextRange
We return a TextRange which indicates the start & length of the characters in our buffer we have flagged as inline input.
• InsertText
We use this to insert the supplied text into our text buffer. If the range parameter is supplied then we use that to replace the text at that range.
• IsEditable
We return True / False depending on if we think we have focus or not.
• KeyDown
We use this to process other key events.
• KeyFallsThrough
We just return False.
• LostFocus
We use this event to notify our text editor that it has lost focus.
• MouseDown
We use this to handle mouse down events which could invoke a context menu, the start of a drag to make a selection or change the current cursor position. We also have code that counts the clicks to handle double and triple clicking.
• MouseDrag
We use this to handle dragging a selection.
• MouseUp
We use this to handle the end of a drag.
• MouseWheel
We pass this event up to the parent so that it can handle scrolling.
• RectForRange
We return a REALbasic.Rect that has the Left & Top properties set to the x & y pixel position of the first character we have flagged as being inline. I think these have to be global (ie: including Window.Left & Window.Top).
• SelectedRange
We return a TextRange that describes the cursor position or selection start / length.
• SetIncompleteText
We use this to add text to our buffer and flag it as being inline. If replacementRange is set we use it to replace existing text. We ignore relativeSelection.
• TextForRange
We return the characters in our text buffer for the specified range.
• TextLength
We return the number of characters in our text buffer.