34. ensureSelectionAt

Parameter syntax:

[ 'selectElement' ]?

This command is intended to be bound to a mouse input. It is generally used by the macro-command which is bound to the drag appEvent in XMLmind XML Editor - Configuration and Deployment.

If the mouse is clicked anywhere inside the node or text selection, this command does nothing at all. That is, the selection is preserved (typically in order to be dragged). Otherwise this command selects the node clicked upon.

If the selectElement option is specified and the node clicked upon is not an element (e.g. a text node), then, it is its parent element which is selected.

XHTML example:

  <appEvent name="drag" />
  <command name="xhtml.drag" />

<command name="xhtml.drag">
      <!-- Either drag the selection or 
           select+drag the element clicked upon. -->
      <command name="ensureSelectionAt" parameter="selectElement" />

          <match context="$selectedElement" 
                 pattern="html:a[@href]|html:a[@href]//*" />
          <set variable="selectedElement" context="$selectedElement" 
               expression="(ancestor-or-self::html:a[@href])[last()]" />
          <get context="$selectedElement" expression="resolve-uri(@href)" />

          <match context="$selectedElement" pattern="html:img[@src]" />
          <get context="$selectedElement" expression="resolve-uri(@src)" />

        <!-- Default drag action. -->
        <command name="drag" />

See also drag.