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

No way to get to next line when doing ```[language] shortcut for codeblocks #397

Open
2 tasks done
RobertBrunhage opened this issue Mar 23, 2024 · 1 comment
Open
2 tasks done
Labels
bug Something isn't working

Comments

@RobertBrunhage
Copy link

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have read the documentation and cannot find an answer.

Describe the bug
Testing in https://mdxeditor.dev/editor/demo go to the bottom of the page and write ```js followed by space. Now try to get to the next line to write in. (I would expect this to work with shift+enter or just clicking below it).

When using the code block button in the navbar it will add a newline below the codeblock to continue writing in.

Reproduction
Testing in https://mdxeditor.dev/editor/demo go to the bottom of the page and write ```js followed by space

To Reproduce
Steps to reproduce the behavior:

  1. https://mdxeditor.dev/editor/demo
  2. Click on the last editable part of the markdown editor
  3. write ```js followed by enter
  4. try to write after the codeblock

Expected behavior
Should be able to continue after writing a codeblock

Desktop (please complete the following information):

  • OS: MacOs
  • Chrome
@RobertBrunhage RobertBrunhage added the bug Something isn't working label Mar 23, 2024
@petyosi
Copy link
Contributor

petyosi commented Mar 24, 2024

That's a legit problem. I have a code that might need some tweaking, as I believe that down arrow should be able to exit the code block, even if it means creating a new paragraph. Right now, you have to press twice if the block is empty.

@RobertBrunhage if you're interested, I'm happy to accept an improvement PR - this is the code block that does some special handling of the codemirror blocks.

const onKeyDownHandler = React.useCallback(
(e: KeyboardEvent) => {
if (e.key === 'ArrowDown') {
const state = codeMirrorRef?.current?.getCodemirror()?.state
if (state) {
const docLength = state.doc.length
const selectionEnd = state.selection.ranges[0].to
if (docLength === selectionEnd) {
// escaping once
if (!atBottom.current) {
atBottom.current = true
} else {
// escaping twice
activeEditor?.update(() => {
const node = $getNodeByKey(nodeKey)!
const nextSibling = node.getNextSibling()
if (nextSibling) {
codeMirrorRef?.current?.getCodemirror()?.contentDOM.blur()
node.selectNext()
} else {
node.insertAfter($createParagraphNode())
}
})
atBottom.current = false
}
}
}
} else if (e.key === 'ArrowUp') {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants