Skip to content

Commit 321b502

Browse files
authored
Merge pull request #489 from fcollonval/diff-file-fix
Correct bug on plain text diff
2 parents 1087e67 + 5be7ce3 commit 321b502

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/components/diff/PlainTextDiff.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as React from 'react';
66
import { IDiffProps } from './Diff';
77
import { httpGitRequest } from '../../git';
88
import { mergeView } from './mergeview';
9-
import { getRefValue, IDiffContext } from './model';
9+
import { getRefValue, IDiffContext, IGitRef, ISpecialRef } from './model';
1010

1111
interface ICurrentReference {
1212
special?: 'WORKING' | 'INDEX';
@@ -35,7 +35,7 @@ export class PlainTextDiff extends React.Component<
3535
}
3636

3737
componentDidMount() {
38-
this.performDiff(this.props.diffContext);
38+
this._performDiff(this.props.diffContext);
3939
}
4040

4141
render() {
@@ -55,9 +55,10 @@ export class PlainTextDiff extends React.Component<
5555
<div className="jp-git-diff-Widget">
5656
<div className="jp-git-diff-root">
5757
<div
58-
id={`diffviewer-${this.props.path}-${getRefValue(
58+
id={this._generateID(
59+
this.props.path,
5960
this.props.diffContext.currentRef
60-
)}`}
61+
)}
6162
className="jp-git-PlainText-diff"
6263
/>
6364
</div>
@@ -71,7 +72,7 @@ export class PlainTextDiff extends React.Component<
7172
* to
7273
* @param diffContext the context in which to perform the diff
7374
*/
74-
private performDiff(diffContext: IDiffContext): void {
75+
private _performDiff(diffContext: IDiffContext): void {
7576
try {
7677
// Resolve what API parameter to call.
7778
let currentRefValue: ICurrentReference;
@@ -119,6 +120,12 @@ export class PlainTextDiff extends React.Component<
119120
}
120121
}
121122

123+
private _generateID(path: string, currentRef: IGitRef | ISpecialRef): string {
124+
return `diffviewer-${this.props.path.replace('/', '-')}-${getRefValue(
125+
this.props.diffContext.currentRef
126+
)}`;
127+
}
128+
122129
/**
123130
* Creates and adds a diff viewer to the DOM with given content
124131
*
@@ -130,9 +137,7 @@ export class PlainTextDiff extends React.Component<
130137

131138
mergeView(
132139
document.getElementById(
133-
`diffviewer-${this.props.path.replace('/', '-')}-${getRefValue(
134-
this.props.diffContext.currentRef
135-
)}`
140+
this._generateID(this.props.path, this.props.diffContext.currentRef)
136141
),
137142
{
138143
value: currContent,

0 commit comments

Comments
 (0)