Skip to content

Commit

Permalink
feat: sort the navigation bar dropdown items alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Aug 6, 2021
1 parent b01460f commit d85ecb2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { createSelection, SELECTION_TYPE } from '../../../logic/selection'
import createDebug from 'debug'
import NavigationBarItem from '../../../components/controls/navigationBar/NavigationBarItem.svelte'
import { caseInsensitiveNaturalCompare } from '../../../logic/sort'
const debug = createDebug('jsoneditor:NavigationBar')
Expand Down Expand Up @@ -45,7 +46,12 @@
if (Array.isArray(node)) {
return range(0, node.length)
} else if (isObject(node)) {
return getIn(state, path.concat(STATE_KEYS)) || Object.keys(node)
const keys = getIn(state, path.concat(STATE_KEYS)) || Object.keys(node)
const sortedKeys = keys.slice(0)
sortedKeys.sort(caseInsensitiveNaturalCompare)
return sortedKeys
} else {
// never happens but just for robustness...
return []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
}

&.jse-navigation-bar-arrow {
font-size: $font-size-mono - 10px;
line-height: $font-size-mono - 10px;
// TODO: fix the height of the buttons for real, this is an ugly
// trick to make the buttons have the same height.
// when there is no selection, the navigation bar must have the same
// height as when there is a selection
font-size: $font-size-mono - 8px;
line-height: $font-size-mono - 8px;
padding: $padding-half $padding;

&.open {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/logic/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parseJSONPointerWithArrayIndices } from '../utils/jsonPointer.js'

const diffSequences = diffSequencesExport.default || diffSequencesExport

function caseInsensitiveNaturalCompare(a, b) {
export function caseInsensitiveNaturalCompare(a, b) {
const aLower = typeof a === 'string' ? a.toLowerCase() : a
const bLower = typeof b === 'string' ? b.toLowerCase() : b

Expand Down

0 comments on commit d85ecb2

Please sign in to comment.