@@ -14,7 +14,8 @@ import { Panel, Widget } from '@lumino/widgets';
14
14
import { IDiffEntry } from 'nbdime/lib/diff/diffentries' ;
15
15
import { IMergeDecision } from 'nbdime/lib/merge/decisions' ;
16
16
import { NotebookMergeModel } from 'nbdime/lib/merge/model' ;
17
- import { NotebookMergeWidget } from 'nbdime/lib/merge/widget' ;
17
+ import { CELLMERGE_CLASS , NotebookMergeWidget } from 'nbdime/lib/merge/widget' ;
18
+ import { UNCHANGED_MERGE_CLASS } from 'nbdime/lib/merge/widget/common' ;
18
19
import { NotebookDiffModel } from 'nbdime/lib/diff/model' ;
19
20
import { CELLDIFF_CLASS , NotebookDiffWidget } from 'nbdime/lib/diff/widget' ;
20
21
import {
@@ -144,12 +145,20 @@ export class NotebookDiff
144
145
if ( this . _areUnchangedCellsHidden !== v ) {
145
146
Private . toggleShowUnchanged (
146
147
this . _scroller ,
148
+ this . _isConflict ,
147
149
this . _areUnchangedCellsHidden
148
150
) ;
149
151
this . _areUnchangedCellsHidden = v ;
150
152
}
151
153
}
152
154
155
+ /**
156
+ * Helper to determine if a notebook merge should be shown.
157
+ */
158
+ private get _isConflict ( ) : boolean {
159
+ return ! ! this . _model . base ;
160
+ }
161
+
153
162
/**
154
163
* Promise which fulfills when the widget is ready.
155
164
*/
@@ -213,13 +222,13 @@ export class NotebookDiff
213
222
try {
214
223
await nbdWidget . init ( ) ;
215
224
216
- Private . markUnchangedRanges ( this . _scroller . node ) ;
225
+ Private . markUnchangedRanges ( this . _scroller . node , this . _isConflict ) ;
217
226
} catch ( reason ) {
218
227
// FIXME there is a bug in nbdime and init got reject due to recursion limit hit
219
228
// console.error(`Failed to init notebook diff view: ${reason}`);
220
229
// getReady.reject(reason);
221
230
console . debug ( `Failed to init notebook diff view: ${ reason } ` ) ;
222
- Private . markUnchangedRanges ( this . _scroller . node ) ;
231
+ Private . markUnchangedRanges ( this . _scroller . node , this . _isConflict ) ;
223
232
}
224
233
} catch ( reason ) {
225
234
this . showError ( reason ) ;
@@ -322,7 +331,11 @@ namespace Private {
322
331
*
323
332
* This simply marks with a class, real work is done by CSS.
324
333
*/
325
- export function toggleShowUnchanged ( root : Widget , show ?: boolean ) : void {
334
+ export function toggleShowUnchanged (
335
+ root : Widget ,
336
+ isConflict : boolean ,
337
+ show ?: boolean
338
+ ) : void {
326
339
const hiding = root . hasClass ( HIDE_UNCHANGED_CLASS ) ;
327
340
if ( show === undefined ) {
328
341
show = hiding ;
@@ -333,7 +346,7 @@ namespace Private {
333
346
if ( show ) {
334
347
root . removeClass ( HIDE_UNCHANGED_CLASS ) ;
335
348
} else {
336
- markUnchangedRanges ( root . node ) ;
349
+ markUnchangedRanges ( root . node , isConflict ) ;
337
350
root . addClass ( HIDE_UNCHANGED_CLASS ) ;
338
351
}
339
352
root . update ( ) ;
@@ -360,12 +373,20 @@ namespace Private {
360
373
/**
361
374
* Marks certain cells with
362
375
*/
363
- export function markUnchangedRanges ( root : HTMLElement ) : void {
364
- const children = root . querySelectorAll ( `.${ CELLDIFF_CLASS } ` ) ;
376
+ export function markUnchangedRanges (
377
+ root : HTMLElement ,
378
+ isConflict : boolean
379
+ ) : void {
380
+ const CELL_CLASS = isConflict ? CELLMERGE_CLASS : CELLDIFF_CLASS ;
381
+ const UNCHANGED_CLASS = isConflict
382
+ ? UNCHANGED_MERGE_CLASS
383
+ : UNCHANGED_DIFF_CLASS ;
384
+
385
+ const children = root . querySelectorAll ( `.${ CELL_CLASS } ` ) ;
365
386
let rangeStart = - 1 ;
366
387
for ( let i = 0 ; i < children . length ; ++ i ) {
367
388
const child = children [ i ] ;
368
- if ( ! child . classList . contains ( UNCHANGED_DIFF_CLASS ) ) {
389
+ if ( ! child . classList . contains ( UNCHANGED_CLASS ) ) {
369
390
// Visible
370
391
if ( rangeStart !== - 1 ) {
371
392
// Previous was hidden
@@ -387,7 +408,10 @@ namespace Private {
387
408
if ( rangeStart === 0 ) {
388
409
// All elements were hidden, nothing to mark
389
410
// Add info on root instead
390
- const tag = root . querySelector ( '.jp-Notebook-diff' ) || root ;
411
+ const tag =
412
+ root . querySelector ( '.jp-Notebook-diff' ) ??
413
+ root . querySelector ( '.jp-Notebook-merge' ) ??
414
+ root ;
391
415
tag . setAttribute ( 'data-nbdime-AllCellsHidden' , N . toString ( ) ) ;
392
416
return ;
393
417
}
0 commit comments