Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] Codeblock + Codemirror plugins - Delete icon not disabled when edit mode is disabled #602

Closed
fedehann opened this issue Oct 5, 2024 · 2 comments
Labels
bug Something isn't working released

Comments

@fedehann
Copy link

fedehann commented Oct 5, 2024

Despite the editor "edit" mode being disabled, the "delete" button of the code block remains active.

image

@aaronjamesmarshallau
Copy link

I also have this issue. Using:

const plugins = [
  // Other plugins
  codeBlockPlugin(),
  codeMirrorPlugin({
    codeBlockLanguages: {
      // ...
    },
    codeMirrorExtensions: [
      EditorState.readOnly.of(true), // Code Mirror readonly configured
      EditorView.editable.of(false)
    ]
  }),
];

// and...

export const Example: FunctionComponent = () => {
  // imagine cool blog content with a triple backtick code block
  const blogContent = ''; 
  return (
    <MDXEditor
      markdown={blogContent}
      readOnly <!-- Read Only editor -->
      plugins={plugins} />
  )
};

I also see this issue. Looking at the code, I assume these are the relevant lines

<div className={styles.codeMirrorToolbar}>
<Select
value={language}
onChange={(language) => {
parentEditor.update(() => {
lexicalNode.setLanguage(language === EMPTY_VALUE ? '' : language)
setTimeout(() => {
parentEditor.update(() => {
lexicalNode.getLatest().select()
})
})
})
}}
triggerTitle={t('codeBlock.selectLanguage', 'Select code block language')}
placeholder={t('codeBlock.inlineLanguage', 'Language')}
items={Object.entries(codeBlockLanguages).map(([value, label]) => ({ value: value ? value : EMPTY_VALUE, label }))}
/>
<button
className={styles.iconButton}
type="button"
title={t('codeblock.delete', 'Delete code block')}
onClick={(e) => {
e.preventDefault()
parentEditor.update(() => {
lexicalNode.remove()
})
}}
>
{iconComponentFor('delete_small')}
</button>
</div>
?

Looks like the readOnly flag is passed in, but not applied to that select which allows controlling language and deleting the code block.

Copy link

🎉 This issue has been resolved in version 3.22.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants