Skip to content

Commit 5b63bed

Browse files
dredavRokt33r
authored andcommitted
fix issue #2894: sort alphabetical will now parse float values starting at all titles and compare these.
1 parent 12229a1 commit 5b63bed

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

browser/main/NoteList/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,30 @@ const { remote } = require('electron')
2626
const { dialog } = remote
2727
const WP_POST_PATH = '/wp/v2/posts'
2828

29+
const matchStartingTitleNumber = new RegExp('^([0-9]*\.?[0-9]+).*$')
30+
2931
function sortByCreatedAt (a, b) {
3032
return new Date(b.createdAt) - new Date(a.createdAt)
3133
}
3234

3335
function sortByAlphabetical (a, b) {
36+
const matchA = matchStartingTitleNumber.exec(a.title)
37+
const matchB = matchStartingTitleNumber.exec(b.title)
38+
39+
if (matchA && matchA.length === 2 && matchB && matchB.length === 2) {
40+
// Both note titles are starting with a float. We will compare it now.
41+
const floatA = parseFloat(matchA[1])
42+
const floatB = parseFloat(matchB[1])
43+
44+
if (floatA < floatB) {
45+
return -1
46+
} else if (floatA > floatB) {
47+
return 1
48+
}
49+
50+
// The float values are equal. We will compare the full title.
51+
}
52+
3453
return a.title.localeCompare(b.title)
3554
}
3655

0 commit comments

Comments
 (0)