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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃摑 Add Ctr+M shortcut for toggling Markdown mode #390

Merged
merged 1 commit into from
Sep 9, 2020
Merged

馃摑 Add Ctr+M shortcut for toggling Markdown mode #390

merged 1 commit into from
Sep 9, 2020

Conversation

ekzhang
Copy link
Contributor

@ekzhang ekzhang commented Sep 8, 2020

Hey there, thanks for making this awesome project! This notebook server has been really useful to me.

One thing I noticed is that it gets repetitive to keep typing md" every time I want to start a Markdown block. This PR aims to try to make this easier by adding a keyboard shortcut to do the same. Right now I picked Ctrl+M/Cmd+M, but feel free to change this if you prefer.

Hope this aligns with the direction you're taking the project!

Changes

  • Added a shortcut (Ctrl+M/Cmd+M) to change a code cell to Markdown, or a Markdown cell to code
  • Robust to leading/trailing whitespace
  • Retains your cursor position in the cell

GIF Demo

@fonsp
Copy link
Owner

fonsp commented Sep 8, 2020

Woa it even keeps the cursor position! Fantastic!

@fonsp
Copy link
Owner

fonsp commented Sep 8, 2020

About the keyboard shortcut - VS Code has a semi-undocumented notebook mode, and I want Pluto to use the same default keyboard shortcuts wherever possible. Do they have one? Otherwise Ctrl/Cmd+M is nice!

@ekzhang
Copy link
Contributor Author

ekzhang commented Sep 8, 2020

Thanks! The keyboard shortcut in VS Code is just "M" when you're selecting the cell in command mode.

@fonsp fonsp merged commit 8fb14e8 into fonsp:master Sep 9, 2020
@ekzhang ekzhang deleted the feature/markdown-shortcut branch September 9, 2020 16:55
@fonsp
Copy link
Owner

fonsp commented Sep 9, 2020

Awesome, thanks Eric! It will be released in today's update :)

What do you want to work on next? I'm always happy to have a video call if you want to discuss open issues/different approaches/future ideas/the weather: fonsvdplas@gmail.com

@ekzhang
Copy link
Contributor Author

ekzhang commented Sep 9, 2020

Amazing! In terms of low-hanging fruit, I wish there was a way to copy/paste cells, and I also wish there was a simpler way to run Pluto from the terminal, like a pluto executable in the path. Maybe this is an unconventional way to do things though, not sure if I can say much on that since I'm inexperienced in Julia.

Anyway, great stuff! It was super easy to set up the dev environment, will definitely send another PR if I find something in the future... (using Pluto for a course this semester because I hate Mathematica 馃槄).

@fonsp
Copy link
Owner

fonsp commented Sep 9, 2020

Good to hear! Look forward to hear more from you!

The Pluto CLI exists 馃槉 - https://github.com/fonsp/PlutoUtils.jl

@fonsp
Copy link
Owner

fonsp commented Sep 9, 2020

Copying + pasting cells would be great! I hope you discovered the cell selection feature? I assume you did, coming from Mathematica :)

It needs to work among different notebooks! And if possible, different notebooks from different sessions (e.g. one on binder, one running locally).

Maybe you could think about the contents of the clipboard? Some options:

  1. It doesn't matter, you put the data in localStorage. But then it only works within the same session
  2. The copy data is exactly like it is in the file (i.e. # |==\ncode\n\n ish). And when you paste onto the page it recognizes that format (and generates new cell IDs to avoid duplicates). This is cool, because people often post notebooks in that format on github.
  3. The copy data also contains formatted output? Like what happens right now if you text-select and copy+paste to Google Docs.

Another thing: for this you would want to place a superbig text cursor after a cell or between two cells, before you hit Ctrl+V. I think this could be really cool, if you also allow text input to create a new cell.

@fonsp
Copy link
Owner

fonsp commented Sep 9, 2020

Let me make that a new issue

@fonsp
Copy link
Owner

fonsp commented Sep 9, 2020

#399

@lyon-fnal
Copy link

lyon-fnal commented Sep 10, 2020

Thanks for adding this nice feature. I'll note that on a Mac, Cmd+M by default minimizes the current window. To get your feature to work, I had to reassign the Minimize action to a different key (see https://apple.stackexchange.com/questions/115562/how-do-i-disable-the-minimize-command-m-shortcut-in-mavericks). Reassigning is fine with me, as I sometimes hit Cmd+M by mistake ... the minimizing window can be somewhat jarring. Now that's no longer a problem and I can use your feature!

@fonsp
Copy link
Owner

fonsp commented Sep 10, 2020

@lyon-fnal As a mac user, can you suggest a solution?

@lyon-fnal
Copy link

Yes - I did in my previous post - sorry that wasn't clear. One can reassign the Minimize function to a different key (e.g. not Cmd+M). See https://apple.stackexchange.com/questions/115562/how-do-i-disable-the-minimize-command-m-shortcut-in-mavericks (works for Catalina) for instructions.

@ekzhang
Copy link
Contributor Author

ekzhang commented Sep 11, 2020

@lyon-fnal I also use a Macbook Pro and haven't experienced this being an issue when I was developing. What browser are you using?

Cmd+M does indeed map to "minimize" for me, but it's not doing that when my cursor is in the CodeMirror editor.

@fonsp
Copy link
Owner

fonsp commented Sep 18, 2020

Ctrl+M on an empty cell places the cursor at the end of the cell, instead of inside the markdown literal. Could you have a look?

image

@lyon-fnal
Copy link

It does that for me too on Safari.

@ekzhang
Copy link
Contributor Author

ekzhang commented Sep 18, 2020

Good point @fonsp. I had some spare time today and was planning to work on #399 , so this fits well into my schedule - will look at it.

@ekzhang
Copy link
Contributor Author

ekzhang commented Sep 19, 2020

Okay, I don't have a good fix for this unfortunately due to some limitations of CodeMirror's API. The best solution I could find is to add a hack when getCursor() returns the last index of the document, to manually call setCursor() and move it back to before the inserted """. This doesn't work with multiple cursors, selection regions, or multiple selection regions though.

I'll send in a PR anyway, since it seems like Ctrl-M on an empty cell is a fairly common case...

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.

None yet

3 participants