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

Using Ctrl-enter to render Markdown cells #120

Closed
SamLau95 opened this issue Oct 4, 2023 · 3 comments · Fixed by #128
Closed

Using Ctrl-enter to render Markdown cells #120

SamLau95 opened this issue Oct 4, 2023 · 3 comments · Fixed by #128
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@SamLau95
Copy link

SamLau95 commented Oct 4, 2023

Thanks for working on jupyterlab-vim! I'm using it to do live-coding for my lectures at UC San Diego.

My muscle memory for using ctrl-enter to render Markdown cells is quite strong. Is there a way to re-enable that command when the extension is active?

When I'm editing a Markdown cell (in vim normal or insert mode), I'd like the ability to press ctrl-enter to render the cell and return to Jupyter vim mode.

@SamLau95 SamLau95 added the enhancement New feature or request label Oct 4, 2023
@firai
Copy link
Collaborator

firai commented Oct 4, 2023

It's possible to add the ability to render Markdown on Ctrl+Enter when the plugin is active, but it's currently not possible to stay in vim (Normal) mode when that happens. This is because rendering Markdown essentially turns the cell into output, and the plugin is currently not able to navigate output via vim (see #53 and #56). You can see this in action if the first cell is a Markdown cell and if you press k there (#52). Therefore, if we implement this, Ctrl+Enter in a Markdown cell would render the Markdown and then have to eject the user to Jupyter Command mode.

By the way, you may already be aware of this, but navigating up or down away from a Markdown cell in this plugin auto-renders the cell.

@firai firai added the good first issue Good for newcomers label Oct 4, 2023
@SamLau95
Copy link
Author

SamLau95 commented Oct 4, 2023

@firai Thanks for the context. I mixed up the terminology in my original question – I'd like it if Ctrl+Enter in a Markdown cell would render Markdown and eject the user to Jupyter Command mode, as you said. From what I know, this is the default behavior of Ctrl+Enter in Jupyter Lab and Notebook.

@firai
Copy link
Collaborator

firai commented Oct 8, 2023

Contributions would be welcome. Looking at the key bindings, Ctrl+Enter is redirected to the vim:run-cell-and-edit command, which is defined here:

commands.addCommand('vim:run-cell-and-edit', {
label: 'Run Cell and Edit Cell',
execute: args => {
const current = getCurrent(args);
if (current) {
const { context, content } = current;
NotebookActions.run(content, context.sessionContext);
current.content.mode = 'edit';
}
},
isEnabled
}),

I think what's needed here is to fire the notebook:run-cell command, which is JL's default command for this binding, if the cell is a Markdown cell. You should be able to test if the current cell is a Markdown cell by following this pattern:

if (
content.activeCell !== null &&
content.activeCell.model.type === 'markdown'
) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants