1
- import { App , Component , debounce , MarkdownRenderer , Menu , Modal , TAbstractFile , TFile , TFolder , WorkspaceLeaf } from 'obsidian' ;
1
+ import { App , Component , debounce , MarkdownRenderer , Menu , Modal , normalizePath , TAbstractFile , TFile , TFolder , WorkspaceLeaf } from 'obsidian' ;
2
2
import { formatFileSize , formatFileSizeKBMB , getFolderStructure } from './utils/format' ;
3
3
import { getPropsPerFile , getTagsPerFile } from './utils/tags' ;
4
4
import { DNPieChart } from './utils/dnpiechart' ;
@@ -82,7 +82,7 @@ export class DNModal extends Modal {
82
82
private readonly intersectionObserver : IntersectionObserver ;
83
83
private _DN_CTX_MENU : Menu ;
84
84
85
- private _previewComponent : Component ;
85
+ private _previewComponent : Component = new Component ( ) ;
86
86
private _hoverDiv : HTMLElement ;
87
87
private _hoverRender : HTMLElement ;
88
88
private _isDraggingPreview : boolean ;
@@ -103,7 +103,7 @@ export class DNModal extends Modal {
103
103
104
104
const { contentEl } = this ;
105
105
106
- this . _previewComponent = new Component ( ) ;
106
+ this . _previewComponent . load ( ) ;
107
107
this . _hoverDiv = this . contentEl . createEl ( 'div' , { cls : 'dn-preview' } ) ;
108
108
109
109
await this . updateModalData ( ) ;
@@ -122,6 +122,7 @@ export class DNModal extends Modal {
122
122
this . dnToggleColoredFiles ( ) ;
123
123
124
124
// Preview window
125
+
125
126
this . _isDraggingPreview = false ;
126
127
this . _hoverDivLeft = '' ;
127
128
this . _hoverDivTop = '' ;
@@ -425,6 +426,8 @@ export class DNModal extends Modal {
425
426
return param . slice ( 1 , - 1 ) ; // Remove single quotes
426
427
} else if ( param . startsWith ( "." ) ) {
427
428
return '\\' + param + '$' ;
429
+ } else if ( param . startsWith ( "/" ) && param . length === 1 ) {
430
+ return '^/$' ;
428
431
} else {
429
432
return param ;
430
433
}
@@ -445,7 +448,7 @@ export class DNModal extends Modal {
445
448
446
449
let rExp : RegExp ;
447
450
448
- const isExcludeSearch = val . startsWith ( '!' ) && val . length >= 2 ;
451
+ const isExcludeSearch = val . startsWith ( '!' ) && val . length >= 1 ;
449
452
let excludeParam = isExcludeSearch ? val . slice ( 1 ) : val ;
450
453
451
454
if ( excludeParam . startsWith ( '"' ) && excludeParam . endsWith ( '"' ) ) {
@@ -477,15 +480,23 @@ export class DNModal extends Modal {
477
480
}
478
481
479
482
if ( isExcludeSearch ) {
480
- this . _files_results = files . filter ( file => {
481
- const isMatch = file . name . toLowerCase ( ) . includes ( excludeParam ) ||
482
- getFolderStructure ( file . path ) . toLowerCase ( ) . includes ( excludeParam ) ||
483
- moment ( file . stat . mtime ) . format ( this . date_format ) . toLowerCase ( ) . includes ( excludeParam ) ||
484
- getTagsPerFile ( file ) . toLowerCase ( ) . includes ( excludeParam ) ||
485
- getPropsPerFile ( file ) . toLowerCase ( ) . includes ( excludeParam ) ;
486
-
487
- return isExcludeSearch ? ! isMatch : isMatch ;
488
- } ) ;
483
+ let isMatch : boolean ;
484
+ if ( excludeParam === '/' ) {
485
+ this . _files_results = files . filter ( file => {
486
+ isMatch = getFolderStructure ( file . path ) . toLowerCase ( ) === '/' ;
487
+ return isExcludeSearch ? ! isMatch : isMatch ;
488
+ } ) ;
489
+ } else {
490
+ this . _files_results = files . filter ( file => {
491
+ isMatch = file . name . toLowerCase ( ) . includes ( excludeParam ) ||
492
+ getFolderStructure ( file . path ) . toLowerCase ( ) . includes ( excludeParam ) ||
493
+ moment ( file . stat . mtime ) . format ( this . date_format ) . toLowerCase ( ) . includes ( excludeParam ) ||
494
+ getTagsPerFile ( file ) . toLowerCase ( ) . includes ( excludeParam ) ||
495
+ getPropsPerFile ( file ) . toLowerCase ( ) . includes ( excludeParam ) ;
496
+
497
+ return isExcludeSearch ? ! isMatch : isMatch ;
498
+ } ) ;
499
+ }
489
500
} else {
490
501
this . _files_results = files . filter (
491
502
file => {
@@ -1450,6 +1461,7 @@ export class DNModal extends Modal {
1450
1461
1451
1462
dnShowPreviewFile ( evt : MouseEvent , file : TFile ) {
1452
1463
this . _hoverDiv . empty ( ) ;
1464
+
1453
1465
const topBar = this . _hoverDiv . createEl ( 'div' , { cls : 'dn-preview-top-bar' } ) ;
1454
1466
const btnClosePreview = topBar . createEl ( 'div' , { cls : 'modal-close-button' } ) ;
1455
1467
@@ -1493,23 +1505,25 @@ export class DNModal extends Modal {
1493
1505
1494
1506
this . _hoverRender = this . _hoverDiv . createEl ( 'div' , { cls : 'dn-pr-content' } ) ;
1495
1507
1496
- MarkdownRenderer . render (
1497
- this . app ,
1498
- '![[' + file . path + ']]' ,
1499
- this . _hoverRender ,
1500
- file . path ,
1501
- this . _previewComponent
1502
- ) ;
1508
+ try {
1509
+ MarkdownRenderer . render (
1510
+ this . app ,
1511
+ '![[' + normalizePath ( file . path ) + ']]' ,
1512
+ this . _hoverRender ,
1513
+ normalizePath ( file . path ) ,
1514
+ this . _previewComponent
1515
+ ) ;
1516
+ } catch ( error ) {
1517
+ return ;
1518
+ }
1503
1519
1504
- this . _hoverRender . addEventListener ( 'mousedown' , ( evt : MouseEvent ) => { evt . stopPropagation ( ) } ) ;
1520
+ this . _hoverDiv . style . display = 'block' ;
1505
1521
1506
1522
// Drag event listeners
1507
1523
previewTop . addEventListener ( 'mousedown' , ( evt ) => this . dnHoverDragOnMouseDown ( evt ) ) ;
1508
1524
this . _hoverDiv . addEventListener ( 'mousemove' , ( evt ) => this . dnHoverDragOnMouseMove ( evt ) ) ;
1509
1525
this . _hoverDiv . addEventListener ( 'mouseup' , ( evt ) => this . dnHoverDragOnMouseUp ( evt ) ) ;
1510
1526
1511
- this . _hoverDiv . style . display = 'block' ;
1512
-
1513
1527
const screenWidth = window . innerWidth ;
1514
1528
const screenHeight = window . innerHeight ;
1515
1529
const divW = this . _hoverDiv . offsetWidth ;
@@ -1521,7 +1535,6 @@ export class DNModal extends Modal {
1521
1535
}
1522
1536
1523
1537
previewTop . removeEventListener ( 'mousedown' , ( evt ) => this . dnHoverDragOnMouseDown ( evt ) ) ;
1524
- this . _hoverRender . removeEventListener ( 'mousedown' , ( evt : MouseEvent ) => { evt . stopPropagation ( ) } ) ;
1525
1538
1526
1539
}
1527
1540
0 commit comments