gaelj / BlazorCodeMirror6

Blazor wrapper for CodeMirror 6
MIT License
20 stars 2 forks source link

Support text/plain mode? #58

Closed Gaz83 closed 10 months ago

Gaz83 commented 10 months ago

Any chance to support text/plain mode?

gaelj commented 10 months ago

In the demo you can view the raw test by unchecking this box image

This sets the component's AutoFormatMarkdown parameter accordingly.

If that's not what you have in mind, could you elaborate ?

gaelj commented 10 months ago

OK I think I understood : you want plain text as a language option ?

Gaz83 commented 10 months ago

Yeah if possible. In CodeMirror5 you can set the mode to null or plain/text. Not sure if CodeMirror6 has similar.

Looking at what you wrote I am now thinking set language to Markdown, switch off the autoformat and disable highlighting. This should do the same thing? If so, wonder if you can change so that you can select plain text and it sets those options for you.

gaelj commented 10 months ago

Implemented and deployed ; can you check and either close this issue or comment it ?

Gaz83 commented 10 months ago

Got the following exception

index-C6LAOLAl.js:77011 Error in initializing CodeMirror TypeError: Cannot read properties of null (reading 'extension') at inner (index-C6LAOLAl.js:2038:31) at inner (index-C6LAOLAl.js:2022:13) at inner (index-C6LAOLAl.js:2015:17) at flatten (index-C6LAOLAl.js:2044:5) at Configuration.resolve (index-C6LAOLAl.js:1952:25) at EditorState.create (index-C6LAOLAl.js:2783:43) at Module.initCodeMirror (index-C6LAOLAl.js:76986:45)

That was from console in Edge

In my blazor app I get this

An error occurred while loading the editor: Message: Cannot read properties of undefined (reading 'state') TypeError: Cannot read properties of undefined (reading 'state') at Module.setDoc (https://localhost:7214/_content/CodeMirror6/index-C6LAOLAl.js:77132:46) at https://localhost:7214/_framework/blazor.web.js:1:3244 at new Promise (<anonymous>) at y.beginInvokeJSFromDotNet (https://localhost:7214/_framework/blazor.web.js:1:3201) at fn._invokeClientMethod (https://localhost:7214/_framework/blazor.web.js:1:62869) at fn._processIncomingData (https://localhost:7214/_framework/blazor.web.js:1:60344) at connection.onreceive (https://localhost:7214/_framework/blazor.web.js:1:53985) at i.onmessage (https://localhost:7214/_framework/blazor.web.js:1:82130)

gaelj commented 10 months ago

Can you make sure the browser cache is cleaned ?

Gaz83 commented 10 months ago

Just tried again with cache cleared, still the same.

gaelj commented 10 months ago

Are you running the example locally or are you on the github actions demo ?

If locally, try running dotnet clean and dotnet build in the CodeMirror6 project .

Gaz83 commented 10 months ago

I am running it all locally. Cloned the git, referenced the project and using in my own projects. I am now going to use your examples project locally. Will get back in a few moments

Gaz83 commented 10 months ago

Ok I can confirm your Examples.BlazorServer projects works fine locally. Let me investigate my projects to see what is happening.

In the mean time, would it be possible to make the nuget packaging? or put it near the top of the list? I think you have good project here and it would be worth doing.

Gaz83 commented 10 months ago

Ok I have managed to replicate the issue locally in your examples. Go into Example.razor and change the Language from the default CodeMirrorLanguage.Markdown to CodeMirrorLanguage.PlainText so that it starts up with that language set. Now when I run it I get the same errors. If I leave it as Markdown and change it to PlainText through the browser then it works fine.

And just as a test, I tried CSharp as the default and that works, so seems related to PlainText at startup

Gaz83 commented 10 months ago

I also just done this in my own project to confirm it's the initial setting. This works.

protected override Task OnAfterRenderAsync(bool firstRender)
  {
      if (_codeMirror is not null)
          if (_codeMirror.Language != CodeMirrorLanguage.PlainText)
                  _codeMirror.Language = CodeMirrorLanguage.PlainText;

      return base.OnAfterRenderAsync(firstRender);
 }
gaelj commented 10 months ago

The bug is now fixed. Thanks for pointing it out !

Gaz83 commented 10 months ago

I can confirm the issue is resolved. Tested and now using the nuget package :-D