Title: [135574] trunk
Revision
135574
Author
[email protected]
Date
2012-11-23 02:14:24 -0800 (Fri, 23 Nov 2012)

Log Message

Web Inspector: ctrl+end in editor does not select the last symbol.
https://bugs.webkit.org/show_bug.cgi?id=103078

Reviewed by Vsevolod Vlasov.

Source/WebCore:

Test: inspector/editor/text-editor-selection.html

* inspector/front-end/DefaultTextEditor.js:
(WebInspector.DefaultTextEditor.prototype._handleScrollChanged):
(WebInspector.DefaultTextEditor.prototype.overrideViewportForTest):
(WebInspector.TextEditorChunkedPanel.prototype._repaintAll):
(WebInspector.TextEditorChunkedPanel.prototype._scrollTop):
(WebInspector.TextEditorChunkedPanel.prototype._clientHeight):
(WebInspector.TextEditorMainPanel.prototype._paintLineChunks):
(WebInspector.TextEditorMainPanel.prototype._selectionToPosition):
(WebInspector.TextEditorMainPanel.prototype._updateHighlightsForRange):

LayoutTests:

* inspector/editor/editor-test.js: Added.
(initialize_EditorTests.InspectorTest.createTestEditor):
(initialize_EditorTests.InspectorTest.dumpEditorChunks):
(initialize_EditorTests):
* inspector/editor/text-editor-selection-expected.txt: Added.
* inspector/editor/text-editor-selection.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (135573 => 135574)


--- trunk/LayoutTests/ChangeLog	2012-11-23 09:57:25 UTC (rev 135573)
+++ trunk/LayoutTests/ChangeLog	2012-11-23 10:14:24 UTC (rev 135574)
@@ -1,3 +1,17 @@
+2012-11-22  Pavel Feldman  <[email protected]>
+
+        Web Inspector: ctrl+end in editor does not select the last symbol.
+        https://bugs.webkit.org/show_bug.cgi?id=103078
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/editor/editor-test.js: Added.
+        (initialize_EditorTests.InspectorTest.createTestEditor):
+        (initialize_EditorTests.InspectorTest.dumpEditorChunks):
+        (initialize_EditorTests):
+        * inspector/editor/text-editor-selection-expected.txt: Added.
+        * inspector/editor/text-editor-selection.html: Added.
+
 2012-11-23  Yury Semikhatsky  <[email protected]>
 
         Unreviewed. Updated test expectations.

Added: trunk/LayoutTests/inspector/editor/editor-test.js (0 => 135574)


--- trunk/LayoutTests/inspector/editor/editor-test.js	                        (rev 0)
+++ trunk/LayoutTests/inspector/editor/editor-test.js	2012-11-23 10:14:24 UTC (rev 135574)
@@ -0,0 +1,24 @@
+function initialize_EditorTests()
+{
+
+InspectorTest.createTestEditor = function(lineCount, clientHeight, chunkSize)
+{
+    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);
+    textModel.setText(lines.join("\n"));
+    return textEditor;
+};
+
+InspectorTest.dumpEditorChunks = function(textEditor)
+{
+    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") + ")");
+};
+
+}
Property changes on: trunk/LayoutTests/inspector/editor/editor-test.js
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/editor/text-editor-selection-expected.txt (0 => 135574)


--- trunk/LayoutTests/inspector/editor/text-editor-selection-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-selection-expected.txt	2012-11-23 10:14:24 UTC (rev 135574)
@@ -0,0 +1,22 @@
+This test checks the text editor selection calculation.
+
+Chunk [0] 0:9 (expanded)
+Chunk [1] 9:18 (collapsed)
+Chunk [2] 18:27 (collapsed)
+Chunk [3] 27:34 (collapsed)
+
+Running: testSelectionAtStartOfCollapsedChunk
+{"startLine":27,"startColumn":0,"endLine":27,"endColumn":0}
+
+Running: testSelectionAtEndOfCollapsedChunk
+{"startLine":33,"startColumn":7,"endLine":33,"endColumn":7}
+
+Running: testSelectionAtMiddleOfCollapsedChunk
+{"startLine":29,"startColumn":4,"endLine":30,"endColumn":6}
+
+Running: testSelectionAtStartAndEndOfExpandedRows
+{"startLine":3,"startColumn":0,"endLine":4,"endColumn":6}
+
+Running: testSelectionAtMiddleOfExpandedRows
+{"startLine":3,"startColumn":3,"endLine":4,"endColumn":4}
+
Property changes on: trunk/LayoutTests/inspector/editor/text-editor-selection-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/inspector/editor/text-editor-selection.html (0 => 135574)


