sparksuite / simplemde-markdown-editor

A simple, beautiful, and embeddable JavaScript Markdown editor. Delightful editing for beginners and experts alike. Features built-in autosaving and spell checking.
https://simplemde.com
MIT License
9.87k stars 1.13k forks source link

Toolbar overhaul #252

Open Eraldo opened 8 years ago

Eraldo commented 8 years ago

If I overwrite the toolbar as demonstrated in the example code:

    toolbar: [{
            name: "bold",
            action: SimpleMDE.toggleBold,
            className: "fa fa-bold",
            title: "Bold",
        },
        {
            name: "custom",
            action: customFunction(editor){
                // Add your own code
            },
            className: "fa fa-star",
            title: "Custom Button",
        },
        "|", // Separator
        ...
    ],

Then the tooltip does not show shortcuts anymore. (none of the buttons do anymore)

As far as I can tell this is because the action e.g.: SimpleMDE.toggleBold will not be found in getBindingName which looks for that function in bindings[key] and finds toggleBold instead. (bindings[key] === f)

Is there a way to add another button without having to recreate all the others? Or how else could I go about that? Ideas? Thanks. ;)

trwired commented 8 years ago

As the guy who retrofitted user customizable shortcuts into the editor, I admit that the bindings look-up table is a little bit of a hack introduced to avoid backwards incompatible changes to how toolbar code works. A fix to both this and #248 should be relatively easy, but I expect backwards incompatible changes to be unavoidable at this point, so I'd like to hear the original author's thoughts on the matter. Especially given that version 2.0 of SimpleMDE is planned at some point and bumping up major revision is IMHO the best time to introduce stuff that breaks the API.

Eraldo commented 8 years ago

Yeah.. that sounds good. :) I guess having the ability to just add or replace parts of the toolbar vs overwrite it entirely would also be great. I hope for progress either way. +1

WesCossick commented 8 years ago

I think we need a solution that accomplishes the following:

  1. Add custom toolbar buttons without rewriting the whole toolbar
  2. Add shortcuts to the tooltips of toolbar buttons even if they're from the toolbar option
  3. Allow shortcuts to be assigned to custom buttons (#248)
  4. Intuitive, clean code
  5. 100% backwards compatibility

Because I advocate using the latest tag when including SimpleMDE from a CDN, I think it's very important to maintain backwards compatibility, even with major releases. Plus this is an important goal if we want users to use the latest code. By ensuring that new updates don't break old code, it's far more likely that users will be using the latest code without fear of breaking their software.

trwired commented 8 years ago

Yes, well, that's not helpful. :) What if the point number 5 prevents a problem from being solved? Asking for future reference, though, because I think I have an idea how to make both issues go away, while keeping backwards compatibility. Will give it a try over the weekend.

WesCossick commented 8 years ago

I'd argue that most, if not all, changes can be accomplished in a fashion that retains backwards compatibility if we're clever enough.

If a particular issue does arise that would inhibit backwards compatibility, then the benefits would need to be weighed with the consequences. But I'd rather cross that bridge when we get there since it's rather situation-dependent.

Eraldo commented 8 years ago

@trwired Awesome.. looking forward to it. :D @WesCossick Sounds like the optimal solution. I wish you luck. Thank's for working on it - I appreciate it a lot.

iorilu commented 7 years ago

seems still can't add shortcut key for custom function? I have following code to handle image upload , want to add a shortkey for this { name: "uploadImage", action: function customFunction(editor){ $("#fileLoader").trigger("click"); }, className: "fa fa-picture-o", title: "Add Image", } ], shortcuts: { "uploadImage": "Cmd-Alt-U" }

jhpratt commented 7 years ago

Seconded. @WesCossick any ideas?

Eraldo commented 6 years ago

Any updates yet? :) Or examples?

Eraldo commented 6 years ago

I guess just being able to add (extend) custom bindings would already fix this. Shall I create a PR?

CWharton commented 6 years ago

@Eraldo, this project is dead and there has been not movement on it. I have talked with Wes and he has no interest in moving forward or passing over the project. Some of us have moved over to https://github.com/Inscryb/inscryb-markdown-editor and I would be happy to accept your PR or any other contributions.