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:
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.
We just return 0 here.
We use this to remove text from our buffer which we flagged as belonging to inline input.
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.
We just return the string System.
We just return 0.
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.
We return a TextRange which indicates the start & length of the characters in our buffer we have flagged as inline input.
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.
We return True / False depending on if we think we have focus or not.
We use this to process other key events.
We just return False.
We use this event to notify our text editor that it has lost focus.
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.
We use this to handle dragging a selection.
We use this to handle the end of a drag.
We pass this event up to the parent so that it can handle scrolling.
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).
We return a TextRange that describes the cursor position or selection start / length.
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.
We return the characters in our text buffer for the specified range.
We return the number of characters in our text buffer.