Tip: Wrap In Quotes IDE script

Other editors have a feature where highlighting text and pressing a quote character will wrap the selected text in quotes rather than overwriting it. I wrote an IDE script to do the same and more. It will quote selected text, handle multiline text by inserting “EndOfLine” and insert matching quotes with your cursor between them when no text is selected.

const kQuote = """"

dim s as string
s = SelText

dim eol as string
if s.InStr( &u0D + &u0A ) <> 0 then
  eol = &u0D + &u0A
elseif s.InStr( &u0D ) <> 0 then
  eol = &u0D
elseif s.InStr( &u0A ) <> 0 then
  eol = &u0A
end if

if eol <> "" then
  dim lines() as string
  lines = Split( s, eol )
  s = join( lines, kQuote + " + EndOfLine + _" + eol + kQuote )
end if

s = kQuote + s + kQuote

dim start as integer
start = SelStart
SelText = s
SelStart = start + 1
SelLength = s.Len - 2

I assigned it to cmd-shift-’ (aka cmd-"). If the script name is “Wrap In Quotes.xojo_script”, on the Mac you can use System Preferences -> Keyboard to assign the keyboard shortcut by creating an App Shortcut for Xojo with the entry “File->IDE Scripts->Wrap In Quotes.xojo_script”. Or you can use the Xojo Preferences.