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 MergeView plugin #455

Open
ledge74 opened this issue Feb 6, 2023 · 10 comments
Open

How to use MergeView plugin #455

ledge74 opened this issue Feb 6, 2023 · 10 comments

Comments

@ledge74
Copy link

ledge74 commented Feb 6, 2023

Hi there,

I'm trying to implement a diff editor with react-codemirror. Is there a way to use the recently created MergeView plugin with this library ?

https://github.com/codemirror/merge
https://marijnhaverbeke.nl/upload/merge/

Thanks!

@jaywcjlove
Copy link
Member

After looking at it, the props API needs to be redesigned and researched.
@ledge74

@maxgurewitz
Copy link

Hey all, what's the current state of your thinking here @jaywcjlove @ledge74 ?

@jaywcjlove
Copy link
Member

@maxgurewitz I try to add a MergeCodeMirror component

import CodeMirror from '@uiw/react-codemirror';  
import { MergeCodeMirror } from '@uiw/react-codemirror';  

@jaywcjlove
Copy link
Member

import { MergeCodeMirror } from '@uiw/react-codemirror'; 

const Original = MergeCodeMirror.Original;
const Modified = MergeCodeMirror.Modified;

<MergeCodeMirror>
  <Original value="txt" extensions=[]/>
  <Modified value="text" extensions=[] />
</MergeCodeMirror>

@ledge74 @maxgurewitz I don't know if this design is reasonable

@jaywcjlove
Copy link
Member

jaywcjlove commented Apr 7, 2023

@ledge74 @maxgurewitz I have implemented an initial version.

import CodeMirrorMerge from 'react-codemirror-merge';
import { EditorView } from 'codemirror';
import { EditorState } from '@codemirror/state';

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

export const Example = () => {
  return (
    <CodeMirrorMerge>
      <Original value={doc} />
      <Modified
        value={doc.replace(/t/g, 'T') + 'Six'}
        extensions={[EditorView.editable.of(false), EditorState.readOnly.of(true)]}
      />
    </CodeMirrorMerge>
  );
};

npm version

@jaywcjlove
Copy link
Member

jaywcjlove commented Apr 7, 2023

image

npm version

@jaywcjlove
Copy link
Member

@Salvehn
Copy link

Salvehn commented Apr 17, 2023

any diff_match_patch integration ideas?

@anthonyvii27
Copy link

Does anyone know how to insert a custom theme into CodeMirrorMerge? Like the Android Studio theme that can be found in the library below.

import { androidstudio } from "@uiw/codemirror-theme-androidstudio";

I'm trying to use this component, but it's not working. For default CodeMirror (@uiw/react-codemirror), it worked perfectly.

<CodeMirrorMerge
  orientation="a-b"
  theme={androidstudio}
>
  // CONTENT
</CodeMirrorMerge>

@jaywcjlove
Copy link
Member

@anthonyvii27

import CodeMirrorMerge from 'react-codemirror-merge';
import { EditorView } from 'codemirror';
import { EditorState } from '@codemirror/state';
import { androidstudio } from '@uiw/codemirror-theme-androidstudio';

const Original = CodeMirrorMerge.Original;
const Modified = CodeMirrorMerge.Modified;
/**
 * https://github.com/uiwjs/react-codemirror/issues/455
 */
let doc = `one
two
three
four
five`;

export const PageExample455 = () => {
  return (
    <CodeMirrorMerge style={{ width: 540 }} orientation="b-a" theme={androidstudio}>
      <Original value={doc} />
      <Modified
        value={doc.replace(/t/g, 'T') + 'Six'}
        extensions={[EditorView.editable.of(false), EditorState.readOnly.of(true)]}
      />
    </CodeMirrorMerge>
  );
};

jaywcjlove added a commit that referenced this issue Aug 3, 2023
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

5 participants