Scripting quotes and parenthesis

While working in another product this morning, I noticed a new feature that was called out and thought it would make a good example of things that can be done with IDE scripting.

The feature in question allows you to easily wrap the current selection in quotes or in parenthesis. A lot of other editors do this with smart quotes or smart parenthesis, but not Xojo. It only requires 5 lines of actual code including a comment for the keyboard shortcut.

// KeyboardShortcut = CMD-SHIFT-9
// Equivalent of CMD/CTRL-(

Dim s As String = SelText // Get the selection from the current editor

If s <> "" Then // If the selection isn't empty
     // Replace the selection with the string enclosed in parenthesis
    SelText = "( " + s + " )"
End If

If you want the same thing for quotes, it would look like this:

// KeyboardShortcut = CMD-SHIFT-'
// equivalent of CMD/CTRL-"

Dim s As String = SelText // Get the selection from the current editor

If s <> "" Then // If the selection isn't empty
     // Replace the selection with the string enclosed in parenthesis
    SelText = """" + s + """"
End If
10 Likes