Pages: 1
Print
Author Topic: Move the text cursor between tags  (Read 1952 times)
bjorn
Member

Posts: 29



« on: February 12, 2014, 08:31:44 AM »

Hi.

In my macro I need to move the text cursor from one tag to its parent tag.

I got the name of the tag I what to move to, but can't figure out how to move the text cursor it self.

When the text cursor is inside the 'Link' tag I want to move the text cursor to the 'Para' tag in code.

<Para>Definitions
            <Link>Pt.4</Link>
</Para>


Its possible that I have to use the rng.SelectElement();  or rng.MoveToElement('Para');.
But can't figure it out.


Using XMetaL(R) Author Enterprise 8.0 Service Pack 1


thanks!
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: February 12, 2014, 02:07:45 PM »

If the selection is currently inside <Link> any of the following will work:

//XMetaL Script Language JScript:
//move selection forwards to Para element
Selection.MoveToElement("Para");

//XMetaL Script Language JScript:
//move selection backwards to Para element
Selection.MoveToElement("Para",false);

//XMetaL Script Language JScript:
//move a range forward to Para element
var rng = ActiveDocument.Range;
rng.MoveToElement("Para");
//(optional), make the range "visible"
rng.Select();

//XMetaL Script Language JScript:
//move a range backwards to Para element
var rng = ActiveDocument.Range;
rng.MoveToElement("Para",false);
//(optional), make the range "visible"
rng.Select();

There are many other APIs that could be used depending on your exact needs. If those needs are actually more complex than what you have described here then another solution might be better suited and might include combinations of the following. These are all of the "move a selection" APIs that directly manipulate it that I can think of.

SelectBeforeContainer()
SelectAfterContainer()
MoveRight()
MoveLeft()
SelectElement()
Collapse()
GotoNext()
GotoPrevious()
SelectBeforeNode()
SelectAfterNode()

The following properties might also be useful:
parentNode
containerNode

Not all of those will do what you want directly and will need to be used in combination with each other or with other APIs or properties.
Logged
Pages: 1
Print
Jump to:  

email us