From 81ec34218b8891d04f464d372f0f307ad234e114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garc=C3=ADa?= Date: Sun, 15 Oct 2017 11:30:20 -0400 Subject: [PATCH 1/2] cherry picked array object sort --- lib/context/context-view.coffee | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/context/context-view.coffee b/lib/context/context-view.coffee index 2f5edf6..25e9b7c 100644 --- a/lib/context/context-view.coffee +++ b/lib/context/context-view.coffee @@ -20,4 +20,23 @@ class ContextView extends View openChildren = true break + cbDeepNaturalSort = (a,b) -> + aIsNumeric = /^\d+$/.test(a.name) + bIsNumeric = /^\d+$/.test(b.name) + # cannot exist two equal keys, so skip case of returning 0 + if aIsNumeric && bIsNumeric # order numbers + return if (parseInt(a.name, 10) < parseInt(b.name, 10)) then -1 else 1 + else if !aIsNumeric && !bIsNumeric # order strings + return if (a.name < b.name) then -1 else 1 + else # string first (same behavior that PHP's `ksort`) + return if aIsNumeric then 1 else -1 + + fnWalkVar = (contextVar) -> + if Array.isArray(contextVar) + for item in contextVar + if Array.isArray(item.value) + fnWalkVar(item.value) + contextVar.sort(cbDeepNaturalSort) + + fnWalkVar(@context.context.variables) @contextListView.append(new ContextVariableListView( {name: @context.name, summary: null, variables: @context.context.variables, autoopen: openChildren, openpaths:@autoopen, parent:null})) From e8762ea2d16167a5329a2ada25afae4aa1e338d8 Mon Sep 17 00:00:00 2001 From: "David St.Amour" Date: Sun, 15 Oct 2017 12:01:03 -0400 Subject: [PATCH 2/2] put array sort behind feature flag --- lib/context/context-view.coffee | 4 ++-- lib/php-debug.coffee | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/context/context-view.coffee b/lib/context/context-view.coffee index 25e9b7c..791e87b 100644 --- a/lib/context/context-view.coffee +++ b/lib/context/context-view.coffee @@ -37,6 +37,6 @@ class ContextView extends View if Array.isArray(item.value) fnWalkVar(item.value) contextVar.sort(cbDeepNaturalSort) - - fnWalkVar(@context.context.variables) + if (atom.config.get('php-debug.SortArray')) + fnWalkVar(@context.context.variables) @contextListView.append(new ContextVariableListView( {name: @context.name, summary: null, variables: @context.context.variables, autoopen: openChildren, openpaths:@autoopen, parent:null})) diff --git a/lib/php-debug.coffee b/lib/php-debug.coffee index d255c7b..db1ea7d 100644 --- a/lib/php-debug.coffee +++ b/lib/php-debug.coffee @@ -135,6 +135,10 @@ module.exports = PhpDebug = UnknownError: type: 'boolean' default: true + SortArray: + title: "Sort Array/Object Elements Alphabetically" + type: 'boolean' + default: true activate: (state) -> if state @@ -318,7 +322,7 @@ module.exports = PhpDebug = atom.focus() @GlobalContext.getCurrentDebugContext().syncCurrentContext(point.getStackDepth()) - + addBreakpointMarker: (line, editor) -> gutter = editor.gutterWithName("php-debug-gutter") range = [[line-1, 0], [line-1, 0]]