@ -123,11 +123,16 @@ function loadSubtreeNoteIds(parentNoteId, subtreeNoteIds) {
}
}
function sortNotes ( parentNoteId , customSortBy = 'title' , reverse = false , foldersFirst = false ) {
function sortNotes ( parentNoteId , customSortBy = 'title' , reverse = false , foldersFirst = false , sortNatural = false , sortLocale ) {
if ( ! customSortBy ) {
customSortBy = 'title' ;
}
if ( ! sortLocale ) {
// sortLocale can not be empty string or null value, default value must be set to undefined.
sortLocale = undefined ;
}
sql . transactional ( ( ) => {
const notes = becca . getNote ( parentNoteId ) . getChildNotes ( ) ;
@ -153,7 +158,14 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder
}
function compare ( a , b ) {
return b === null || b === undefined || a < b ? - 1 : 1 ;
if ( ! sortNatural ) {
// alphabetical sort
return b === null || b === undefined || a < b ? - 1 : 1 ;
} else {
// natural sort
return a . localeCompare ( b , sortLocale , { numeric : true , sensitivity : 'base' } ) ;
}
}
const topAEl = fetchValue ( a , 'top' ) ;
@ -224,8 +236,11 @@ function sortNotesIfNeeded(parentNoteId) {
const sortReversed = parentNote . getLabelValue ( 'sortDirection' ) ? . toLowerCase ( ) === "desc" ;
const sortFoldersFirstLabel = parentNote . getLabel ( 'sortFoldersFirst' ) ;
const sortFoldersFirst = sortFoldersFirstLabel && sortFoldersFirstLabel . value . toLowerCase ( ) !== "false" ;
const sortNaturalLabel = parentNote . getLabel ( 'sortNatural' ) ;
const sortNatural = sortNaturalLabel && sortNaturalLabel . value . toLowerCase ( ) !== "false" ;
const sortLocale = parentNote . getLabelValue ( 'sortLocale' ) ;
sortNotes ( parentNoteId , sortedLabel . value , sortReversed , sortFoldersFirst ) ;
sortNotes ( parentNoteId , sortedLabel . value , sortReversed , sortFoldersFirst , sortNatural , sortLocale );
}
/ * *