mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 05:59:53 +08:00
Merge 6804c0c37a
into 11c8cc1e19
This commit is contained in:
commit
e31f2fb9ce
@ -1,6 +1,7 @@
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { isFile, isFile2, isSymbolicLink } from './index'
|
import { isFile, isFile2, isSymbolicLink } from './index'
|
||||||
|
import minimatch from 'minimatch'
|
||||||
|
|
||||||
const isOsx = process.platform === 'darwin'
|
const isOsx = process.platform === 'darwin'
|
||||||
|
|
||||||
@ -120,3 +121,19 @@ export const getResourcesPath = () => {
|
|||||||
}
|
}
|
||||||
return resPath
|
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
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@ import fsPromises from 'fs/promises'
|
|||||||
import log from 'electron-log'
|
import log from 'electron-log'
|
||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
import { exists } from 'common/filesystem'
|
import { exists } from 'common/filesystem'
|
||||||
import { hasMarkdownExtension } from 'common/filesystem/paths'
|
import { hasMarkdownExtension, checkPathExcludePattern } from 'common/filesystem/paths'
|
||||||
import { getUniqueId } from '../utils'
|
import { getUniqueId } from '../utils'
|
||||||
import { loadMarkdownFile } from '../filesystem/markdown'
|
import { loadMarkdownFile } from '../filesystem/markdown'
|
||||||
import { isLinux, isOsx } from '../config'
|
import { isLinux, isOsx } from '../config'
|
||||||
@ -159,6 +159,10 @@ class Watcher {
|
|||||||
if (/(?:^|[/\\])(?:\..|node_modules|(?:.+\.asar))/.test(pathname)) {
|
if (/(?:^|[/\\])(?:\..|node_modules|(?:.+\.asar))/.test(pathname)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkPathExcludePattern(pathname, this._preferences.getItem('treePathExcludePatterns'))) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if (fileInfo.isDirectory()) {
|
if (fileInfo.isDirectory()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,14 @@
|
|||||||
:onChange="value => onSelectChange('wordWrapInToc', value)"
|
:onChange="value => onSelectChange('wordWrapInToc', value)"
|
||||||
></bool>
|
></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. -->
|
<!-- TODO: The description is very bad and the entry isn't used by the editor. -->
|
||||||
<cur-select
|
<cur-select
|
||||||
description="Sort field for files in open folders"
|
description="Sort field for files in open folders"
|
||||||
@ -125,6 +133,7 @@ import Range from '../common/range'
|
|||||||
import CurSelect from '../common/select'
|
import CurSelect from '../common/select'
|
||||||
import Bool from '../common/bool'
|
import Bool from '../common/bool'
|
||||||
import Separator from '../common/separator'
|
import Separator from '../common/separator'
|
||||||
|
import textBox from '../common/textBox'
|
||||||
import { isOsx } from '@/util'
|
import { isOsx } from '@/util'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -140,7 +149,8 @@ export default {
|
|||||||
Bool,
|
Bool,
|
||||||
Range,
|
Range,
|
||||||
CurSelect,
|
CurSelect,
|
||||||
Separator
|
Separator,
|
||||||
|
textBox
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
this.titleBarStyleOptions = titleBarStyleOptions
|
this.titleBarStyleOptions = titleBarStyleOptions
|
||||||
@ -158,6 +168,7 @@ export default {
|
|||||||
defaultDirectoryToOpen: state => state.preferences.defaultDirectoryToOpen,
|
defaultDirectoryToOpen: state => state.preferences.defaultDirectoryToOpen,
|
||||||
openFilesInNewWindow: state => state.preferences.openFilesInNewWindow,
|
openFilesInNewWindow: state => state.preferences.openFilesInNewWindow,
|
||||||
openFolderInNewWindow: state => state.preferences.openFolderInNewWindow,
|
openFolderInNewWindow: state => state.preferences.openFolderInNewWindow,
|
||||||
|
projectPaths: state => state.preferences.treePathExcludePatterns,
|
||||||
zoom: state => state.preferences.zoom,
|
zoom: state => state.preferences.zoom,
|
||||||
hideScrollbar: state => state.preferences.hideScrollbar,
|
hideScrollbar: state => state.preferences.hideScrollbar,
|
||||||
wordWrapInToc: state => state.preferences.wordWrapInToc,
|
wordWrapInToc: state => state.preferences.wordWrapInToc,
|
||||||
|
@ -14,6 +14,7 @@ const state = {
|
|||||||
fileSortBy: 'created',
|
fileSortBy: 'created',
|
||||||
startUpAction: 'lastState',
|
startUpAction: 'lastState',
|
||||||
defaultDirectoryToOpen: '',
|
defaultDirectoryToOpen: '',
|
||||||
|
treePathExcludePatterns: [],
|
||||||
language: 'en',
|
language: 'en',
|
||||||
|
|
||||||
editorFontFamily: 'Open Sans',
|
editorFontFamily: 'Open Sans',
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"fileSortBy": "created",
|
"fileSortBy": "created",
|
||||||
"startUpAction": "lastState",
|
"startUpAction": "lastState",
|
||||||
"defaultDirectoryToOpen": "",
|
"defaultDirectoryToOpen": "",
|
||||||
|
"treePathExcludePatterns": [],
|
||||||
"language": "en",
|
"language": "en",
|
||||||
|
|
||||||
"editorFontFamily": "Open Sans",
|
"editorFontFamily": "Open Sans",
|
||||||
|
Loading…
Reference in New Issue
Block a user