wshanks/tbkeys

Command to preformat text?

AGI-chandler opened this issue · 3 comments

I've been using this add-on for a while for one single thing, that being it's ability to format the selected text as "code" so it shows up in monospace when composing HTML e-mail.  I can't remember how I even figured it out, it was quite involved, and I think I had to enter a script in the developer console?  In the end I had a stroke of luck and found out it was simply cmd_code, so putting this in the compose key bindings did the trick:

{
  "ctrl+d": "cmd:cmd_code"
}

Now I just select some text and push ctrl+d, so convenient considering the alternative is selecting text then going to Format -> Text Style -> Code each time.

However, now I've found that <pre> works a lot better and was hoping I could update my shortcut.  Unfortunately, cmd_pre nor cmd_preformat work.  So wondering if you know the command or how I'm supposed to find it again?  Thanks

Try something like:

(function () {
  function selectWordUnderCursor() {
    if (!window.GetSelectionAsText()) {
      window.goDoCommand('cmd_charNext');
      window.goDoCommand('cmd_wordPrevious');
      window.goDoCommand('cmd_selectWordNext');
    }
  }
  selectWordUnderCursor();
  var s = window.GetSelectionAsText();
  s = '<pre>' + s + '</pre>';
  window.GetCurrentEditor().insertHTML(s);
})();

I wrote the command based on the Change Case button.

Change Case for Thunderbird
http://custombuttons.sourceforge.net/forum/viewtopic.php?f=4&t=289

Unicode code converter (use to decode custombutton:// url)
http://r12a.github.io/app-conversion/

Are you using tbkey or tbkeys-lite?

You cannot run arbitrary javascript with tbkeys-lite.

You can use the cmd shorthand and func shorthand with tbkeys and tbkeys-lite.

Use the cmd shorthand for calling a command using the goDoCommand method.

For example, "cmd:cmd_nextMsg" is the same as "window.goDoCommand('cmd_nextMsg');".

Use the func shorthand for calling a function on the window object without a parameter.

For example, "func:MsgNewMessage" is the same as "window.MsgNewMessage();".

There is a tbkeys.xpi link on the releases page.

Install
http://github.com/wshanks/tbkeys#install

Tips
http://forums.mozillazine.org/viewtopic.php?p=14872763#p14872763

Yeah tb-lite, I'd rather stick with that.  cmd_code is listed in https://github.com/mozilla/gecko-dev/blob/master/widget/CommandList.h for example but don't see anything about "pre".  I'm guessing there is no built-in command then, but how does TB do it?  Hmm, actually I have other add-on ThunderHTMLedit that puts "HTML" tab for the email, I forgot that was extra and so I just type <pre> in there and TB can still interpret it, just doesn't have commands for every HTML tag...  Oh well!