Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Switch Back to Plaintext Language Mode #4

@jsilfver

Description

@jsilfver

The default value for the API parameter [language] is an empty string (''), which sets the editor to plaintext mode. When the [language] parameter is updated, the editor switches to the corresponding language mode. However, it appears that once a language is selected, it is not possible to revert the editor back to plaintext mode by setting [language] to an empty string ('').

Allowing users to switch back to plaintext mode is useful, especially when they test a language that turns out to be unsuitable for the editor’s content.

Ref forum: https://discuss.codemirror.net/t/switching-between-plaintext-and-a-language-throws-error/3104

Ref code-editor:

setLanguage(lang: string) {
    if (!lang) {
      return;
    }
    if (this.languages.length === 0) {
      if (this.view) {
        console.error('No supported languages. Please set the `languages` prop at first.');
      }
      return;
    }
    const langDesc = this._findLanguage(lang);
    langDesc?.load().then(lang => {
      this._dispatchEffects(this._languageConf.reconfigure([lang]));
    });
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions