Changeset 80347 in webkit


Ignore:
Timestamp:
Mar 4, 2011 6:40:54 AM (13 years ago)
Author:
podivilov@chromium.org
Message:

2011-03-04 Andrey Adaikin <aandrey@google.com>

Reviewed by Pavel Feldman.

Web Inspector: [Text editor] Do bisect to find visible chunks
https://bugs.webkit.org/show_bug.cgi?id=55685

  • inspector/front-end/TextViewer.js: (WebInspector.TextEditorChunkedPanel.prototype._chunkNumberForLine): (WebInspector.TextEditorChunkedPanel.prototype._findVisibleChunks): (WebInspector.TextEditorChunkedPanel.prototype._repaintAll): (WebInspector.TextEditorGutterChunk.prototype.get offsetTop): (WebInspector.TextEditorMainPanel.prototype._updateHighlightsForRange): (WebInspector.TextEditorMainChunk.prototype.get offsetTop):
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r80346 r80347  
     12011-03-04  Andrey Adaikin  <aandrey@google.com>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: [Text editor] Do bisect to find visible chunks
     6        https://bugs.webkit.org/show_bug.cgi?id=55685
     7
     8        * inspector/front-end/TextViewer.js:
     9        (WebInspector.TextEditorChunkedPanel.prototype._chunkNumberForLine):
     10        (WebInspector.TextEditorChunkedPanel.prototype._findVisibleChunks):
     11        (WebInspector.TextEditorChunkedPanel.prototype._repaintAll):
     12        (WebInspector.TextEditorGutterChunk.prototype.get offsetTop):
     13        (WebInspector.TextEditorMainPanel.prototype._updateHighlightsForRange):
     14        (WebInspector.TextEditorMainChunk.prototype.get offsetTop):
     15
    1162011-03-04  Andrey Adaikin  <aandrey@google.com>
    217
  • trunk/Source/WebCore/inspector/front-end/TextViewer.js

    r80346 r80347  
    388388    _chunkNumberForLine: function(lineNumber)
    389389    {
    390         // Bisect.
    391         var from = 0;
    392         var to = this._textChunks.length - 1;
    393         while (from < to) {
    394             var mid = Math.floor((from + to + 1) / 2);
    395             if (this._textChunks[mid].startLine <= lineNumber)
    396                 from = mid;
    397             else
    398                 to = mid - 1;
    399         }
    400         return from;
     390        function compareLineNumbers(value, chunk)
     391        {
     392            return value < chunk.startLine ? -1 : 1;
     393        }
     394        var insertBefore = insertionIndexForObjectInListSortedByFunction(lineNumber, this._textChunks, compareLineNumbers);
     395        return insertBefore - 1;
    401396    },
    402397
     
    404399    {
    405400        return this._textChunks[this._chunkNumberForLine(lineNumber)];
     401    },
     402
     403    _findVisibleChunks: function(visibleFrom, visibleTo)
     404    {
     405        function compareOffsetTops(value, chunk)
     406        {
     407            return value < chunk.offsetTop ? -1 : 1;
     408        }
     409        var insertBefore = insertionIndexForObjectInListSortedByFunction(visibleFrom, this._textChunks, compareOffsetTops);
     410
     411        var from = insertBefore - 1;
     412        for (var to = from + 1; to < this._textChunks.length; ++to) {
     413            if (this._textChunks[to].offsetTop >= visibleTo)
     414                break;
     415        }
     416        return { start: from, end: to };
    406417    },
    407418
     
    419430        var visibleTo = this.element.scrollTop + this.element.clientHeight;
    420431
    421         var offset = 0;
    422         var fromIndex = -1;
    423         var toIndex = 0;
    424         for (var i = 0; i < this._textChunks.length; ++i) {
    425             var chunk = this._textChunks[i];
    426             var chunkHeight = chunk.height;
    427             if (offset + chunkHeight > visibleFrom && offset < visibleTo) {
    428                 if (fromIndex === -1)
    429                     fromIndex = i;
    430                 toIndex = i + 1;
    431             } else {
    432                 if (offset >= visibleTo)
    433                     break;
    434             }
    435             offset += chunkHeight;
    436         }
    437 
    438         if (toIndex)
    439             this._expandChunks(fromIndex, toIndex);
     432        if (visibleTo) {
     433            var result = this._findVisibleChunks(visibleFrom, visibleTo);
     434            this._expandChunks(result.start, result.end);
     435        }
    440436    },
    441437
     
    651647            return this._textViewer._totalHeight(this.element);
    652648        return this._textViewer._totalHeight(this._expandedLineRows[0], this._expandedLineRows[this._expandedLineRows.length - 1]);
     649    },
     650
     651    get offsetTop()
     652    {
     653        return this._expandedLineRows ? this._expandedLineRows[0].offsetTop : this.element.offsetTop;
    653654    },
    654655
     
    13421343        var visibleTo = this.element.scrollTop + this.element.clientHeight;
    13431344
    1344         var offset = 0;
    1345         var lastVisibleLine = 0;
    1346         for (var i = 0; i < this._textChunks.length; ++i) {
    1347             var chunk = this._textChunks[i];
    1348             var chunkHeight = chunk.height;
    1349             if (offset + chunkHeight > visibleFrom && offset < visibleTo)
    1350                 lastVisibleLine = chunk.startLine + chunk.linesCount;
    1351             else if (offset >= visibleTo)
    1352                 break;
    1353             offset += chunkHeight;
    1354         }
     1345        var result = this._findVisibleChunks(visibleFrom, visibleTo);
     1346        var chunk = this._textChunks[result.end - 1];
     1347        var lastVisibleLine = chunk.startLine + chunk.linesCount;
    13551348
    13561349        lastVisibleLine = Math.max(lastVisibleLine, range.endLine);
     
    15281521    },
    15291522
     1523    get offsetTop()
     1524    {
     1525        return this._expandedLineRows ? this._expandedLineRows[0].offsetTop : this.element.offsetTop;
     1526    },
     1527
    15301528    _createRow: function(lineNumber)
    15311529    {
Note: See TracChangeset for help on using the changeset viewer.