@@ -331,6 +331,39 @@ export class DirTreeListing extends DirListing {
331
331
} ) ;
332
332
}
333
333
334
+ /**
335
+ * Handle 'mousedown' event
336
+ *
337
+ * Note: This allow to change the path to the root and clear selection when the user
338
+ * is clicking on an empty space.
339
+ */
340
+ private _eventMouseDown ( event : MouseEvent ) : void {
341
+ const entry = this . modelForClick ( event ) ;
342
+
343
+ if ( entry ) {
344
+ if ( entry . type === 'directory' ) {
345
+ this . model . path = '/' + entry . path ;
346
+
347
+ if (
348
+ this . _singleClickToUnfold &&
349
+ ( event . button === 0 || // State toggled on main button
350
+ ( event . button === 2 && ! this . model . isOpen ( entry . path ) ) || // State toggled on right click if folder is closed
351
+ event . type === 'click' ) // State toggled on click and double click
352
+ ) {
353
+ this . model . toggle ( entry . path ) ;
354
+ }
355
+ } else {
356
+ this . model . path = '/' + PathExt . dirname ( entry . path ) ;
357
+ }
358
+ } else {
359
+ // TODO Upstream this logic to JupyterLab (clearing selection when clicking the empty space)?
360
+ this . clearSelectedItems ( ) ;
361
+ this . update ( ) ;
362
+
363
+ this . model . path = this . model . rootPath ;
364
+ }
365
+ }
366
+
334
367
private _hitTestNodes ( nodes : HTMLElement [ ] , event : MouseEvent ) : number {
335
368
return ArrayExt . findFirstIndex (
336
369
nodes ,
@@ -356,43 +389,14 @@ export class DirTreeListing extends DirListing {
356
389
break ;
357
390
case 'mousedown' :
358
391
super . handleEvent ( event ) ;
359
- this . _changeModelPath ( event as MouseEvent ) ;
392
+ this . _eventMouseDown ( event as MouseEvent ) ;
360
393
break ;
361
394
default :
362
395
super . handleEvent ( event ) ;
363
396
break ;
364
397
}
365
398
}
366
399
367
- /**
368
- * Change the model path on each 'mousedown' event
369
- *
370
- * Note: This allow to change the path to the root when the user
371
- * is clicking on an empty space.
372
- */
373
- private _changeModelPath ( event : MouseEvent ) : void {
374
- const entry = this . modelForClick ( event ) ;
375
-
376
- if ( entry ) {
377
- if ( entry . type === 'directory' ) {
378
- this . model . path = '/' + entry . path ;
379
-
380
- if (
381
- this . _singleClickToUnfold &&
382
- ( event . button === 0 || // State toggled on main button
383
- ( event . button === 2 && ! this . model . isOpen ( entry . path ) ) || // State toggled on right click if folder is closed
384
- event . type === 'click' ) // State toggled on click and double click
385
- ) {
386
- this . model . toggle ( entry . path ) ;
387
- }
388
- } else {
389
- this . model . path = '/' + PathExt . dirname ( entry . path ) ;
390
- }
391
- } else {
392
- this . model . path = this . model . rootPath ;
393
- }
394
- }
395
-
396
400
private _singleClickToUnfold = true ;
397
401
}
398
402
0 commit comments