Skip to content

Commit

Permalink
Use natural sorting in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnovak committed Mar 30, 2024
1 parent eaa9937 commit c6048b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Restoring the window size and position on startup is now more robust.
- Idle perfomance has been improved; CPU and GPU utilisation is now close to
zero if there is no user input.
- All sorted items use [natural sort order](https://en.wikipedia.org/wiki/Natural_sort_order) now.
- The user manual has been overhauled for improved wording and clarity.
- Improved status bar messages, dialogs, and more status icons.
- Minor improvements to some of the bundled themes.
Expand Down
14 changes: 8 additions & 6 deletions src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import hocon
import icons
import level
import map
import naturalsort
import persistence
import rect
import selection
Expand Down Expand Up @@ -2405,7 +2406,8 @@ proc buildThemeList(a) =
raise newException(IOError, "Cannot find any themes, exiting")

themeNames.sort(
proc (a, b: ThemeName): int = cmp(a.name, b.name)
proc (a, b: ThemeName): int =
cmpNaturalIgnoreCase(a.name.toRunes, b.name.toRunes)
)

a.theme.themeNames = themeNames
Expand Down Expand Up @@ -7653,8 +7655,7 @@ proc renderRegionDropDown(a) =
mainPane = mainPaneRect(a)

if currRegion.isSome:
var sortedRegionNames = l.regionNames
sort(sortedRegionNames)
var sortedRegionNames = l.regionNames.naturalSort

let currRegionName = currRegion.get.name
var sortedRegionIdx = sortedRegionNames.find(currRegionName)
Expand Down Expand Up @@ -8195,9 +8196,10 @@ func sortByNoteType(x, y: Annotation): int =

func sortByTextAndLocation(locX: Location, x: Annotation,
locY: Location, y: Annotation): int =
var c = cmpIgnoreCase(x.text, y.text); if c != 0: return c
c = cmp(locX.level, locY.level); if c != 0: return c
c = cmp(locX.row, locY.row); if c != 0: return c
var c = cmpNaturalIgnoreCase(x.text.toRunes,
y.text.toRunes); if c != 0: return c
c = cmp(locX.level, locY.level); if c != 0: return c
c = cmp(locX.row, locY.row); if c != 0: return c
return cmp(locX.col, locY.col)

# }}}
Expand Down
8 changes: 6 additions & 2 deletions src/map.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import std/options
import std/sequtils
import std/sets
import std/tables
import std/unicode

import common
import deps/with
import level
import links
import naturalsort
import rect
import regions
import utils
Expand Down Expand Up @@ -49,13 +51,15 @@ proc sortLevels*(m) =
var sortedLevelsWithIndex = zip(m.levels, (0..m.levels.high).toSeq)
sortedLevelsWithIndex.sort(
proc (a, b: tuple[level: Level, idx: int]): int =
var c = cmp(a.level.locationName, b.level.locationName)
var c = cmpNaturalIgnoreCase(a.level.locationName.toRunes,
b.level.locationName.toRunes)
if c != 0: return c

c = cmp(b.level.elevation, a.level.elevation)
if c != 0: return c

return cmp(a.level.levelName, b.level.levelName)
return cmpNaturalIgnoreCase(a.level.levelName.toRunes,
b.level.levelName.toRunes)
)

m.sortedLevelNames = @[]
Expand Down

0 comments on commit c6048b0

Please sign in to comment.