Changeset 46391 in webkit


Ignore:
Timestamp:
Jul 25, 2009 2:44:06 AM (15 years ago)
Author:
oliver@apple.com
Message:

2009-07-24 Joseph Pecoraro <joepeck02@gmail.com>

Reviewed by Oliver Hunt.

Inspector: Properties Should be Sorted more Naturally
https://bugs.webkit.org/show_bug.cgi?id=27329

  • inspector/front-end/ObjectPropertiesSection.js: (WebInspector.ObjectPropertiesSection.prototype.update): use the displaySort when showing properties (WebInspector.ObjectPropertiesSection.prototype._displaySort): alphaNumerical sort (WebInspector.ObjectPropertyTreeElement.prototype.onpopulate): use the displaySort when showing properties
  • inspector/front-end/utilities.js: (Object.sortedProperties): allow for an optional sorting function in Object.sortedProperties
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r46390 r46391  
     12009-07-24  Joseph Pecoraro  <joepeck02@gmail.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Inspector: Properties Should be Sorted more Naturally
     6        https://bugs.webkit.org/show_bug.cgi?id=27329
     7
     8        * inspector/front-end/ObjectPropertiesSection.js:
     9        (WebInspector.ObjectPropertiesSection.prototype.update): use the displaySort when showing properties
     10        (WebInspector.ObjectPropertiesSection.prototype._displaySort): alphaNumerical sort
     11        (WebInspector.ObjectPropertyTreeElement.prototype.onpopulate): use the displaySort when showing properties
     12        * inspector/front-end/utilities.js:
     13        (Object.sortedProperties): allow for an optional sorting function in Object.sortedProperties
     14
    1152009-07-24  Pavel Feldman  <pfeldman@chromium.org>
    216
  • trunk/WebCore/inspector/front-end/ObjectPropertiesSection.js

    r45889 r46391  
    11/*
    22 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
     3 * Copyright (C) 2009 Joseph Pecoraro
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    5960            for (var prop in this.extraProperties)
    6061                properties.push(prop);
    61         properties.sort();
     62        properties.sort(this._displaySort);
    6263
    6364        this.propertiesTreeOutline.removeChildren();
     
    8081            this.propertiesTreeOutline.appendChild(infoElement);
    8182        }
     83    },
     84
     85    _displaySort: function(a,b) {
     86
     87        // if used elsewhere make sure to
     88        //  - convert a and b to strings (not needed here, properties are all strings)
     89        //  - check if a == b (not needed here, no two properties can be the same)
     90
     91        var diff = 0;
     92        var chunk = /^\d+|^\D+/;
     93        var chunka, chunkb, anum, bnum;
     94        while (diff === 0) {
     95            if (!a && b)
     96                return -1;
     97            if (!b && a)
     98                return 1;
     99            chunka = a.match(chunk)[0];
     100            chunkb = b.match(chunk)[0];
     101            anum = !isNaN(chunka);
     102            bnum = !isNaN(chunkb);
     103            if (anum && !bnum)
     104                return -1;
     105            if (bnum && !anum)
     106                return 1;
     107            if (anum && bnum) {
     108                diff = chunka - chunkb;
     109                if (diff === 0 && chunka.length !== chunkb.length) {
     110                    if (!+chunka && !+chunkb) // chunks are strings of all 0s (special case)
     111                        return chunka.length - chunkb.length;
     112                    else
     113                        return chunkb.length - chunka.length;
     114                }
     115            } else if (chunka !== chunkb)
     116                return (chunka < chunkb) ? -1 : 1;
     117            a = a.substring(chunka.length);
     118            b = b.substring(chunkb.length);
     119        }
     120        return diff;
    82121    }
    83122}
     
    110149
    111150        var childObject = this.safePropertyValue(this.parentObject, this.propertyName);
    112         var properties = Object.sortedProperties(childObject);
     151        var properties = Object.sortedProperties(childObject, WebInspector.ObjectPropertiesSection.prototype._displaySort);
    113152        for (var i = 0; i < properties.length; ++i) {
    114153            var propertyName = properties[i];
  • trunk/WebCore/inspector/front-end/utilities.js

    r46345 r46391  
    9595}
    9696
    97 Object.sortedProperties = function(obj)
     97Object.sortedProperties = function(obj, sortFunc)
    9898{
    9999    var properties = [];
    100100    for (var prop in obj)
    101101        properties.push(prop);
    102     properties.sort();
     102    properties.sort(sortFunc);
    103103    return properties;
    104104}
Note: See TracChangeset for help on using the changeset viewer.