fix: #438 to sort files in folder (#1005)

* fix: #438 to sort files in folder

* Change to use localeCompare as per review
This commit is contained in:
Ken Chen 2019-05-05 23:23:01 +08:00 committed by Felix Häusler
parent 230c90c920
commit 68be52a87d
3 changed files with 13 additions and 2 deletions

View File

@ -141,6 +141,7 @@ foo<section>bar</section>zar
- Mark Text didn't remove highlight when I delete the markdown symbol like * or `. (#893)
- After delete ``` at the beginning to paragraph by backspace, then type other text foo, the color will be strange, if you type 1. bar. error happened. (#892)
- Fix highlight error in code block (#545 #890)
- Fix files sorting in folder (#438)
### 0.13.65

View File

@ -28,7 +28,9 @@ const getters = {
}
if (state.projectTree) travel(state.projectTree)
return files.sort()
files.sort((f1, f2) => f1.name.localeCompare(f2.name))
return files
}
}

View File

@ -56,7 +56,15 @@ export const addFile = (tree, file) => {
// Add file to related directory
if (!currentFolder.files.find(f => f.name === name)) {
file.id = getUniqueId()
currentFolder.files.push(file)
const idx = currentFolder.files.findIndex(f => {
return f.name.localeCompare(name) > 0
})
if (idx !== -1) {
currentFolder.files.splice(idx, 0, file)
} else {
currentFolder.files.push(file)
}
}
}