codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.86k stars 373 forks source link

Script editor shows "NL" character instead of rendering actual new line (v-6) #1429

Closed R-Sg closed 2 months ago

R-Sg commented 2 months ago

Describe the issue

I am using codemirror version6 , i tried to use lineSeparator based on OS but not succes, it just Shows "NL" not rendering actual new line.

Script editor shows "NL" character instead of rendering actual new line (v-6)

OS-Mac arm Chrome LNScreenshot

Browser and platform

No response

Reproduction link

No response

marijnh commented 2 months ago

What value did you set lineSeparator to? If you set it to, for example, \r\n, and then load a document that contains just \n characters between lines, your editor will look like the screenshot, because in an editor configured that way, \n does not start a new line.

R-Sg commented 2 months ago

I have added the lineSeparatorin default extension like this:-

const defaultExtensions = [
  EditorState.lineSeparator.of('\r\n'),
  ]

And then add that extensions like this under useEffect:-

const state = EditorState.create({
        extensions: [
          ...defaultExtensions ,
          editableConfig.current.of([
            EditorView.editable.of(!disabled),
            EditorState.readOnly.of(readonly),
          ].concat(keepHistory ? [history()] : [])),
          ]

If I am missing something then could you please provide me an sample example code of few lines. Otherwise please tell me what i am doing wrong on my above code. Thanks for quick response, As its bit blocker for me.

marijnh commented 2 months ago

Then this is behaving as expected. I explained what is going on in my first comment. I cannot give you sample code without knowing what you are trying to do.

R-Sg commented 2 months ago

I just want to have lineSeparator which should be OS based if any windows user using my application then it should set default lineSeparator according to windows OS, if mac user then set default lineSeparator to Mac Os same for linux.

That's only my requirement.

R-Sg commented 2 months ago

My main concern is this, hope now you clear :- As I experienced that if I copy the Query SQL text to the ClipBoard, that NewLine sign is only LF. On Windows OS the NewLine is CRLF. Some tools can handle the orphan CR or LF, like Notepad++. But if I paste the SQL text into DevExpress controls like cxMemo (= dialogs written in Delphi), the whole SQL is only one line!

That's why i try to use lineSeparator based on OS.

Please let me know if still not clear THanks

marijnh commented 2 months ago

You don't want to use lineSeparator for that, unless you can guarantee that the input is also stictly using that line separator.

If you just want to process code copied from the editor, I've added clipboardOutputFilter in @codemirror/view 6.33.0, which might help.

R-Sg commented 2 months ago

I already used that clipboardOUtputFilter it works but, i want a feature that if windows/mac/linux user using my application then codemirror editor should autodetect the OS and change the EOL(end of line) accoedingly. Is it possible with codemirror methods? Thanks in advance