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 · 12 comments
Open

How to use MergeView plugin #455

ledge74 opened this issue Feb 6, 2023 · 12 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 added a commit that referenced this issue Apr 7, 2023

Verified

This commit was signed with the committer’s verified signature.
spencerschrock Spencer Schrock
github-actions bot pushed a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@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 added a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
github-actions bot pushed a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
jaywcjlove added a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@jaywcjlove
Copy link
Member

jaywcjlove commented Apr 7, 2023

image

npm version

jaywcjlove added a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
github-actions bot pushed a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…) eb6b780
github-actions bot pushed a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
jaywcjlove added a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
github-actions bot pushed a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
jaywcjlove added a commit that referenced this issue Apr 7, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@jaywcjlove
Copy link
Member

github-actions bot pushed a commit that referenced this issue Apr 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
jaywcjlove referenced this issue Apr 8, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
…tChanges`, `gutter` props.
jaywcjlove added a commit that referenced this issue Apr 8, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
github-actions bot pushed a commit that referenced this issue Apr 8, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@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

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
github-actions bot pushed a commit that referenced this issue Aug 3, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
@nichochar
Copy link

The codemirror-merge library now supports a unifiedView mode.
It would be nice to have this react library support it. I'm not sure how much of the interfaces it would change however.
Here's a code snippet and screenshot that show what it takes with a minimal setup:

import {unifiedMergeView} from "@codemirror/merge"
import {EditorView, basicSetup} from "codemirror"
import {EditorState} from "@codemirror/state"


let doc = `one
two
three
four
five`

new EditorView({
  doc,
  extensions: [basicSetup, unifiedMergeView({
    original: doc.replace(/t/g, "T") + "\nSix",
    mergeControls: false,
  })],
  parent: document.body
})

CleanShot 2024-07-19 at 12 08 10

I need this asap, so will try to hack something up, but it would be good to have support in this (great) react library natively

@maxgurewitz
Copy link

thank you @jaywcjlove !

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

6 participants