This commit is contained in:
Neway13 2024-06-13 20:44:51 -04:00 committed by GitHub
commit e31f2fb9ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'
import { isFile, isFile2, isSymbolicLink } from './index'
import minimatch from 'minimatch'
const isOsx = process.platform === 'darwin'
@ -120,3 +121,19 @@ export const getResourcesPath = () => {
}
return resPath
}
/**
* Returns true if the pathname matches one of the exclude patterns.
*
* @param {string} pathname Path of file or directory
* @param {string} patterns Glob expressions
*/
export const checkPathExcludePattern = (pathname, patterns) => {
if (!pathname || typeof pathname !== 'string') return false
for (const pattern of patterns) {
if (minimatch(pathname, pattern, { matchBase: true })) {
return true
}
}
return false
}

View File

@ -3,7 +3,7 @@ import fsPromises from 'fs/promises'
import log from 'electron-log'
import chokidar from 'chokidar'
import { exists } from 'common/filesystem'
import { hasMarkdownExtension } from 'common/filesystem/paths'
import { hasMarkdownExtension, checkPathExcludePattern } from 'common/filesystem/paths'
import { getUniqueId } from '../utils'
import { loadMarkdownFile } from '../filesystem/markdown'
import { isLinux, isOsx } from '../config'
@ -159,6 +159,10 @@ class Watcher {
if (/(?:^|[/\\])(?:\..|node_modules|(?:.+\.asar))/.test(pathname)) {
return true
}
if (checkPathExcludePattern(pathname, this._preferences.getItem('treePathExcludePatterns'))) {
return true
}
if (fileInfo.isDirectory()) {
return false
}

View File

@ -71,6 +71,14 @@
:onChange="value => onSelectChange('wordWrapInToc', value)"
></bool>
<text-box description='Patterns to exclude directorys or files'
notes='Glob Patterns, Use "," to separate multiple pattern. Requires restart.'
:input="projectPaths"
:defaultValue="treePathExcludePatterns"
:onChange="value => onSelectChange('treePathExcludePatterns', value.split(','))"
more="https://github.com/isaacs/minimatch"
></text-box>
<!-- TODO: The description is very bad and the entry isn't used by the editor. -->
<cur-select
description="Sort field for files in open folders"
@ -125,6 +133,7 @@ import Range from '../common/range'
import CurSelect from '../common/select'
import Bool from '../common/bool'
import Separator from '../common/separator'
import textBox from '../common/textBox'
import { isOsx } from '@/util'
import {
@ -140,7 +149,8 @@ export default {
Bool,
Range,
CurSelect,
Separator
Separator,
textBox
},
data () {
this.titleBarStyleOptions = titleBarStyleOptions
@ -158,6 +168,7 @@ export default {
defaultDirectoryToOpen: state => state.preferences.defaultDirectoryToOpen,
openFilesInNewWindow: state => state.preferences.openFilesInNewWindow,
openFolderInNewWindow: state => state.preferences.openFolderInNewWindow,
projectPaths: state => state.preferences.treePathExcludePatterns,
zoom: state => state.preferences.zoom,
hideScrollbar: state => state.preferences.hideScrollbar,
wordWrapInToc: state => state.preferences.wordWrapInToc,

View File

@ -14,6 +14,7 @@ const state = {
fileSortBy: 'created',
startUpAction: 'lastState',
defaultDirectoryToOpen: '',
treePathExcludePatterns: [],
language: 'en',
editorFontFamily: 'Open Sans',

View File

@ -10,6 +10,7 @@
"fileSortBy": "created",
"startUpAction": "lastState",
"defaultDirectoryToOpen": "",
"treePathExcludePatterns": [],
"language": "en",
"editorFontFamily": "Open Sans",