|
1 | 1 | class SidebarEnhancePlugin extends BasePlugin { |
2 | 2 | process = () => { |
3 | | - if (this.config.DISPLAY_NON_MARKDOWN_FILES && File.SupportedFiles) { |
| 3 | + const displayNonMarkdownFiles = File.SupportedFiles && this.config.DISPLAY_NON_MARKDOWN_FILES |
| 4 | + if (displayNonMarkdownFiles) { |
4 | 5 | this._displayNonMarkdownFiles() |
5 | | - if (this.config.CUSTOMIZE_SIDEBAR_ICONS) { |
6 | | - this._customizeSidebarIcons() |
7 | | - } |
| 6 | + } |
| 7 | + if (this.config.HIDDEN_FOLDER_PATTERNS.length || (displayNonMarkdownFiles && this.config.CUSTOMIZE_SIDEBAR_ICONS)) { |
| 8 | + this._rerenderOutlineNode() |
8 | 9 | } |
9 | 10 | if (this.config.KEEP_OUTLINE_FOLD_STATE && File.option.canCollapseOutlinePanel) { |
10 | 11 | this._keepOutlineFoldState() |
@@ -41,20 +42,45 @@ class SidebarEnhancePlugin extends BasePlugin { |
41 | 42 | }) |
42 | 43 | } |
43 | 44 |
|
44 | | - _customizeSidebarIcons = () => { |
45 | | - const ICONS = new Map( |
46 | | - this.config.SIDEBAR_ICONS |
47 | | - .filter(item => item.enable && item.extensions.length && item.extensions.every(ext => !!ext)) |
48 | | - .flatMap(item => item.extensions.map(ext => [`.${ext.trim()}`, item.icon.trim()])) |
49 | | - ) |
50 | | - this.utils.decorate(() => File?.editor?.library?.fileTree, "renderNode", null, ($node, info) => { |
51 | | - if (!info.isFile) return |
52 | | - const ext = this.utils.Package.Path.extname(info.name) |
53 | | - const icon = ICONS.get(ext) |
54 | | - if (icon) { |
55 | | - $node.find(".file-node-icon").removeClass("fa fa-file-text-o").addClass(icon) |
| 45 | + _rerenderOutlineNode = () => { |
| 46 | + const getCustomFileIcons = () => { |
| 47 | + const ICONS = new Map( |
| 48 | + this.config.SIDEBAR_ICONS |
| 49 | + .filter(item => item.enable && item.extensions.length && item.extensions.every(ext => !!ext)) |
| 50 | + .flatMap(item => item.extensions.map(ext => [`.${ext.trim()}`, item.icon.trim()])) |
| 51 | + ) |
| 52 | + const fn = ($node, info) => { |
| 53 | + if (!info.isFile) return |
| 54 | + const ext = this.utils.Package.Path.extname(info.name) |
| 55 | + const icon = ICONS.get(ext) |
| 56 | + if (icon) $node.find(".file-node-icon").removeClass("fa fa-file-text-o").addClass(icon) |
| 57 | + } |
| 58 | + return this.config.CUSTOMIZE_SIDEBAR_ICONS && ICONS.size ? fn : this.utils.identity |
| 59 | + } |
| 60 | + |
| 61 | + const getHideFolders = () => { |
| 62 | + const newRegexp = p => { |
| 63 | + try { |
| 64 | + return new RegExp(p) |
| 65 | + } catch (e) { |
| 66 | + } |
| 67 | + } |
| 68 | + const REGEXPS = this.config.HIDDEN_FOLDER_PATTERNS.map(newRegexp).filter(Boolean) |
| 69 | + const fn = ($node, info) => { |
| 70 | + if (info.isDirectory && REGEXPS.some(reg => reg.test(info.name))) { |
| 71 | + $node.addClass("plugin-common-hidden") |
| 72 | + } |
56 | 73 | } |
| 74 | + return REGEXPS.length ? fn : this.utils.identity |
| 75 | + } |
| 76 | + |
| 77 | + const customizeFileIcons = getCustomFileIcons() |
| 78 | + const hideFolders = getHideFolders() |
| 79 | + this.utils.decorate(() => File?.editor?.library?.fileTree, "renderNode", null, ($node, info) => { |
| 80 | + customizeFileIcons($node, info) |
| 81 | + hideFolders($node, info) |
57 | 82 | }) |
| 83 | + |
58 | 84 | this.utils.eventHub.once(this.utils.eventHub.eventType.fileOpened, () => File.editor.library.refreshPanelCommand()) |
59 | 85 | } |
60 | 86 |
|
|
0 commit comments