REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: offset-to-caret


This function is provided to convert from an xy offset within a text face to a character index within a string. It is mainly used for text editing and text mapping operations such as for colored or hyperlinked text.

Here is an interesting example. When you click your mouse on the upper text face, the string from that position forward will be shown in the lower text face.

view layout [
    body 80x50 "This is an example string."
        feel [
            engage: func [face act event] [
                if act = 'down [
                    bx/text: copy offset-to-caret
                        face event/offset
                    show bx
    bx: body 80x50 white black

When the top face is clicked, the event/offset contains the xy offset that is converted to a string index position with offset-to-caret. The string from that point forward is copied and displayed in the lower text box (bx).

Note that the string does not have to be displayed for this function to work. Also remember that when making changes to the contents of strings that are longer than 200 characters, you must set the text face line-list to NONE to force the recomputation of all line breaks.

  TOC < Back Next > - WIP Wiki Feedback Admin