--- trunk/LayoutTests/inspector/editor/text-editor-selection.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/editor/text-editor-selection.html	2012-11-23 10:14:24 UTC (rev 135574)
@@ -0,0 +1,69 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+function test()
+{
+    var textEditor = InspectorTest.createTestEditor(34);
+    InspectorTest.dumpEditorChunks(textEditor);
+
+    InspectorTest.runTestSuite([
+        function testSelectionAtStartOfCollapsedChunk(next)
+        {
+            var chunks = textEditor._mainPanel._textChunks;
+            var lastChunk = chunks[chunks.length - 1];
+            window.getSelection().setBaseAndExtent(lastChunk.element, 0, lastChunk.element, 0);
+            InspectorTest.addResult(textEditor._mainPanel._getSelection());
+            next();
+        },
+
+        function testSelectionAtEndOfCollapsedChunk(next)
+        {
+            var chunks = textEditor._mainPanel._textChunks;
+            var lastChunk = chunks[chunks.length - 1];
+            window.getSelection().setBaseAndExtent(lastChunk.element, 1, lastChunk.element, 1);
+            InspectorTest.addResult(textEditor._mainPanel._getSelection());
+            next();
+        },
+
+        function testSelectionAtMiddleOfCollapsedChunk(next)
+        {
+            var chunks = textEditor._mainPanel._textChunks;
+            var lastChunk = chunks[chunks.length - 1];
+            window.getSelection().setBaseAndExtent(lastChunk.element.firstChild, 20, lastChunk.element.firstChild, 30);
+            InspectorTest.addResult(textEditor._mainPanel._getSelection());
+            next();
+        },
+
+        function testSelectionAtStartAndEndOfExpandedRows(next)
+        {
+            var chunks = textEditor._mainPanel._textChunks;
+            var firstChunk = chunks[0];
+            window.getSelection().setBaseAndExtent(firstChunk.expandedLineRow(3), 0, firstChunk.expandedLineRow(4), 1);
+            InspectorTest.addResult(textEditor._mainPanel._getSelection());
+            next();
+        },
+
+        function testSelectionAtMiddleOfExpandedRows(next)
+        {
+            var chunks = textEditor._mainPanel._textChunks;
+            var firstChunk = chunks[0];
+            window.getSelection().setBaseAndExtent(firstChunk.expandedLineRow(3).firstChild, 3, firstChunk.expandedLineRow(4).firstChild, 4);
+            InspectorTest.addResult(textEditor._mainPanel._getSelection());
+            next();
+        },
+    ]);
+}
+
+</script>
+</head>
+
+<body _onload_="runTest()">
+<p>
+This test checks the text editor selection calculation.
+</p>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/editor/text-editor-selection.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (135573 => 135574)


--- trunk/Source/WebCore/ChangeLog	2012-11-23 09:57:25 UTC (rev 135573)
+++ trunk/Source/WebCore/ChangeLog	2012-11-23 10:14:24 UTC (rev 135574)
@@ -1,3 +1,22 @@
+2012-11-22  Pavel Feldman  <[email protected]>
+
+        Web Inspector: ctrl+end in editor does not select the last symbol.
+        https://bugs.webkit.org/show_bug.cgi?id=103078
+
+        Reviewed by Vsevolod Vlasov.
+
+        Test: inspector/editor/text-editor-selection.html
+
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.DefaultTextEditor.prototype._handleScrollChanged):
+        (WebInspector.DefaultTextEditor.prototype.overrideViewportForTest):
+        (WebInspector.TextEditorChunkedPanel.prototype._repaintAll):
+        (WebInspector.TextEditorChunkedPanel.prototype._scrollTop):
+        (WebInspector.TextEditorChunkedPanel.prototype._clientHeight):
+        (WebInspector.TextEditorMainPanel.prototype._paintLineChunks):
+        (WebInspector.TextEditorMainPanel.prototype._selectionToPosition):
+        (WebInspector.TextEditorMainPanel.prototype._updateHighlightsForRange):
+
 2012-11-23  Yury Semikhatsky  <[email protected]>
 
         Remove references to non-chromium entries from WebCore.gypi

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


