stevencohn / OneMore

A OneNote add-in with simple, yet powerful and useful features
Mozilla Public License 2.0
2.6k stars 218 forks source link

Hotkey to apply "Code" style #1612

Open cspotcode opened 4 days ago

cspotcode commented 4 days ago

Problem to Solve

I often want to quickly paste or type code snippets formatted in monospace, but don't have any hotkey to do this. I have hotkeys for italics, headings 1-6, quotes, and to reset formatting to normal, but no hotkey for "Code."

New Feature/Solution

Keybinding to apply the "Code" style to selected text.

Vanilla OneNote has Ctrl+Alt+1-6 for headings and Ctrl+Shift+N to reset to "Normal." But I've always lamented the lack of a "Code" keybinding.

OneMore adds Ctrl+Alt+Shift+1-9, which is great! But no Code. I'm worried that if I rename the 7th style, Ctrl+Alt+Shift+7, from "Page Title" to "Code," it'll break "Apply styles to this page" and TOC features, because even though OneNote shows me monospace font, it secretly thinks the text is a "Page Title."

If OneMore added a "Code" keybind, then I could:

  1. Write or paste some code.
  2. Ctrl+Shift+Up to highlight it.
  3. Press new "Code" keybind -- Ctrl+Alt+C? -- to format as monospace.
  4. Press F6 or Alt-F6 to wrap in a (code) box.

Alternative Solutions

1314 could work, but the "Code" header eats up screen real-estate so I'm hoping to use the Alt+F6 "Text Box" instead.

I'm not sure that #1314 can be cleanly implemented, because it would destroy the formatting of selected text. This might be nice sometimes but not all the time, so it would need a way to opt-in or opt-out and that's more complex.

stevencohn commented 4 days ago

Ctrl+Alt+Shift+1-9 map to the first 9 custom styles. You have the ability to reorder your custom styles. As long as you keep "code" within that range, you're good to go.

Having another special key binding would present exactly the same naming problem that you mention. In other words, you still have to be careful to maintain the name. And remember that OneMore is translated to multiple languages so that key binding would need to be dynamic and set by the Settings dialog, adding quite a bit of complexity far above and beyond just using Ctrl+Alt+Shift+1-9.

Note also the OneMore Quick Style palette which you open using Ctrl+<comma> and then type "code" to apply your custom code style (or whatever you name your custom monospace style)

cspotcode commented 4 days ago

OneMore Quick Style palette

I didn't know about this, thank you! This solves my problem.

Having another special key binding would present exactly the same naming problem that you mention.

Ok, I had imagined it would be akin to OneNote's native Ctrl+Shift+N, which always applies OneNote's native "Normal" style. I was thinking that, if native OneNote has a hotkey dedicated to "Normal" style, then OneMore could add one fully dedicated to OneNote's "Code" style. (doesn't even need to be a OneMore style) But I think I understand what you're saying: styles must always be looked up by index, cuz OneNote doesn't expose an API akin to GetWellKnownStyle(Styles.NORMAL) or anything like that.

You have the ability to reorder your custom styles

Thanks, to be honest, I hadn't found the button for reodering. :( My mistake.

I had been worried that reordering would mess up ToCs, and didn't fully understand the warning shown here: image

But seems like moving "Code" into position 7 doesn't affect ToCs! And "Quick Style palette" also solves my problem, so it's a non-issue.