@@ -6,7 +6,7 @@ import * as React from 'react';
6
6
import { IDiffProps } from './Diff' ;
7
7
import { httpGitRequest } from '../../git' ;
8
8
import { mergeView } from './mergeview' ;
9
- import { getRefValue , IDiffContext , IGitRef , ISpecialRef } from './model' ;
9
+ import { IDiffContext } from './model' ;
10
10
11
11
interface ICurrentReference {
12
12
special ?: 'WORKING' | 'INDEX' ;
@@ -32,6 +32,7 @@ export class PlainTextDiff extends React.Component<
32
32
constructor ( props : IPlainTextDiffProps ) {
33
33
super ( props ) ;
34
34
this . state = { errorMessage : null } ;
35
+ this . _mergeViewRef = React . createRef < HTMLDivElement > ( ) ;
35
36
}
36
37
37
38
componentDidMount ( ) {
@@ -54,13 +55,7 @@ export class PlainTextDiff extends React.Component<
54
55
return (
55
56
< div className = "jp-git-diff-Widget" >
56
57
< div className = "jp-git-diff-root" >
57
- < div
58
- id = { this . _generateID (
59
- this . props . path ,
60
- this . props . diffContext . currentRef
61
- ) }
62
- className = "jp-git-PlainText-diff"
63
- />
58
+ < div ref = { this . _mergeViewRef } className = "jp-git-PlainText-diff" />
64
59
</ div >
65
60
</ div >
66
61
) ;
@@ -120,12 +115,6 @@ export class PlainTextDiff extends React.Component<
120
115
}
121
116
}
122
117
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
-
129
118
/**
130
119
* Creates and adds a diff viewer to the DOM with given content
131
120
*
@@ -135,22 +124,19 @@ export class PlainTextDiff extends React.Component<
135
124
private _addDiffViewer ( prevContent : string , currContent : string ) {
136
125
const mode = Mode . findByFileName ( this . props . path ) ;
137
126
138
- mergeView (
139
- document . getElementById (
140
- this . _generateID ( this . props . path , this . props . diffContext . currentRef )
141
- ) ,
142
- {
143
- value : currContent ,
144
- orig : prevContent ,
145
- lineNumbers : true ,
146
- mode : mode . mime ,
147
- theme : 'jupyter' ,
148
- connect : 'align' ,
149
- collapseIdentical : true ,
150
- revertButtons : false
151
- }
152
- ) ;
127
+ mergeView ( this . _mergeViewRef . current , {
128
+ value : currContent ,
129
+ orig : prevContent ,
130
+ lineNumbers : true ,
131
+ mode : mode . mime ,
132
+ theme : 'jupyter' ,
133
+ connect : 'align' ,
134
+ collapseIdentical : true ,
135
+ revertButtons : false
136
+ } ) ;
153
137
}
138
+
139
+ private _mergeViewRef : React . RefObject < HTMLDivElement > ;
154
140
}
155
141
156
142
/**
0 commit comments