Christian K?hrt wrote:
> I got the following problem:
> - I wanna split an element to insert another elmenent
> - avoid the split when the cursor is on the first or last position
> inside the element to split (because a split in this situation results
> an element without content) .. instead I want to use the insert after/
> before command
> - the idea was to use the dotSelected variable and the string-length()
> to check if the cursor is in the first or last position of my element
> content
>
> <sequence>
> <pass>
> <command name="selectNode"
> parameter="self[implicitElement]
> {http://www.xmlmind.com/xmleditor/schema/ELearning/schema}Emphasis"/>
> <test expression="($dotOffset > 0) and
> ($dotOffset < string-length($dot))"/>
> <command name="split"
> parameter="[implicitElement]"/>
> <command name="insert"
> parameter="before[implicitElement]
> {http://www.xmlmind.com/xmleditor/schema/ELearning/schema}InternetLink"/>
> </pass>
> </sequence>
>
> this is my pass section.
> <http://dict.leo.org/se?lp=ende&p=lURE.&search=unfortunately>
> this works fine as long as I click from "outside" the Emphasis element
> in it. But when I enter this element by moving the cursor in it seems
> like that the dotSelected variable is set only once at the beginning of
> the content of the Emphasis element to 0.
>
No the $dotOffset variable is always up to date. (Use get+alert to check
this if you want.)
In my opinion, your problems comes from your very complex pass section.
Please try to make your macro as simple as possible (even if it is not
perfect in terms of detecting whether it can executed or not!).
Example: the macro below splits a DocBook emphasis to 2 parts and
converts *second* part to an ulink.
---
<binding>
<keyPressed code="F2" />
<command name="test" />
</binding>
<command name="test">
<macro>
<sequence>
<command name="selectNode"
parameter="self[implicitElement] emphasis"/>
<test expression="($dotOffset > 0) and
($dotOffset < string-length($dot))"/>
<command name="split" parameter="[implicitElement]"/>
<command name="convert" parameter="[implicitElement] ulink"/>
</sequence>
</macro>
</command>
---
If you want to convert first part or if you want to wrap (instead of
converting) any of the split parts, this is easy to do.