Title: [135606] trunk
Revision
135606
Author
[email protected]
Date
2012-11-23 07:01:35 -0800 (Fri, 23 Nov 2012)

Log Message

Web Inspector: damaging last chunk does not remove its garbage from DOM
https://bugs.webkit.org/show_bug.cgi?id=103132

Reviewed by Vsevolod Vlasov.

Source/WebCore:

Removing everything between undamaged chunks, not registered chunk rows.

* inspector/front-end/DefaultTextEditor.js:
(WebInspector.TextEditorMainPanel.prototype._insertSpanBefore):
(WebInspector.TextEditorMainPanel.prototype._updateChunksForRanges):
(WebInspector.TextEditorMainChunk.prototype.updateCollapsedLineRow):
(WebInspector.TextEditorMainChunk.prototype.firstElement):
(WebInspector.TextEditorMainChunk.prototype.lastElement):

LayoutTests:

* inspector/editor/editor-test.js:
(initialize_EditorTests.InspectorTest.createTestEditor):
(initialize_EditorTests.InspectorTest.dumpEditorChunks):
(initialize_EditorTests.InspectorTest.dumpEditorModel):
(initialize_EditorTests.InspectorTest.dumpEditorDOM):
(initialize_EditorTests):
* inspector/editor/text-editor-remove-chunks-from-dom-expected.txt: Added.
* inspector/editor/text-editor-remove-chunks-from-dom.html: Added.
* inspector/editor/text-editor-selection-expected.txt:
* inspector/editor/text-editor-selection.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (135605 => 135606)


--- trunk/LayoutTests/ChangeLog	2012-11-23 14:55:46 UTC (rev 135605)
+++ trunk/LayoutTests/ChangeLog	2012-11-23 15:01:35 UTC (rev 135606)
@@ -1,3 +1,21 @@
+2012-11-23  Pavel Feldman  <[email protected]>
+
+        Web Inspector: damaging last chunk does not remove its garbage from DOM
+        https://bugs.webkit.org/show_bug.cgi?id=103132
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/editor/editor-test.js:
+        (initialize_EditorTests.InspectorTest.createTestEditor):
+        (initialize_EditorTests.InspectorTest.dumpEditorChunks):
+        (initialize_EditorTests.InspectorTest.dumpEditorModel):
+        (initialize_EditorTests.InspectorTest.dumpEditorDOM):
+        (initialize_EditorTests):
+        * inspector/editor/text-editor-remove-chunks-from-dom-expected.txt: Added.
+        * inspector/editor/text-editor-remove-chunks-from-dom.html: Added.
+        * inspector/editor/text-editor-selection-expected.txt:
+        * inspector/editor/text-editor-selection.html:
+
 2012-11-23  Kent Tamura  <[email protected]>
 
         Correct input[type=number] value sanitization for user-input

Modified: trunk/LayoutTests/inspector/editor/editor-test.js (135605 => 135606)


--- trunk/LayoutTests/inspector/editor/editor-test.js	2012-11-23 14:55:46 UTC (rev 135605)
+++ trunk/LayoutTests/inspector/editor/editor-test.js	2012-11-23 15:01:35 UTC (rev 135606)
@@ -3,22 +3,51 @@
 
 InspectorTest.createTestEditor = function(lineCount, clientHeight, chunkSize)
 {
+    WebInspector.debugDefaultTextEditor = true;
     var textEditor = new WebInspector.DefaultTextEditor("", new WebInspector.TextEditorDelegate());
     textEditor.overrideViewportForTest(0, clientHeight || 100, chunkSize || 10);
     textEditor.show(WebInspector.inspectorView.element);
     var textModel = textEditor._textModel;
     var lines = [];
     for (var i = 0; i < lineCount; ++i)
-        lines.push("Line " + i);
+        lines.push(i);
     textModel.setText(lines.join("\n"));
     return textEditor;
 };
 
 InspectorTest.dumpEditorChunks = function(textEditor)
 {
+    InspectorTest.addResult("Chunk model");
     var chunks = textEditor._mainPanel._textChunks;
     for (var i = 0; i < chunks.length; ++i)
         InspectorTest.addResult("Chunk [" + i + "] " + chunks[i].startLine + ":" + chunks[i].endLine + " (" + (chunks[i]._expanded ? "expanded" : "collapsed") + ")");
 };
 
