Skip to content

Commit 4f5b45f

Browse files
committed
Fixing gutter highlight and word diff highlight during line select
1 parent 7254fd9 commit 4f5b45f

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ const defaultStyles = {
189189
wordRemoved?: {}, //style object
190190
codeFoldGutter?: {}, //style object
191191
emptyLine?: {}, //style object
192+
emptyGutter?: {}, //style object
192193
}
193194
```
194195

Diff for: src/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
217217
lineNumber && this.onLineNumberClickProxy(lineNumberTemplate)
218218
}
219219
className={cn(this.styles.gutter, {
220+
[this.styles.emptyGutter]: !lineNumber,
220221
[this.styles.diffAdded]: added,
221222
[this.styles.diffRemoved]: removed,
222223
[this.styles.highlightedGutter]: highlightLine,
@@ -232,6 +233,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
232233
&& this.onLineNumberClickProxy(additionalLineNumberTemplate)
233234
}
234235
className={cn(this.styles.gutter, {
236+
[this.styles.emptyGutter]: !additionalLineNumber,
235237
[this.styles.diffAdded]: added,
236238
[this.styles.diffRemoved]: removed,
237239
[this.styles.highlightedGutter]: highlightLine,

Diff for: src/styles.ts

+32-18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface ReactDiffViewerStyles {
1414
wordAdded?: string;
1515
wordRemoved?: string;
1616
codeFoldGutter?: string;
17+
emptyGutter?: string;
1718
emptyLine?: string;
1819
codeFold?: string;
1920
[key: string]: string;
@@ -42,6 +43,7 @@ export interface ReactDiffViewerStylesOverride {
4243
diffRemoved?: Interpolation;
4344
diffAdded?: Interpolation;
4445
marker?: Interpolation;
46+
emptyGutter?: Interpolation;
4547
highlightedLine?: Interpolation;
4648
highlightedGutter?: Interpolation;
4749
gutter?: Interpolation;
@@ -110,6 +112,23 @@ export default (styleOverride: ReactDiffViewerStylesOverride): ReactDiffViewerSt
110112
label: 'diff-added',
111113
});
112114

115+
const wordDiff = css({
116+
padding: 2,
117+
display: 'inline-flex',
118+
borderRadius: 1,
119+
label: 'word-diff',
120+
});
121+
122+
const wordAdded = css({
123+
background: variables.wordAddedBackground,
124+
label: 'word-added',
125+
});
126+
127+
const wordRemoved = css({
128+
background: variables.wordRemovedBackground,
129+
label: 'word-removed',
130+
});
131+
113132
const codeFoldGutter = css({
114133
backgroundColor: variables.codeFoldGutterBackground,
115134
label: 'code-fold-gutter',
@@ -155,6 +174,9 @@ export default (styleOverride: ReactDiffViewerStylesOverride): ReactDiffViewerSt
155174
const highlightedLine = css({
156175
background: variables.highlightBackground,
157176
label: 'highlighted-line',
177+
[`.${wordAdded}, .${wordRemoved}`]: {
178+
backgroundColor: 'initial',
179+
},
158180
});
159181

160182
const highlightedGutter = css({
@@ -166,10 +188,10 @@ export default (styleOverride: ReactDiffViewerStylesOverride): ReactDiffViewerSt
166188
minWidth: 40,
167189
padding: '0 10px',
168190
label: 'gutter',
169-
cursor: 'pointer',
170191
textAlign: 'right',
171192
background: variables.gutterBackground,
172193
'&:hover': {
194+
cursor: 'pointer',
173195
background: variables.gutterBackgroundDark,
174196
pre: {
175197
opacity: 1,
@@ -192,28 +214,19 @@ export default (styleOverride: ReactDiffViewerStylesOverride): ReactDiffViewerSt
192214
},
193215
});
194216

217+
const emptyGutter = css({
218+
'&:hover': {
219+
background: variables.gutterBackground,
220+
cursor: 'initial',
221+
},
222+
label: 'empty-gutter',
223+
});
224+
195225
const line = css({
196226
verticalAlign: 'baseline',
197227
label: 'line',
198228
});
199229

200-
const wordDiff = css({
201-
padding: 2,
202-
display: 'inline-flex',
203-
borderRadius: 1,
204-
label: 'word-diff',
205-
});
206-
207-
const wordAdded = css({
208-
background: variables.wordAddedBackground,
209-
label: 'word-added',
210-
});
211-
212-
const wordRemoved = css({
213-
background: variables.wordRemovedBackground,
214-
label: 'word-removed',
215-
});
216-
217230
const defaultStyles: any = {
218231
diffContainer,
219232
diffRemoved,
@@ -228,6 +241,7 @@ export default (styleOverride: ReactDiffViewerStylesOverride): ReactDiffViewerSt
228241
wordRemoved,
229242
codeFoldGutter,
230243
codeFold,
244+
emptyGutter,
231245
emptyLine,
232246
};
233247

0 commit comments

Comments
 (0)