uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.65k stars 132 forks source link

How to use with line-break? #330

Closed alexandrsek closed 2 years ago

alexandrsek commented 2 years ago

Hello everyone! How to apply the line-break?

jaywcjlove commented 2 years ago

I do not understand what you mean. @alexandrsek

yannicka commented 2 years ago

I think I am looking for a solution to the same problem.

The EditorView object allow a lineWrapping argument: https://codemirror.net/docs/ref/#view.EditorView.lineWrapping

How is it possible to set this parameter (and others similar options) to true?

jaywcjlove commented 2 years ago

@yannicka See example: https://codemirror.net/examples/config/#dynamic-configuration

jaywcjlove commented 2 years ago
import React from "react";
import { EditorView } from "codemirror";
import CodeMirror from "@uiw/react-codemirror";
import { javascript } from "@codemirror/lang-javascript";

export default function App() {
  return (
    <div>
      <CodeMirror
        value="console.log('hello world!');console.log('hello world!');console.log('hello world!');console.log('hello world!');"
        height="200px"
        theme="dark"
        extensions={[EditorView.lineWrapping, javascript({ jsx: true })]}
        onChange={(value, viewUpdate) => {
          console.log("value:", value);
        }}
      />
    </div>
  );
}

https://codesandbox.io/embed/react-codemirror-example-codemirror-6-forked-7bgggy?fontsize=14&hidenavigation=1&theme=dark

@yannicka @alexandrsek

https://discuss.codemirror.net/t/dynamically-change-linewrapping/3027/3

alexandrsek commented 2 years ago

Thanks! Thats exactly what I was looking for! Good luck!