scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.66k stars 193 forks source link

Is there a way to have multiple editors that we can switch through with tabs? #190

Closed mehmetron closed 4 years ago

mehmetron commented 4 years ago

I'm trying to implement a sort of file system where there are multiple editors with separate content that the user can switch through.

Can I implement something like this using react-codemirror2?

fongandrew commented 4 years ago

This is probably better asked on Stack Overflow rather than raised as an issue on the project, but yes, probably.

Each editor is its own React component and you have multiple instances of CodeMirror itself.

mehmetron commented 4 years ago

I ask because in the Codemirror docs you can create multiple editor instances

Each editor is associated with an instance of CodeMirror.Doc, its document. A document represents the editor content, plus a selection, an undo history, and a mode. A document can only be associated with a single editor at a time. You can create new documents by calling the CodeMirror.Doc(text: string, mode: Object, firstLineNumber: ?number, lineSeparator: ?string) constructor. The last three arguments are optional and can be used to set a mode for the document, make it start at a line number other than 0, and set a specific line separator respectively.

And I was wondering if react-codemirror2 supports this functionality

fongandrew commented 4 years ago

Yes, it does. You can see it working here. https://codesandbox.io/s/intelligent-star-i7r73?file=/src/App.js