Thanks for your contribution.
Manuel Collado wrote:
> poster wrote:
>
>> I am still thinking this through, so bear with me. I understand that
>> XXE, at its core, should provide a primitive set of editing
>> operations. Document-specific ones can be defined by the document-type
>> author.
>>
>> My main question is: can the basic editing operations set of XXE be
>> improved?
>>
>> For example, document types typically define collections of things.
>> What would be appropriate primitive operations on these collections?
>> One that I see quite often is "move this item (up or down) within this
>> collection".
>>
>> As I understand it, I can do this today by "cut" and "paste" or "paste
>> after". However, this has a very different user feel than a "move",
>> where the element never disappears from the document. Imagine
>> selecting an element, and then visually stepping it up or down in its
>> containing collection.
>>
>> Would such an operation be appropriate for XXE to support?
>
>
> I've written commands that do that (see below). To move elements or sets
> of contiguous elements just select them, and press Ctrl-Alt-UP/DOWN as
> many times as required.
>
> <!--
> =======================================================================
> Move the explicitly selected element(s) before the preceding element
>
> ========================================================================
> -->
>
> <command name="moveBefore">
> <macro>
> <sequence>
> <!-- test for a preceding element, and record its location -->
> <match context="$selected" pattern="*[position() > 1]" />
> <set variable="newAnchor" context="$selected"
> expression="./preceding-sibling::*[1]" />
> <!-- copy the selected element(s) and record its location -->
> <command name="copy" parameter="[selectedNodes]" />
> <set variable="anchor" expression="$selectedNodes" />
> <!-- select now the preceding element -->
> <set variable="selected" expression="$newAnchor" />
> <choice>
> <sequence> <!-- try to complete the command -->
> <!-- paste (duplicate) the selection copy before the
> preceding element -->
> <command name="paste" parameter="before" />
> <!-- select the whole set of pasted elements and record its
> location -->
> <set variable="selected2" expression="$newAnchor" />
> <command name="selectNode"
> parameter="extendToPreviousSiblingOrNode" />
> <set variable="newAnchor" expression="$selectedNodes" />
> <!-- delete the original selected node(s) -->
> <set variable="selectedNodes" expression="$anchor" />
> <command name="delete" />
> <!-- reselect the moved element(s) -->
> <set variable="selectedNodes" expression="$newAnchor" />
> </sequence>
> <sequence> <!-- else, restore the original selection -->
> <set variable="selectedNodes" expression="$anchor" />
> </sequence>
> </choice>
> </sequence>
> </macro>
> </command>
>
> <binding>
> <keyPressed code="UP" modifiers="alt ctrl" />
> <command name="moveBefore" />
> </binding>
>
>
> <!--
> =======================================================================
> Move the explicitly selected element(s) after the following element
>
> ========================================================================
> -->
>
> <command name="moveAfter">
> <macro>
> <sequence>
> <!-- test for a following element, and record its location -->
> <match context="$selected2" pattern="*[position() <
> last()]" />
> <set variable="newAnchor" context="$selected2"
> expression="./following-sibling::*[1]" />
> <!-- copy the selected element(s) and record its location -->
> <command name="copy" parameter="[selectedNodes]" />
> <set variable="anchor" expression="$selectedNodes" />
> <choice>
> <sequence> <!-- there is an element after the following
> element -->
> <match context="$newAnchor" pattern="*[position() <
> last()]" />
> <!-- record the location past the following element -->
> <set variable="newAnchor2" context="$newAnchor"
> expression="./following-sibling::*[1]" />
> <!-- select now the following element -->
> <set variable="selected" expression="$newAnchor" />
> <choice>
> <sequence> <!-- try to complete the command -->
> <command name="paste" parameter="after" />
> <!-- select the whole set of pasted elements and record
> its location -->
> <set variable="selected2" expression="$newAnchor2" />
> <command name="selectNode"
> parameter="extendToPreviousSiblingOrNode" />
> <set variable="newAnchor" expression="$selectedNodes" />
> <!-- delete the original selected node(s) -->
> <set variable="selectedNodes" expression="$anchor" />
> <command name="delete" />
> <!-- reselect the moved element(s) -->
> <set variable="selectedNodes" expression="$newAnchor" />
> </sequence>
> <sequence> <!-- else, restore the original selection -->
> <set variable="selectedNodes" expression="$anchor" />
> </sequence>
> </choice>
> </sequence>
> <sequence> <!-- there are no elements after the following
> element -->
> <!-- select now the following element -->
> <set variable="selected" expression="$newAnchor" />
> <choice>
> <sequence> <!-- try to complete the command -->
> <command name="paste" parameter="after" />
> <!-- select the whole set of pasted elements and record
> its location -->
> <set variable="selected2" context="$newAnchor"
> expression="./following-sibling::*[last()]" />
> <set variable="newAnchor" expression="$selectedNodes" />
> <!-- delete the original selected node(s) -->
> <set variable="selectedNodes" expression="$anchor" />
> <command name="delete" />
> <!-- reselect the moved element(s) -->
> <set variable="selectedNodes" expression="$newAnchor" />
> </sequence>
> <sequence> <!-- else, restore the original selection -->
> <set variable="selectedNodes" expression="$anchor" />
> </sequence>
> </choice>
> </sequence>
> </choice>
> </sequence>
> </macro>
> </command>
>
> <binding>
> <keyPressed code="DOWN" modifiers="alt ctrl" />
> <command name="moveAfter" />
> </binding>
>
>
> This code in unnecessarily complex for moving set of nodes, because
> after pasting a set of nodes only the first one gets selected. My
> (tricky) code forces selection of the whole set of just pasted nodes.
>
> This way the command can be repeated to move further.
>
> [snipped]
>
> Hope this helps,