Web Inspector: home button behaviour is wrong in DTE
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2013 09:34:16 +0000 (09:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Feb 2013 09:34:16 +0000 (09:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=109154

Patch by Andrey Lushnikov <lushnikov@chromium.org> on 2013-02-11
Reviewed by Vsevolod Vlasov.

Source/WebCore:

Handle home key shortcut explicitly in TextEditorMainPanel.

New test: inspector/editor/text-editor-home-button.html

* inspector/front-end/DefaultTextEditor.js:
(WebInspector.TextEditorMainPanel.prototype._registerShortcuts):
(WebInspector.TextEditorMainPanel.prototype._handleHomeKey):

LayoutTests:

Add layout test to verify home button behaviour. Exclude this test on
platforms that do not have eventSender object in test shell.

* inspector/editor/editor-test.js:
(initialize_EditorTests.lineWithCursor):
(initialize_EditorTests.InspectorTest.textWithSelection): Added helper method to add selection symbols in text.
* inspector/editor/text-editor-home-button-expected.txt: Added.
* inspector/editor/text-editor-home-button.html: Added.
* platform/efl/TestExpectations:
* platform/mac/TestExpectations:
* platform/qt/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@142439 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/editor/editor-test.js
LayoutTests/inspector/editor/text-editor-home-button-expected.txt [new file with mode: 0644]
LayoutTests/inspector/editor/text-editor-home-button.html [new file with mode: 0644]
LayoutTests/platform/efl/TestExpectations
LayoutTests/platform/mac/TestExpectations
LayoutTests/platform/qt/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/DefaultTextEditor.js

index 95970f0ecd40a9a8395ffcf4c3b118f31a77f919..f5848a0e84e3e2187ae011f8cc02fa93e2115967 100644 (file)
@@ -1,3 +1,22 @@
+2013-02-11  Andrey Lushnikov  <lushnikov@chromium.org>
+
+        Web Inspector: home button behaviour is wrong in DTE
+        https://bugs.webkit.org/show_bug.cgi?id=109154
+
+        Reviewed by Vsevolod Vlasov.
+
+        Add layout test to verify home button behaviour. Exclude this test on
+        platforms that do not have eventSender object in test shell.
+
+        * inspector/editor/editor-test.js:
+        (initialize_EditorTests.lineWithCursor):
+        (initialize_EditorTests.InspectorTest.textWithSelection): Added helper method to add selection symbols in text.
+        * inspector/editor/text-editor-home-button-expected.txt: Added.
+        * inspector/editor/text-editor-home-button.html: Added.
+        * platform/efl/TestExpectations:
+        * platform/mac/TestExpectations:
+        * platform/qt/TestExpectations:
+
 2013-02-11  Philippe Normand  <pnormand@igalia.com>
 
         Unreviewed, GTK gardening
index 152313808a46539967275555adf28d534859d173..e54e1b5f9279a02a09dd96c2a261fceef42218a7 100644 (file)
@@ -19,6 +19,26 @@ InspectorTest.fillEditorWithText = function(textEditor, lineCount)
     textModel.setText(lines.join("\n"));
 }
 
+InspectorTest.textWithSelection = function(text, selection)
+{
+    if (!selection)
+        return text;
+
+    function lineWithCursor(line, column, cursorChar)
+    {
+        return line.substring(0, column) + cursorChar + line.substring(column);
+    }
+
+    var lines = text.split("\n");
+    selection = selection.normalize();
+    var endCursorChar = selection.isEmpty() ? "|" : "<";
+    lines[selection.endLine] = lineWithCursor(lines[selection.endLine], selection.endColumn, endCursorChar);
+    if (!selection.isEmpty()) {
+        lines[selection.startLine] = lineWithCursor(lines[selection.startLine], selection.startColumn, ">");
+    }
+    return lines.join("\n");
+}
+
 InspectorTest.insertTextLine = function(line)
 {
     function enter()
diff --git a/LayoutTests/inspector/editor/text-editor-home-button-expected.txt b/LayoutTests/inspector/editor/text-editor-home-button-expected.txt
new file mode 100644 (file)
index 0000000..acb3e0d
--- /dev/null
@@ -0,0 +1,95 @@
+This test verifies that home button triggers selection between first symbol of the line and first non-blank symbol of the line.
+
+function foo()
+{
+    return 42;
+}
+
+Running: testFirstNonBlankCharacter
+function foo()
+{
+    retu|rn 42;
+}
+function foo()
+{
+    |return 42;
+}
+
+Running: testFirstNonBlankCharacterFromWhitespace
+function foo()
+{
+  |  return 42;
+}
+function foo()
+{
+    |return 42;
+}
+
+Running: testHomeButtonToggling
+function foo()
+{
+  |  return 42;
+}
+function foo()
+{
+    |return 42;
+}
+function foo()
+{
+|    return 42;
+}
+function foo()
+{
+    |return 42;
+}
+
+Running: testHomeButtonDoesNotChangeCursor
+fu|nction foo()
+{
+    return 42;
+}
+|function foo()
+{
+    return 42;
+}
+|function foo()
+{
+    return 42;
+}
+
+Running: testHomeButtonWithShift
+>function foo()
+{
+    retu<rn 42;
+}
+>function foo()
+{
+    <return 42;
+}
+>function foo()
+{
+<    return 42;
+}
+>function foo()
+{
+    <return 42;
+}
+
+Running: testHomeButtonWithShiftInversed
+function foo()
+{
+    retu>rn 42;
+}<
+function foo()
+{
+    >return 42;
+}<
+function foo()
+{
+>    return 42;
+}<
+function foo()
+{
+    >return 42;
+}<
+
diff --git a/LayoutTests/inspector/editor/text-editor-home-button.html b/LayoutTests/inspector/editor/text-editor-home-button.html
new file mode 100644 (file)
index 0000000..bb61ccb
--- /dev/null
@@ -0,0 +1,124 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="editor-test.js"></script>
+<script>
+
+function test()
+{
+function foo()
+{
+    return 42;
+}
+    var textEditor = InspectorTest.createTestEditor();
+    textEditor.overrideViewportForTest(0, undefined, 3);
+    textEditor.mimeType = "text/javascript";
+    textEditor.setReadOnly(false);
+    textEditor.element.focus();
+
+    textEditor.setText(foo.toString());
+
+    InspectorTest.addResult(textEditor.text());
+
+    function dumpTextEditorWithSelection()
+    {
+        InspectorTest.addResult(InspectorTest.textWithSelection(textEditor.text(), textEditor.selection()));
+    }
+
+    function homeButton(shift)
+    {
+        var key = WebInspector.isMac() ? "leftArrow" : "home";
+        var modifiers = WebInspector.isMac() ? ["metaKey"] : [];
+        if (shift)
+            modifiers.push("shiftKey");
+        eventSender.keyDown(key, modifiers);
+    }
+
+    InspectorTest.runTestSuite([
+        function testFirstNonBlankCharacter(next)
+        {
+            var selection = WebInspector.TextRange.createFromLocation(2, 8);
+            textEditor.setSelection(selection);
+            dumpTextEditorWithSelection();
+            homeButton(false);
+            dumpTextEditorWithSelection();
+            next();
+        },
+
+        function testFirstNonBlankCharacterFromWhitespace(next)
+        {
+            var selection = WebInspector.TextRange.createFromLocation(2, 2);
+            textEditor.setSelection(selection);
+            dumpTextEditorWithSelection();
+            homeButton(false);
+            dumpTextEditorWithSelection();
+            next();
+        },
+
+        function testHomeButtonToggling(next)
+        {
+            var selection = WebInspector.TextRange.createFromLocation(2, 2);
+            textEditor.setSelection(selection);
+            dumpTextEditorWithSelection();
+            homeButton(false);
+            dumpTextEditorWithSelection();
+            homeButton(false);
+            dumpTextEditorWithSelection();
+            homeButton(false);
+            dumpTextEditorWithSelection();
+            next();
+        },
+
+        function testHomeButtonDoesNotChangeCursor(next)
+        {
+            var selection = WebInspector.TextRange.createFromLocation(0, 2);
+            textEditor.setSelection(selection);
+            dumpTextEditorWithSelection();
+            homeButton(false);
+            dumpTextEditorWithSelection();
+            homeButton(false);
+            dumpTextEditorWithSelection();
+            next();
+        },
+
+        function testHomeButtonWithShift(next)
+        {
+            var selection = new WebInspector.TextRange(0, 0, 2, 8);
+            textEditor.setSelection(selection);
+            dumpTextEditorWithSelection();
+            homeButton(true);
+            dumpTextEditorWithSelection();
+            homeButton(true);
+            dumpTextEditorWithSelection();
+            homeButton(true);
+            dumpTextEditorWithSelection();
+            next();
+        },
+
+        function testHomeButtonWithShiftInversed(next)
+        {
+            var selection = new WebInspector.TextRange(3, 1, 2, 8);
+            textEditor.setSelection(selection);
+            dumpTextEditorWithSelection();
+            homeButton(true);
+            dumpTextEditorWithSelection();
+            homeButton(true);
+            dumpTextEditorWithSelection();
+            homeButton(true);
+            dumpTextEditorWithSelection();
+            next();
+        }
+    ]);
+}
+
+</script>
+</head>
+
+<body onload="runTest();">
+<p>
+This test verifies that home button triggers selection between first symbol of the line
+and first non-blank symbol of the line.
+</p>
+
+</body>
+</html>
index a3fa8bc70455dbfaafab154712069fa917bbb51c..b7d4139b11dfa5a60cd39f68c4c2242bf018451d 100644 (file)
@@ -1835,6 +1835,7 @@ webkit.org/b/106743 media/video-controls-captions.html [ Failure ]
 # https://bugs.webkit.org/show_bug.cgi?id=106883
 inspector/editor/text-editor-formatter.html
 inspector/editor/text-editor-word-jumps.html
+inspector/editor/text-editor-home-button.html
 
 # Remove from list after enabling CANVAS_PATH
 webkit.org/b/108508 fast/canvas/canvas-path-constructors.html [ Failure ]
index 44f75472ca3ecf58024d1b600f08f78e3d0da085..748fe093baa1d03bb084116c9d44ce94950f9116 100644 (file)
@@ -254,6 +254,7 @@ animations/play-state.html
 # https://bugs.webkit.org/show_bug.cgi?id=106793
 inspector/editor/text-editor-formatter.html [ Skip ]
 inspector/editor/text-editor-word-jumps.html [ Skip ]
+inspector/editor/text-editor-home-button.html [ Skip ]
 
 # https://bugs.webkit.org/show_bug.cgi?id=71120
 inspector/debugger/selected-call-frame-after-formatting-source.html
index 801ead0723d03407896444ecb2e95a405dd5dd6f..481b27e9a7148544f4e00272c8fd5a4b0f6e4b1a 100644 (file)
@@ -2603,6 +2603,7 @@ webkit.org/b/39725 fast/events/drag-and-drop-autoscroll.html [ Skip ]
 # https://bugs.webkit.org/show_bug.cgi?id=106883
 inspector/editor/text-editor-formatter.html
 inspector/editor/text-editor-word-jumps.html
+inspector/editor/text-editor-home-button.html
 
 # [Qt] REGRESSION(r141634) test failing
 webkit.org/b/108813 compositing/visibility/visibility-image-layers-dynamic.html [ Skip ]
index 5dde9271ddd085382b7f0588f4137dad70f8a69a..b158a76932b96b89c0daf17a2003cc9de55cbcd8 100644 (file)
@@ -1,3 +1,18 @@
+2013-02-11  Andrey Lushnikov  <lushnikov@chromium.org>
+
+        Web Inspector: home button behaviour is wrong in DTE
+        https://bugs.webkit.org/show_bug.cgi?id=109154
+
+        Reviewed by Vsevolod Vlasov.
+
+        Handle home key shortcut explicitly in TextEditorMainPanel.
+
+        New test: inspector/editor/text-editor-home-button.html
+
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.TextEditorMainPanel.prototype._registerShortcuts):
+        (WebInspector.TextEditorMainPanel.prototype._handleHomeKey):
+
 2013-02-11  Abhishek Arya  <inferno@chromium.org>
 
         Add ASSERT_WITH_SECURITY_IMPLICATION to detect out of bounds access
index 70dff34e0527820b4d70138d4c22367d5e887450..6a42da4f3a83675200a536e33f8559f179949630 100644 (file)
@@ -1408,6 +1408,37 @@ WebInspector.TextEditorMainPanel.prototype = {
         var handleShiftTabKey = this._handleTabKeyPress.bind(this, true);
         this._shortcuts[WebInspector.KeyboardShortcut.makeKey(keys.Tab.code)] = handleTabKey;
         this._shortcuts[WebInspector.KeyboardShortcut.makeKey(keys.Tab.code, modifiers.Shift)] = handleShiftTabKey;
+
+        var homeKey = WebInspector.isMac() ? keys.Right : keys.Home;
+        var homeModifier = WebInspector.isMac() ? modifiers.Meta : modifiers.None;
+        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(homeKey.code, homeModifier)] = this._handleHomeKey.bind(this, false);
+        this._shortcuts[WebInspector.KeyboardShortcut.makeKey(homeKey.code, homeModifier | modifiers.Shift)] = this._handleHomeKey.bind(this, true);
+    },
+
+    /**
+     * @param {boolean} shift
+     */
+    _handleHomeKey: function(shift)
+    {
+        var selection = this.selection();
+
+        var line = this._textModel.line(selection.endLine);
+        var firstNonBlankCharacter = 0;
+        while (firstNonBlankCharacter < line.length) {
+            var char = line.charAt(firstNonBlankCharacter);
+            if (char === " " || char === "\t")
+                ++firstNonBlankCharacter;
+            else
+                break;
+        }
+        if (firstNonBlankCharacter >= line.length || selection.endColumn === firstNonBlankCharacter)
+            return false;
+
+        selection.endColumn = firstNonBlankCharacter;
+        if (!shift)
+            selection = selection.collapseToEnd();
+        this._restoreSelection(selection);
+        return true;
     },
 
     _handleShowWhitespaceInEditorChange: function()