31. ensureSelectionAt
Prev | Chapter 6. Commands written in the Java™ programming language | Next

## 31. 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:

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

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

          <choice>
            <sequence>
              <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)" />
            </sequence>

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

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

See also drag.

Prev | Up | Next
30. editPITarget | Home | 32. execute