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

Desktop: Support executing codemirror commands when using execCommand #5012

Merged
merged 2 commits into from
Jun 7, 2021

Conversation

CalebJohn
Copy link
Collaborator

I was helping @tessus with something and it came up that this could be useful. And actually with the wording I think the previous behaviour was a bit confusing/wrong.

@laurent22
Copy link
Owner

Could you give an example of what was not possible before, and what's possible now? How will the editor commands be invoked?

@CalebJohn
Copy link
Collaborator Author

The exact case that inspired this change was adding the joinLines command to the context menu.

await joplin.commands.execute('editor.execCommand', {
    name: 'joinLines',
});

CodeMirror has a selection of commands that are typically bound to keys, but can also be called with codemirror.execCommand(name). These commands were previously inaccessible without using a contentScript. There is no change to executing codemirror functions, this just adds the ability to also execute commands.

A benefit of this is that will give plugin developers more power to control the codemirror editor without having to write a contentScript.

@laurent22
Copy link
Owner

Sounds good, and that would indeed be useful. I think it would be good to add some plugin documentation about this as it's a bit hard to discover. Maybe you could add a new section on top of JoplinCommand.ts (below the "Executing Joplin's internal commands" section) with an example? Also is there a list of the Code Mirror commands we support that we can point to?

@CalebJohn
Copy link
Collaborator Author

That's a good suggestion @laurent22 adding documentation was long overdue. It's done now, I didn't build the docs locally but they should be good to go.

@laurent22
Copy link
Owner

Looks good, thanks for the update and doc!

@laurent22 laurent22 merged commit a7e6795 into laurent22:dev Jun 7, 2021
@CalebJohn CalebJohn deleted the execommands branch June 7, 2021 14:35
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

Successfully merging this pull request may close these issues.

2 participants