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

Lines disalign between different files #203

Open
JerryLu991223 opened this issue Dec 2, 2024 · 0 comments
Open

Lines disalign between different files #203

JerryLu991223 opened this issue Dec 2, 2024 · 0 comments

Comments

@JerryLu991223
Copy link

JerryLu991223 commented Dec 2, 2024

Currently, I find that the split line between origin code and current is not stable. I have adjusted the style for "line", but it still misaligned.
截屏2024-12-02 17 21 10

Here is my code:

import React from "react"
import ReactDiffViewer, { DiffMethod, ReactDiffViewerStylesOverride } from "react-diff-viewer"

interface IProps {
  filePath?: string
  oldValue?: string
  newValue?: string
  leftTitle?: string
  rightTitle?: string
  splitView?: boolean
  loading?: boolean
}

const styles = {
  line: {
    wordBreak: 'break-word',
    whiteSpace: "normal"
  },
  diffContainer: {
    borderRadius: '8px',
    border: '1px solid #e8e8e8',
  },
  gutter: {
    width: '2.5%'
  }
}

const DiffViewer: React.FC<IProps> = ({ filePath, oldValue, newValue, rightTitle, loading, splitView = true }) => {
  // const highlightSyntax = (str) => (
  //   <pre
  //     style={{ display: "inline" }}
  //     class="foo"
  //     dangerouslySetInnerHTML={{
  //       // __html: Prism.highlight(str, Prism.languages.javascript)
  //       __html: Prism.highlight(str, Prism.languages.json, "json")
  //       // __html: str
  //     }}
  //   />
  // );

  return (
    <div >
      {loading && (
          <CubeSpin />
        ) || <ReactDiffViewer
          oldValue={oldValue?.toString()}
          newValue={newValue?.toString()}
          splitView={splitView}
          compareMethod={DiffMethod.WORDS}
          leftTitle={filePath}
          rightTitle={rightTitle}
          styles={styles as ReactDiffViewerStylesOverride}
          // renderContent={highlightSyntax}
        />}
    </div>
  );
}

export default DiffViewer;

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

1 participant