Fix #1879 Add .md extension to files created in sidebar if no extension is given (#1886)

* Fix #1879: Add .md extension to files created in sidebar if no extension given.

* Use hasMarkdownExtension function everywhere an extension has to be checked.

Allowed markdown extensions are handeled in several places in different ways. Use the hasMarkdownFunction from common/filesystem/paths.js to allow to easily update the allowed extensions when needed.
This commit is contained in:
Davis Riedel 2020-02-08 10:26:37 +01:00 committed by GitHub
parent 622ff90d58
commit 862324387c
4 changed files with 14 additions and 5 deletions

View File

@ -15,6 +15,8 @@ export const MARKDOWN_EXTENSIONS = [
'txt'
]
export const MARKDOWN_INCLUSIONS = MARKDOWN_EXTENSIONS.map(x => '*.' + x)
export const IMAGE_EXTENSIONS = [
'jpeg',
'jpg',

View File

@ -1,11 +1,10 @@
import path from 'path'
import { ipcRenderer } from 'electron'
import { isChildOfDirectory } from 'common/filesystem/paths'
import { isChildOfDirectory, hasMarkdownExtension, MARKDOWN_INCLUSIONS } from '../../common/filesystem/paths'
import bus from '../bus'
import { delay } from '@/util'
import FileSearcher from '@/node/fileSearcher'
const MD_EXTENSION = /\.(?:markdown|mdown|mkdn|md|mkd|mdwn|mdtxt|mdtext|text|txt)$/i
const SPECIAL_CHARS = /[\[\]\\^$.\|\?\*\+\(\)\/]{1}/g // eslint-disable-line no-useless-escape
// The quick open command
@ -174,11 +173,11 @@ class QuickOpenCommand {
_getInclusions = query => {
// NOTE: This will fail on `foo.m` because we search for `foo.m.md`.
if (MD_EXTENSION.test(query)) {
if (hasMarkdownExtension(query)) {
return [`*${query}`]
}
const inclusions = ['*.markdown', '*.mdown', '*.mkdn', '*.md', '*.mkd', '*.mdwn', '*.mdtxt', '*.mdtext', '*.text', '*.txt']
const inclusions = MARKDOWN_INCLUSIONS
for (let i = 0; i < inclusions.length; ++i) {
inclusions[i] = `*${query}` + inclusions[i]
}

View File

@ -89,6 +89,7 @@ import EmptyIcon from '@/assets/icons/undraw_empty.svg'
import FindCaseIcon from '@/assets/icons/searchIcons/iconCase.svg'
import FindWordIcon from '@/assets/icons/searchIcons/iconWord.svg'
import FindRegexIcon from '@/assets/icons/searchIcons/iconRegex.svg'
import { MARKDOWN_INCLUSIONS } from '../../../common/filesystem/paths'
export default {
data () {
@ -232,7 +233,7 @@ export default {
followSymlinks: this.searchFollowSymlinks,
// Only search markdown files
inclusions: ['*.markdown', '*.mdown', '*.mkdn', '*.md', '*.mkd', '*.mdwn', '*.mdtxt', '*.mdtext', '*.text', '*.txt']
inclusions: MARKDOWN_INCLUSIONS
})
.then(() => {
this.searchResult = newSearchResult

View File

@ -6,6 +6,7 @@ import { create, paste, rename } from '../util/fileSystem'
import { PATH_SEPARATOR } from '../config'
import notice from '../services/notification'
import { getFileStateFromData } from './help'
import { hasMarkdownExtension } from '../../common/filesystem/paths'
const state = {
activeItem: {},
@ -173,7 +174,13 @@ const actions = {
CREATE_FILE_DIRECTORY ({ commit, state }, name) {
const { dirname, type } = state.createCache
if (type === 'file' && !hasMarkdownExtension(name)) {
name += '.md'
}
const fullName = `${dirname}/${name}`
create(fullName, type)
.then(() => {
commit('CREATE_PATH', {})