--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2012-11-23 09:57:25 UTC (rev 135573)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2012-11-23 10:14:24 UTC (rev 135574)
@@ -455,7 +455,7 @@
 
     _handleScrollChanged: function(event)
     {
-        var visibleFrom = this._mainPanel.element.scrollTop;
+        var visibleFrom = this._mainPanel._scrollTop();
         var firstVisibleLineNumber = this._mainPanel._findFirstVisibleLineNumber(visibleFrom);
         this._delegate.scrollChanged(firstVisibleLineNumber);
     },
@@ -652,6 +652,18 @@
         this._mainPanel.endDomUpdates();
     },
 
+    /**
+     * @param {number} scrollTop
+     * @param {number} clientHeight
+     * @param {number} chunkSize
+     */
+    overrideViewportForTest: function(scrollTop, clientHeight, chunkSize)
+    {
+        this._mainPanel._scrollTopOverrideForTest = scrollTop;
+        this._mainPanel._clientHeightOverrideForTest = clientHeight;
+        this._mainPanel._defaultChunkSize = chunkSize;
+    },
+
     __proto__: WebInspector.View.prototype
 }
 
@@ -922,8 +934,8 @@
         if (this._paintCoalescingLevel)
             return;
 
-        var visibleFrom = this.element.scrollTop;
-        var visibleTo = this.element.scrollTop + this.element.clientHeight;
+        var visibleFrom = this._scrollTop();
+        var visibleTo = visibleFrom + this._clientHeight();
 
         if (visibleTo) {
             var result = this._findVisibleChunks(visibleFrom, visibleTo);
@@ -931,6 +943,16 @@
         }
     },
 
+    _scrollTop: function()
+    {
+        return typeof this._scrollTopOverrideForTest === "number" ? this._scrollTopOverrideForTest : this.element.scrollTop; 
+    },
+
+    _clientHeight: function()
+    {
+        return typeof this._clientHeightOverrideForTest === "number" ? this._clientHeightOverrideForTest : this.element.clientHeight; 
+    },
+
     /**
      * @param {number} fromIndex
      * @param {number} toIndex
@@ -1751,7 +1773,7 @@
     {
         // First, paint visible lines, so that in case of long lines we should start highlighting
         // the visible area immediately, instead of waiting for the lines above the visible area.
-        var visibleFrom = this.element.scrollTop;
+        var visibleFrom = this._scrollTop();
         var firstVisibleLineNumber = this._findFirstVisibleLineNumber(visibleFrom);
 
         var chunk;
@@ -1986,7 +2008,9 @@
         // We reached our container node, traverse within itself until we reach given offset.
         if (node === container && offset) {
             var text = node.textContent;
-            for (var i = 0; i < offset; ++i) {
+            // In case offset == 1 and lineRow is a chunk div, we need to traverse it all.
+            var textOffset = (node._chunk && offset === 1) ? text.length : offset;
+            for (var i = 0; i < textOffset; ++i) {
                 if (text.charAt(i) === "\n") {
                     lineNumber++;
                     column = 0;
@@ -2417,8 +2441,8 @@
      */
     _updateHighlightsForRange: function(range)
     {
-        var visibleFrom = this.element.scrollTop;
-        var visibleTo = this.element.scrollTop + this.element.clientHeight;
+        var visibleFrom = this._scrollTop();
+        var visibleTo = visibleFrom + this._clientHeight();
 
         var result = this._findVisibleChunks(visibleFrom, visibleTo);
         var chunk = this._textChunks[result.end - 1];

Modified: trunk/Source/WebCore/inspector/front-end/TextEditorModel.js (135573 => 135574)


--- trunk/Source/WebCore/inspector/front-end/TextEditorModel.js	2012-11-23 09:57:25 UTC (rev 135573)
+++ trunk/Source/WebCore/inspector/front-end/TextEditorModel.js	2012-11-23 10:14:24 UTC (rev 135574)
@@ -135,6 +135,11 @@
     shift: function(lineOffset)
     {
         return new WebInspector.TextRange(this.startLine + lineOffset, this.startColumn, this.endLine + lineOffset, this.endColumn);
+    },
+
+    toString: function()
+    {
+        return JSON.stringify(this);
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to