Skip to main content
1-Visitor
January 17, 2013
Question

Restoring cursor position

  • January 17, 2013
  • 2 replies
  • 1041 views

Good day!


Let us mark cursor position in the form of "|" sign.


For example, we have the following node in Arbortext Editor 5.2.


<node1>This is a sim|ple text.</node1>


Then my Java plugin encloses part of text with a "b" and "i" nodes:


<node1>This is a sim|ple text.</node1>


I want to restore the cursor position relatively to "node1", but the following code will not help me:


pos = oid_caret_pos(oid) // oid of the node1


...


goto_oid(oid, pos)



oid_caret_pos treats each non-text object (that is, markup, equations, tables, graphics) as one character.

    2 replies

    18-Opal
    January 17, 2013
    Hi Ilya--



    Right, oid_caret() and oid_caret_pos() won't help in this instance,
    since you are modifying the content after storing the location, which
    will throw the pointers off.



    Probably the easiest way to manage this would be to use some kind of
    marker like a PI to take the place of the caret, and then using that to
    find the caret position after modifying the content, something like
    this:



    # insert caret marker

    insert(");

    local caretoid = oid_caret();



    # make changes

    mark_up_text(oid1);



    # restore caret

    goto_oid(caretoid);

    oid_delete(caretoid);



    HTH.



    --Clay



    Clay Helberg

    Senior Consultant



    TerraXML

    1380 Forest Park Circle, Suite 100

    Lafayette, CO 80027
    1-Visitor
    January 30, 2013

    Thank you for this trick, it works fine.