Skip to content

Commit

Permalink
[tree-view] Use common comparator function by sort methods
Browse files Browse the repository at this point in the history
  • Loading branch information
asiloisad committed Jan 14, 2025
1 parent 89a13e1 commit 2428d28
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/tree-view/lib/directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class Directory {
} catch (error) {
names = []
}
names.sort(new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'}).compare)
names.sort(this.compareEntries)

const files = []
const directories = []
Expand Down Expand Up @@ -335,16 +335,12 @@ class Directory {
return this.sortEntries(directories.concat(files))
}

normalizeEntryName(value) {
let normalizedValue = value.name
if (normalizedValue == null) {
normalizedValue = value
}
compareEntries(firstName, secondName) {
return compareFn(firstName, secondName)
}

if (normalizedValue != null) {
normalizedValue = normalizedValue.toLowerCase()
}
return normalizedValue
normalizeEntryName(value) {
return value.name ? value.name : value
}

sortEntries(combinedEntries) {
Expand All @@ -354,7 +350,7 @@ class Directory {
return combinedEntries.sort((first, second) => {
const firstName = this.normalizeEntryName(first)
const secondName = this.normalizeEntryName(second)
return firstName.localeCompare(secondName)
return this.compareEntries(firstName, secondName)
})
}
}
Expand Down Expand Up @@ -461,3 +457,5 @@ class Directory {
return this.path === dirname
}
}

const compareFn = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'}).compare

0 comments on commit 2428d28

Please sign in to comment.