RickStrahl / MarkdownMonster

An extensible Markdown Editor, Viewer and Weblog Publisher for Windows
https://markdownmonster.west-wind.com
Other
1.59k stars 235 forks source link

Is there a keyboard shortcut and/or a KeyBinding Id that I could use to perform a "Format Table"? #1079

Closed bcmadsen closed 9 months ago

bcmadsen commented 9 months ago

I've seen MarkdownMonster-KeyBindings.json. I've seen the documentation. If what I'm looking for exists, I'm looking for it in the wrong place. I think it might not.

I find myself formatting tables a lot, and I would love for that to have a keyboard shortcut. I can see how I might set up a key binding for this, but I need an "Id" value, and I'm not clear on what that would be. Is there one? Where is it documented, if so?

To be clear, the table formatting I'm talking about is the one in the popup menu when you right-click on a table in the editor. The first items on that menu are Edit Table and Format Table. I do the Format Table so often that I'd love to tie it to a keyboard shortcut. But ... is that something I can do?

If that's not something we can set up with a key binding, can we at least set up an accelerator on that menu for those first two items? That way, I could press Shift-F10 to bring up the menu, after which a number of the menu items have accelerators (e.g, the "C" which is underlined in "Close Document" or the "T" in "Open Terminal") -- but none of the letters in "Edit Table" and "Format Table" are underlined to allow this. If one of them was, I could solve this by pressing Shift-F10 and then the underlined letter in "Format Table", if only there was one.

It's a little thing, I know, but for me, this would be so much more convenient than the current path to get there.

RickStrahl commented 9 months ago

No there's not at the moment. Only on the context menu.

There's no really a menu that works for this because the option is only conditionally available when you are already sitting on a table and it's very expensive to check whether you are (a bunch of parsing has to happen).

I think what I will do though is an entry in the Control Palette so you'll be able to use Ctrl-Shift-P - Format Table to get to it. Currently there's only Insert Table on the Command Palette and it probably needs Edit Table and Format Table to be added.

bcmadsen commented 9 months ago

Finding an entry in the ctrl-shift-p list seems like more keystrokes than the options I already have now. Are we sure that adding accelerators (that is, underlining one of the letters) to the Shift-F10 popup menu isn't a possibility? That really seems like the quickest way to get to where I want to go, to be honest. Shift-F10 then F (or whatever other letter you think makes the most sense), would work really well, I'd say.

image

RickStrahl commented 9 months ago

Command Palette is pretty quick once you start using it more often. These days I use only core shortcuts (ctrl-b/i etc.) for everything else that's more complicated I go straight to the Command Palette. Between the Hot Key a few letters for hotkeying and downarrow to nav, it's very quick. Certainly quicker than trying to remember or work with complex key chords (which unfortunately don't work very well due to WebView keyboard handling issues).

Here's what the Format Table functionality looks like using the Command Palette:

CommandPaletteFormatTable

This update's in 3.1.17.1+

RickStrahl commented 9 months ago

I've just added improved support for custom keybindings that can be mapped against commands that aren't explicitly mapped into the keybindings manager. This basically allows mapping any commands that exist.

For example, in 3.1.17.3 and later you can add commands like this in MarkdownMonster-KeyBindings.json:

  {
    "Id": "FormatTable",
    "Key": "Ctrl-Shift-Q",
    "CommandName": "FormatTable",
    "CommandParameter": null
  },
  {
    "Id": "EditTable",
    "Key": "Ctrl-Shift-W",
    "CommandName": "EditTable",
    "CommandParameter": null
  }

This will allow you to map a direct keyboard shortcut and it works for the two commands above.

The trick is finding key combinations that are available and that you can actually remember (I used arbitrary keys here in order to avoid interference with existing commands).

bcmadsen commented 9 months ago

Thank you so much!

I ended up using keys F9 and F10, because I don't see those used anywhere else, and it's working splendidly.

(My only bit of possibly negative feedback: I noticed that editing the MarkdownMonster-KeyBindings.json file inside MM doesn't seem to stick at first, which came as a surprise. At first, I made the changes you discussed above but with F9 and F10, then thought I had closed and saved them, and was surprised to find that the KeyBindings file reverts to what it was before I made changes to it. I found myself needing to open that JSON file in another editor, other than MM, and then I needed to continually save it in its changed form while I opened a Markdown text file in MM and closed both the document and MM again, in order to get the change to stick. Otherwise that keybindings file would revert against my wishes. With this subterfuge, I have succeeded in getting the file to stay changed, and now I love being able to format my tables this way. Thank you again!)

RickStrahl commented 9 months ago

Yeah I noticed that as well, and I have it on my list to try and pin that down. In theory, keybindings should load when the application starts and immediately save to root out any non-matching or invalid entries. So in that case editing and saving should just save and then load on the next restart.

Somehow though it appears that the keybindings are saving at another time...

RickStrahl commented 9 months ago

Take a look a 3.2.1.

You should now be able to make a key binding change and see that change immediately applied - assuming you use a key that's not already in use.

Save now:

bcmadsen commented 9 months ago

Thank you for all of that. I have 3.2.1 now, and I am happy to confirm that it resolves the issue I was having with the earlier build.

Thank you again.