The following macro swaps the character before the caret with the character after the caret. It is useful if, like everybody, you are a bit dyslexic.
<command name="transposeChars"> <macro undoable="true" label="Transpose Characters"> <sequence> <test expression="not($selected) and not($mark) and $dotOffset > 0 and $dotOffset < string-length($dot)"/> <command name="selectTo" parameter="previousChar" /> <command name="cut" /> <command name="moveDotTo" parameter="nextChar" /> <command name="paste" parameter="into" /> </sequence> </macro> </command>
As a pseudo-command of a macro, test can be executed only if its
expression attribute evaluated as a boolean in the context specified by its
context attribute returns true.
Test is used in the above macro to ensure that the macro can be executed only if:
There is no node selection:
There is no text selection:
The caret is not before first character of a textual node:
$dotOffset > 0.
The caret is not after last character of a textual node:
$dotOffset < string-length($dot).
implicitElement seen in previous examples,
dotOffset are predefined variables mapped to the selection in XXE.