Are you a fast typer?

Then you probably frequently run across the problem that your left index was quicker than expected and you end up with characters in the wrong sequence. I very otfen do ;-)

Andrew Brown sent in a neat little macro that swaps letters to bring them in the correct sequence again :

Sub transpose
' acb, 2001-2003
' very heavily commented trivial macro
' which demonstrates how to get at the text under the cursor
' and do something useful with it.
Dim oDocument as Object
Dim oText as Object
Dim oVCursor, oCursor As Object
Dim sWombat as string
    'shortcut to the active document
    oDocument=thiscomponent
    ' after this, an obscure call gets the current cursor position
    oVCursor = oDocument.currentcontroller.getViewCursor()
    ' but most cursor methods don't work with a view cursor
    ' so now I create an invisible cursor under it, to do the work.
    oText = oVCursor.getText()
    ' the Pitonyak hack
    oCursor=oText.createTextCursorByRange(oVCursor.getStart())
    ' grab the next character
    oCursor.goRight(1,TRUE)
    ' and save a copy of it (no clipboard)
    sWombat = ocursor.getString()
    ' delete the original (seems to be no obvious delete method)
    oCursor.setString("")
    ' next two lines move the invisible cursor
    ' back one letter before where it started
    oCursor.CollapseToStart()
    oCursor.goLeft(1,true)
    ' and now insert the previously cut character
    oText.insertString(oCursor.getStart(),sWombat,false)
    oVCursor.GoLeft(1,false) ' finally return the visible cursor whence it came
End Sub

Now assign that macro to a shortcut key using Tools - Customize.

Happy Sawpping!


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by fpe