Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command to preformat text? #123

Open
AGI-chandler opened this issue Jan 21, 2023 · 3 comments
Open

Command to preformat text? #123

AGI-chandler opened this issue Jan 21, 2023 · 3 comments

Comments

@AGI-chandler
Copy link

AGI-chandler commented Jan 21, 2023

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

@morat523035
Copy link

morat523035 commented Jan 21, 2023

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/

@morat523035
Copy link

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

@AGI-chandler
Copy link
Author

AGI-chandler commented Jan 21, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants