Skip to content

Commit c004629

Browse files
KirboAeolun
andauthored
feat: add hideMarkers (#37)
Co-authored-by: Bart Riepe <[email protected]>
1 parent ef88b39 commit c004629

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class Diff extends PureComponent {
7676
| compareMethod | `DiffMethod` | `DiffMethod.CHARS` | JsDiff text diff method used for diffing strings. Check out the [guide](https://github.com/praneshr/react-diff-viewer/tree/v3.0.0#text-block-diff-comparison) to use different methods. |
7777
| renderGutter | `(diffData) => ReactNode` | `undefined` | Function that can be used to render an extra gutter with various information next to the line number. |
7878
| hideLineNumbers | `boolean` | `false` | Show and hide line numbers. |
79-
| alwaysShowLines | `string[]` | `[]` | List of lines to always be shown, regardless of diff status. Line number are prefixed with `L` and `R` for the left and right section of the diff viewer, respectively. For example, `L-20` means 20th line in the left pane. `extraLinesSurroundingDiff` applies to these lines as well. |
79+
| hideMarkers | `boolean` | `false` | Show and hide `+`/`-` markers. |
80+
| alwaysShowLines | `string[]` | `[]` | List of lines to always be shown, regardless of diff status. Line number are prefixed with `L` and `R` for the left and right section of the diff viewer, respectively. For example, `L-20` means 20th line in the left pane. `extraLinesSurroundingDiff` applies to these lines as well. |
8081
| renderContent | `function` | `undefined` | Render Prop API to render code in the diff viewer. Helpful for [syntax highlighting](#syntax-highlighting) |
8182
| onLineNumberClick | `function` | `undefined` | Event handler for line number click. `(lineId: string) => void` |
8283
| highlightLines | `string[]` | `[]` | List of lines to be highlighted. Works together with `onLineNumberClick`. Line number are prefixed with `L` and `R` for the left and right section of the diff viewer, respectively. For example, `L-20` means 20th line in the left pane. To highlight a range of line numbers, pass the prefixed line number as an array. For example, `[L-2, L-3, L-4, L-5]` will highlight the lines `2-5` in the left pane. |

src/index.tsx

+29-17
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface ReactDiffViewerProps {
3333
extraLinesSurroundingDiff?: number;
3434
// Show/hide line number.
3535
hideLineNumbers?: boolean;
36+
// Show/hide `+`/`-` markers.
37+
hideMarkers?: boolean;
3638
/**
3739
* Show the lines indicated here. Specified as L20 or R18 for respectively line 20 on the left or line 18 on the right.
3840
*/
@@ -96,6 +98,7 @@ class DiffViewer extends React.Component<
9698
compareMethod: DiffMethod.CHARS,
9799
styles: {},
98100
hideLineNumbers: false,
101+
hideMarkers: false,
99102
extraLinesSurroundingDiff: 3,
100103
showDiffOnly: true,
101104
useDarkTheme: false,
@@ -272,20 +275,22 @@ class DiffViewer extends React.Component<
272275
styles: this.styles,
273276
})
274277
: null}
275-
<td
276-
className={cn(this.styles.marker, {
277-
[this.styles.emptyLine]: !content,
278-
[this.styles.diffAdded]: added,
279-
[this.styles.diffRemoved]: removed,
280-
[this.styles.diffChanged]: changed,
281-
[this.styles.highlightedLine]: highlightLine,
282-
})}
283-
>
284-
<pre>
285-
{added && '+'}
286-
{removed && '-'}
287-
</pre>
288-
</td>
278+
{!this.props.hideMarkers && (
279+
<td
280+
className={cn(this.styles.marker, {
281+
[this.styles.emptyLine]: !content,
282+
[this.styles.diffAdded]: added,
283+
[this.styles.diffRemoved]: removed,
284+
[this.styles.diffChanged]: changed,
285+
[this.styles.highlightedLine]: highlightLine,
286+
})}
287+
>
288+
<pre>
289+
{added && '+'}
290+
{removed && '-'}
291+
</pre>
292+
</td>
293+
)}
289294
<td
290295
className={cn(this.styles.content, {
291296
[this.styles.emptyLine]: !content,
@@ -556,6 +561,7 @@ class DiffViewer extends React.Component<
556561
rightTitle,
557562
splitView,
558563
hideLineNumbers,
564+
hideMarkers,
559565
nonce,
560566
} = this.props;
561567

@@ -567,9 +573,15 @@ class DiffViewer extends React.Component<
567573

568574
this.styles = this.computeStyles(this.props.styles, useDarkTheme, nonce);
569575
const nodes = this.renderDiff();
570-
const colSpanOnSplitView = hideLineNumbers ? 2 : 3;
571-
const colSpanOnInlineView = hideLineNumbers ? 2 : 4;
572-
let columnExtension = this.props.renderGutter ? 1 : 0;
576+
let colSpanOnSplitView = hideLineNumbers ? 2 : 3;
577+
let colSpanOnInlineView = hideLineNumbers ? 2 : 4;
578+
579+
if (hideMarkers) {
580+
colSpanOnSplitView -= 1;
581+
colSpanOnInlineView -= 1;
582+
}
583+
584+
const columnExtension = this.props.renderGutter ? 1 : 0;
573585

574586
const title = (leftTitle || rightTitle) && (
575587
<tr>

0 commit comments

Comments
 (0)