@@ -288,6 +288,38 @@ describe('@jupyterlab/notebook', () => {
288
288
expect ( source ) . toBe ( 'rabarbar' ) ;
289
289
expect ( provider . currentMatchIndex ) . toBe ( null ) ;
290
290
} ) ;
291
+
292
+ it ( 'should not replace the current match in a read-only cell' , async ( ) => {
293
+ panel . model ! . sharedModel . insertCells ( 0 , [
294
+ {
295
+ cell_type : 'markdown' ,
296
+ source : 'test1' ,
297
+ metadata : { editable : false }
298
+ } ,
299
+ { cell_type : 'code' , source : 'test2' , metadata : { editable : false } }
300
+ ] ) ;
301
+
302
+ await provider . startQuery ( / t e s t \d / , undefined ) ;
303
+ expect ( provider . currentMatchIndex ) . toBe ( 0 ) ;
304
+ let replaced = await provider . replaceCurrentMatch ( 'bar' ) ;
305
+ expect ( replaced ) . toBe ( false ) ;
306
+ const source = panel . model ! . cells . get ( 0 ) . sharedModel . getSource ( ) ;
307
+ expect ( source ) . toBe ( 'test1' ) ;
308
+
309
+ await provider . highlightNext ( ) ;
310
+ expect ( provider . currentMatchIndex ) . toBe ( 1 ) ;
311
+ replaced = await provider . replaceCurrentMatch ( 'bar' ) ;
312
+ expect ( replaced ) . toBe ( false ) ;
313
+ const source1 = panel . model ! . cells . get ( 1 ) . sharedModel . getSource ( ) ;
314
+ expect ( source1 ) . toBe ( 'test2' ) ;
315
+
316
+ await provider . highlightNext ( ) ;
317
+ expect ( provider . currentMatchIndex ) . toBe ( 2 ) ;
318
+ replaced = await provider . replaceCurrentMatch ( 'bar' ) ;
319
+ expect ( replaced ) . toBe ( true ) ;
320
+ const source2 = panel . model ! . cells . get ( 2 ) . sharedModel . getSource ( ) ;
321
+ expect ( source2 ) . toBe ( 'bar test2' ) ;
322
+ } ) ;
291
323
} ) ;
292
324
293
325
describe ( '#replaceAllMatches()' , ( ) => {
@@ -354,6 +386,34 @@ describe('@jupyterlab/notebook', () => {
354
386
expect ( source ) . toBe ( 'test1\nbar2\nbar3\nbar4\ntest5' ) ;
355
387
await provider . endQuery ( ) ;
356
388
} ) ;
389
+
390
+ it ( 'should not replace all matches in read-only cells' , async ( ) => {
391
+ panel . model ! . sharedModel . insertCells ( 2 , [
392
+ {
393
+ cell_type : 'markdown' ,
394
+ source : 'test1 test2' ,
395
+ metadata : { editable : false }
396
+ } ,
397
+ {
398
+ cell_type : 'code' ,
399
+ source : 'test1 test2 test3' ,
400
+ metadata : { editable : false }
401
+ }
402
+ ] ) ;
403
+ await provider . startQuery ( / t e s t \d / , undefined ) ;
404
+ await provider . highlightNext ( ) ;
405
+ const replaced = await provider . replaceAllMatches ( 'test0' ) ;
406
+ expect ( replaced ) . toBe ( true ) ;
407
+ let source = panel . model ! . cells . get ( 0 ) . sharedModel . getSource ( ) ;
408
+ expect ( source ) . toBe ( 'test0 test0' ) ;
409
+ source = panel . model ! . cells . get ( 1 ) . sharedModel . getSource ( ) ;
410
+ expect ( source ) . toBe ( 'test0' ) ;
411
+ source = panel . model ! . cells . get ( 2 ) . sharedModel . getSource ( ) ;
412
+ expect ( source ) . toBe ( 'test1 test2' ) ;
413
+ source = panel . model ! . cells . get ( 3 ) . sharedModel . getSource ( ) ;
414
+ expect ( source ) . toBe ( 'test1 test2 test3' ) ;
415
+ expect ( provider . currentMatchIndex ) . toBe ( null ) ;
416
+ } ) ;
357
417
} ) ;
358
418
359
419
describe ( '#getSelectionState()' , ( ) => {
0 commit comments