Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to wrap text in CodeMirrorMerge? #514

Closed
kimfucious opened this issue Jun 2, 2023 · 2 comments
Closed

How to wrap text in CodeMirrorMerge? #514

kimfucious opened this issue Jun 2, 2023 · 2 comments
Labels

Comments

@kimfucious
Copy link

I'm trying to compare two markdown files, using CodeMirrorMerge.

Using the documentation here, I've managed to produce what's shown in this screenshot:
image
In this example the text is a single "paragraph" of around 60 words. In practice, there will be many more paragraphs with more or less words.

The "original" text is on the left, and the "modified" is on the right. I want to potentially merge changes that are in modified to the original.

Question: Is there any way to wrap the text? It's near impossible to compare long lines (i.e. paragraphs) on a single line?

With CodeMirror from @uiw/react-codemirror, I can wrap text with the following code:

extensions={[
    vim({ status: true }),
    markdown(),
    EditorView.lineWrapping, // <= right here
    EditorView.contentAttributes.of({ spellcheck: "true" }),
]}

The wrapping looks like this:
image

I can't see a way to do this with CodeMirrorMerge.

@jaywcjlove
Copy link
Member

@kimfucious https://codesandbox.io/embed/nostalgic-rgb-gj6kfz?fontsize=14&hidenavigation=1&theme=dark

Upgrade v4.20.3

import React, { useState } from "react";
import CodeMirrorMerge from "react-codemirror-merge";
import { EditorView } from "@codemirror/view";

const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
let doc = `one
two
threethreethreethreethreethreethreethreethreethreethreethree
four
five`;

export default function App() {
  const [value, setValue] = useState("");
  const [valueModified, setValueModified] = useState("");
  return (
    <div>
      <CodeMirrorMerge orientation="a-b">
        <Original
          extensions={[EditorView.lineWrapping]}
          onChange={(value) => {
            setValue(value);
          }}
          value={doc}
        />
        <Modified
          extensions={[EditorView.lineWrapping]}
          onChange={(value) => {
            setValueModified(value);
          }}
          value={doc.replace(/t/g, "T") + "Six"}
        />
      </CodeMirrorMerge>
      <div style={{ display: "flex" }}>
        <pre style={{ flex: 1 }}>{value} </pre>
        <pre style={{ backgroundColor: "#fff", flex: 1 }}>{valueModified} </pre>
      </div>
    </div>
  );
}

@jaywcjlove jaywcjlove added the demo label Jun 2, 2023
@kimfucious
Copy link
Author

Hi @jaywcjlove.

That's perfect! Thanks much for the help.

I didn't realize that you could add extensions to Original and Modified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants