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 use codemirrormerge on json data?. #559

Open
divyamohanraju07 opened this issue Aug 30, 2023 · 2 comments
Open

How to use codemirrormerge on json data?. #559

divyamohanraju07 opened this issue Aug 30, 2023 · 2 comments

Comments

@divyamohanraju07
Copy link

divyamohanraju07 commented Aug 30, 2023

I am working in a project requirement where i need to compare the config files from different deployment environment. I was searching for a difference editor and finalised with codemirror. My data to handle is in json format. When i load it in codemirror merge, my screen is blank with no error indication. I do not know where should i indicate the lang support. Any help here would be gr8.

import React, {useState} from 'react';
import './mergeView.css';
import CodeMirrorMerge from 'react-codemirror-merge';
import { EditorView } from 'codemirror';
import { EditorState } from '@codemirror/state';
import { githubLight, githubDark } from '@uiw/codemirror-theme-github';
import { StreamLanguage } from '@codemirror/language';
import {javascript} from '@codemirror/lang-javascript';


const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
const original_doc = `{one: to, three: four}`;
const modified_doc = `{One: Two, Three: Four}`;

export const Example = () => {
  const [theme, setTheme] = useState('light');
  return (
    <>
    <CodeMirrorMerge theme={theme === 'light' ? githubLight : githubDark} orientation="b-a">
      <Original value={original_doc} />
      <Modified
        value={modified_doc}
        extensions={[EditorView.editable.of(false), EditorState.readOnly.of(true)]}
      />
    </CodeMirrorMerge>
    <button className="theme-btn" onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}> Change Theme </button>
    </>
  );
};
@jaywcjlove
Copy link
Member

import CodeMirrorMerge from "react-codemirror-merge";
import "./styles.css";

import { EditorView } from "@codemirror/view";
import { EditorState } from "@codemirror/state";
import { githubLight } from "@uiw/codemirror-theme-github";
const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
const original_doc = `{\n  one: to, \n  three: four\n}`;
const modified_doc = `{\n  One: Two, \n  Three: Four\n}`;

export default function App() {
  return (
    <div className="App">
      <CodeMirrorMerge theme={githubLight} orientation="b-a">
        <Original value={original_doc} />
        <Modified
          value={modified_doc}
          extensions={[
            EditorView.editable.of(false),
            EditorState.readOnly.of(true)
          ]}
        />
      </CodeMirrorMerge>
    </div>
  );
}

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

No branches or pull requests

2 participants