+InspectorTest.dumpEditorModel = function(textEditor)
+{
+    InspectorTest.addResult("Text model");
+    var textModel = textEditor._textModel;
+    for (var i = 0; i < textModel.linesCount; ++i) {
+        var prefix = "[" + i + "]";
+        while (prefix.length < 10)
+            prefix += " ";
+        InspectorTest.addResult(prefix + textModel.line(i));
+    }
+};
+
+InspectorTest.dumpEditorDOM = function(textEditor)
+{
+    InspectorTest.addResult("Editor DOM");
+    var element = textEditor._mainPanel._container;
+    for (var node = element.firstChild; node; node = node.nextSibling) {
+        if (node._chunk)
+            var prefix = "[" + node._chunk.startLine + ":" + node._chunk.endLine + "]";
+        else
+            var prefix = "[" + node.lineNumber + "]";
+        while (prefix.length < 10)
+            prefix += " ";
+        InspectorTest.addResult(prefix + node.outerHTML);
+    }
+};
+
 }

Added: trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom-expected.txt (0 => 135606)


--- trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom-expected.txt	2012-11-23 15:01:35 UTC (rev 135606)
@@ -0,0 +1,39 @@
+This test checks how damaged chunks' DOM is removed from the container.
+
+
+Running: testDamageLastChunk
+
+Before editing
+Text model
+[0]       0
+[1]       1
+[2]       2
+[3]       3
+[4]       4
+[5]       
+Editor DOM
+[0]       <div class="webkit-line-content">0</div>
+[1]       <div class="webkit-line-content">1</div>
+[2]       <div class="webkit-line-content">2</div>
+[3]       <div class="webkit-line-content">3</div>
+[4]       <div class="webkit-line-content">4</div>
+[5]       <div class="webkit-line-content"><br></div>
+
+After editing
+Text model
+[0]       0
+[1]       1
+[2]       2
+[3]       3
+[4]       4
+[5]       additional 5
+[6]       
+Editor DOM
+[0]       <div class="webkit-line-content">0</div>
+[1]       <div class="webkit-line-content">1</div>
+[2]       <div class="webkit-line-content">2</div>
+[3]       <div class="webkit-line-content">3</div>
+[4]       <div class="webkit-line-content">4</div>
+[5]       <div class="webkit-line-content">additional 5</div>
+[6]       <div class="webkit-line-content"><br></div>
+
Property changes on: trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom.html (0 => 135606)


--- trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom.html	2012-11-23 15:01:35 UTC (rev 135606)
@@ -0,0 +1,36 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+function test()
+{
+    InspectorTest.runTestSuite([
+        function testDamageLastChunk(next)
+        {
+            var textEditor = InspectorTest.createTestEditor(5);
+            textEditor.setText(textEditor.text() + "\n");
+            InspectorTest.addResult("\nBefore editing");
+            InspectorTest.dumpEditorModel(textEditor);
+            InspectorTest.dumpEditorDOM(textEditor);
+            var textModel = textEditor._textModel;
+            textModel.editRange(new WebInspector.TextRange(5, 0, 5, 0), "additional 5\n");
+            InspectorTest.addResult("\nAfter editing");
+            InspectorTest.dumpEditorModel(textEditor);
+            InspectorTest.dumpEditorDOM(textEditor);
+            next();
+        },
+    ]);
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+This test checks how damaged chunks' DOM is removed from the container.
+</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/editor/text-editor-remove-chunks-from-dom.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/inspector/editor/text-editor-selection-expected.txt (135605 => 135606)


--- trunk/LayoutTests/inspector/editor/text-editor-selection-expected.txt	2012-11-23 14:55:46 UTC (rev 135605)
+++ trunk/LayoutTests/inspector/editor/text-editor-selection-expected.txt	2012-11-23 15:01:35 UTC (rev 135606)
@@ -1,5 +1,6 @@
 This test checks the text editor selection calculation.
 
+Chunk model
 Chunk [0] 0:9 (expanded)
 Chunk [1] 9:18 (collapsed)
 Chunk [2] 18:27 (collapsed)
@@ -9,14 +10,14 @@
 {"startLine":27,"startColumn":0,"endLine":27,"endColumn":0}
 
 Running: testSelectionAtEndOfCollapsedChunk
-{"startLine":33,"startColumn":7,"endLine":33,"endColumn":7}
+{"startLine":33,"startColumn":2,"endLine":33,"endColumn":2}
 
 Running: testSelectionAtMiddleOfCollapsedChunk
-{"startLine":29,"startColumn":4,"endLine":30,"endColumn":6}
+{"startLine":27,"startColumn":1,"endLine":30,"endColumn":2}
 
 Running: testSelectionAtStartAndEndOfExpandedRows
-{"startLine":3,"startColumn":0,"endLine":4,"endColumn":6}
+{"startLine":3,"startColumn":0,"endLine":4,"endColumn":1}
 
 Running: testSelectionAtMiddleOfExpandedRows
-{"startLine":3,"startColumn":3,"endLine":4,"endColumn":4}
+{"startLine":3,"startColumn":1,"endLine":4,"endColumn":1}
 

Modified: trunk/LayoutTests/inspector/editor/text-editor-selection.html (135605 => 135606)


--- trunk/LayoutTests/inspector/editor/text-editor-selection.html	2012-11-23 14:55:46 UTC (rev 135605)
+++ trunk/LayoutTests/inspector/editor/text-editor-selection.html	2012-11-23 15:01:35 UTC (rev 135606)
@@ -32,7 +32,7 @@
         {
             var chunks = textEditor._mainPanel._textChunks;
             var lastChunk = chunks[chunks.length - 1];
-            window.getSelection().setBaseAndExtent(lastChunk.element.firstChild, 20, lastChunk.element.firstChild, 30);
+            window.getSelection().setBaseAndExtent(lastChunk.element.firstChild, 1, lastChunk.element.firstChild, 11);
             InspectorTest.addResult(textEditor._mainPanel._getSelection());
             next();
         },

Modified: trunk/Source/WebCore/ChangeLog (135605 => 135606)


--- trunk/Source/WebCore/ChangeLog	2012-11-23 14:55:46 UTC (rev 135605)
+++ trunk/Source/WebCore/ChangeLog	2012-11-23 15:01:35 UTC (rev 135606)
@@ -1,3 +1,19 @@
+2012-11-23  Pavel Feldman  <[email protected]>
+
+        Web Inspector: damaging last chunk does not remove its garbage from DOM
+        https://bugs.webkit.org/show_bug.cgi?id=103132
+
+        Reviewed by Vsevolod Vlasov.
+
+        Removing everything between undamaged chunks, not registered chunk rows.
+
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.TextEditorMainPanel.prototype._insertSpanBefore):
+        (WebInspector.TextEditorMainPanel.prototype._updateChunksForRanges):
+        (WebInspector.TextEditorMainChunk.prototype.updateCollapsedLineRow):
+        (WebInspector.TextEditorMainChunk.prototype.firstElement):
+        (WebInspector.TextEditorMainChunk.prototype.lastElement):
+
 2012-11-23  Ilya Tikhonovsky  <[email protected]>
 
         RenderLayer minor clean-up: replace raw pointers with OwnPtrs.

Modified: trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js (135605 => 135606)


--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2012-11-23 14:55:46 UTC (rev 135605)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2012-11-23 15:01:35 UTC (rev 135606)
@@ -2076,7 +2076,7 @@
 
         var span = this._cachedSpans.pop() || document.createElement("span");
         span.className = "webkit-" + className;
