Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Commit 51a2946

Browse files
authored
Version 5.2.1
1 parent ccff73e commit 51a2946

File tree

1 file changed

+37
-24
lines changed

1 file changed

+37
-24
lines changed

src/dn.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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';
22
import { formatFileSize, formatFileSizeKBMB, getFolderStructure } from './utils/format';
33
import { getPropsPerFile, getTagsPerFile } from './utils/tags';
44
import { DNPieChart } from './utils/dnpiechart';
@@ -82,7 +82,7 @@ export class DNModal extends Modal {
8282
private readonly intersectionObserver: IntersectionObserver;
8383
private _DN_CTX_MENU: Menu;
8484

85-
private _previewComponent: Component;
85+
private _previewComponent: Component = new Component();
8686
private _hoverDiv: HTMLElement;
8787
private _hoverRender: HTMLElement;
8888
private _isDraggingPreview: boolean;
@@ -103,7 +103,7 @@ export class DNModal extends Modal {
103103

104104
const { contentEl } = this;
105105

106-
this._previewComponent = new Component();
106+
this._previewComponent.load();
107107
this._hoverDiv = this.contentEl.createEl('div', { cls: 'dn-preview' });
108108

109109
await this.updateModalData();
@@ -122,6 +122,7 @@ export class DNModal extends Modal {
122122
this.dnToggleColoredFiles();
123123

124124
// Preview window
125+
125126
this._isDraggingPreview = false;
126127
this._hoverDivLeft = '';
127128
this._hoverDivTop = '';
@@ -425,6 +426,8 @@ export class DNModal extends Modal {
425426
return param.slice(1, -1); // Remove single quotes
426427
} else if (param.startsWith(".")) {
427428
return '\\' + param + '$';
429+
} else if (param.startsWith("/") && param.length === 1) {
430+
return '^/$';
428431
} else {
429432
return param;
430433
}
@@ -445,7 +448,7 @@ export class DNModal extends Modal {
445448

446449
let rExp: RegExp;
447450

448-
const isExcludeSearch = val.startsWith('!') && val.length >= 2;
451+
const isExcludeSearch = val.startsWith('!') && val.length >= 1;
449452
let excludeParam = isExcludeSearch ? val.slice(1) : val;
450453

451454
if (excludeParam.startsWith('"') && excludeParam.endsWith('"')) {
@@ -477,15 +480,23 @@ export class DNModal extends Modal {
477480
}
478481

479482
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+
}
489500
} else {
490501
this._files_results = files.filter(
491502
file => {
@@ -1450,6 +1461,7 @@ export class DNModal extends Modal {
14501461

14511462
dnShowPreviewFile(evt: MouseEvent, file: TFile) {
14521463
this._hoverDiv.empty();
1464+
14531465
const topBar = this._hoverDiv.createEl('div', { cls: 'dn-preview-top-bar' });
14541466
const btnClosePreview = topBar.createEl('div', { cls: 'modal-close-button' });
14551467

@@ -1493,23 +1505,25 @@ export class DNModal extends Modal {
14931505

14941506
this._hoverRender = this._hoverDiv.createEl('div', { cls: 'dn-pr-content' });
14951507

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+
}
15031519

1504-
this._hoverRender.addEventListener('mousedown', (evt: MouseEvent) => { evt.stopPropagation() });
1520+
this._hoverDiv.style.display = 'block';
15051521

15061522
// Drag event listeners
15071523
previewTop.addEventListener('mousedown', (evt) => this.dnHoverDragOnMouseDown(evt));
15081524
this._hoverDiv.addEventListener('mousemove', (evt) => this.dnHoverDragOnMouseMove(evt));
15091525
this._hoverDiv.addEventListener('mouseup', (evt) => this.dnHoverDragOnMouseUp(evt));
15101526

1511-
this._hoverDiv.style.display = 'block';
1512-
15131527
const screenWidth = window.innerWidth;
15141528
const screenHeight = window.innerHeight;
15151529
const divW = this._hoverDiv.offsetWidth;
@@ -1521,7 +1535,6 @@ export class DNModal extends Modal {
15211535
}
15221536

15231537
previewTop.removeEventListener('mousedown', (evt) => this.dnHoverDragOnMouseDown(evt));
1524-
this._hoverRender.removeEventListener('mousedown', (evt: MouseEvent) => { evt.stopPropagation() });
15251538

15261539
}
15271540

0 commit comments

Comments
 (0)