-        if (false) // For paint debugging.
+        if (WebInspector.FALSE) // For paint debugging.
             span.addStyleClass("debug-fadeout");
         span.textContent = content;
         element.insertBefore(span, oldChild);
@@ -2412,27 +2412,33 @@
                 this._textChunks[chunkNumber].startLine += linesDiff;
         }
 
+        // Remove damaged chunks from DOM and from textChunks model.
+        var lastUndamagedChunk = firstDamagedChunkNumber > 0 ? this._textChunks[firstDamagedChunkNumber - 1] : null;
+        var firstUndamagedChunk = lastDamagedChunkNumber + 1 < this._textChunks.length ? this._textChunks[lastDamagedChunkNumber + 1] : null;
+        var removeDOMFromNode = lastUndamagedChunk ? lastUndamagedChunk.lastElement().nextSibling : this._container.firstChild;
+        var removeDOMToNode = firstUndamagedChunk ? firstUndamagedChunk.firstElement() : null;
+        for (var node = removeDOMFromNode; node && node !== removeDOMToNode; ) {
+            var nodeToRemove = node;
+            node = node.nextSibling;
+            nodeToRemove.remove();
+        }
+        this._textChunks.splice(firstDamagedChunkNumber, lastDamagedChunkNumber - firstDamagedChunkNumber + 1);
+
         // Compute damaged chunks span
         var startLine = firstDamagedChunk.startLine;
         var endLine = lastDamagedChunk.endLine + linesDiff;
+        var lineSpan = endLine - startLine;
 
         // Re-create chunks for damaged area.
-        var insertedChunks = [];
-        var insertionIndex = lastDamagedChunkNumber + 1;
-
-        var lineSpan = endLine - startLine;
+        var insertionIndex = firstDamagedChunkNumber;
         var chunkSize = Math.ceil(lineSpan / Math.ceil(lineSpan / this._defaultChunkSize));
 
         for (var i = startLine; i < endLine; i += chunkSize) {
             var chunk = this._createNewChunk(i, Math.min(endLine, i + chunkSize));
             this._textChunks.splice(insertionIndex++, 0, chunk);
-            this._container.insertBefore(chunk.element, firstDamagedChunk.anchorElement());
+            this._container.insertBefore(chunk.element, removeDOMToNode);
         }
 
-        // Remove damaged chunks from DOM and the chunks list.
-        var removedChunks = this._textChunks.splice(firstDamagedChunkNumber, lastDamagedChunkNumber - firstDamagedChunkNumber + 1);
-        for (var i = 0; i < removedChunks.length; ++i)
-            removedChunks[i].detachFromDOM();
         this._assertDOMMatchesTextModel();
     },
 
@@ -2721,7 +2727,7 @@
         for (var i = this.startLine; i < this.startLine + this.linesCount; ++i)
             lines.push(this._textModel.line(i));
 
-        if (WebInspector.debugDefaultTextEditor)
+        if (WebInspector.FALSE)
             console.log("Rebuilding chunk with " + lines.length + " lines");
 
         this.element.removeChildren();
@@ -2731,19 +2737,14 @@
             this.element.appendChild(document.createElement("br"));
     },
 
-    detachFromDOM: function()
+    firstElement: function()
     {
-        if (this._expandedLineRows) {
-            for (var i = 0; i < this._expandedLineRows.length; ++i)
-                this._expandedLineRows[i].remove();
-            delete this._expandedLineRows;
-        } else
-            this.element.remove();
+        return this._expandedLineRows ? this._expandedLineRows[0] : this.element;
     },
 
-    anchorElement: function()
+    lastElement: function()
     {
-        return this._expandedLineRows ? this._expandedLineRows[0] : this.element;
+        return this._expandedLineRows ? this._expandedLineRows[this._expandedLineRows.length - 1] : this.element;
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to