Web Inspector: Indenting fully selected line should not indent the line next to it
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2012 06:17:48 +0000 (06:17 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Mar 2012 06:17:48 +0000 (06:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=81758

Source/WebCore:

In the editor, you can select a whole line by moving caret at 0 column
position and pressing Shift + Arrow Down/Up. After that, pressing Tab
indents 2 lines: fully selected one and the line next to it. The patch
changes this behaviour to indent only fully selected line since that is
what pretty-match all the other code editors do.

Patch by Nikita Vasilyev <me@elv1s.ru> on 2012-03-25
Reviewed by Pavel Feldman.

Test: inspector/editor/indentation.html

* inspector/front-end/TextViewer.js:
(WebInspector.TextEditorMainPanel.prototype._indentLines):
    Do not insert indent at the begging of the last line if a selection
    ends on its 0 column.
(WebInspector.TextEditorMainPanel.prototype._unindentLines):
    Do not remove indent at the begging of the last line if a selection
    ends on its 0 column.

LayoutTests:

Patch by Nikita Vasilyev <me@elv1s.ru> on 2012-03-25
Reviewed by Pavel Feldman.

* inspector/editor/indentation-expected.txt: Added.
* inspector/editor/indentation.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/editor/indentation-expected.txt [new file with mode: 0644]
LayoutTests/inspector/editor/indentation.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/TextViewer.js

index 12cbdb6..0aac6e5 100644 (file)
@@ -1,3 +1,13 @@
+2012-03-25  Nikita Vasilyev  <me@elv1s.ru>
+
+        Web Inspector: Indenting fully selected line should not indent the line next to it
+        https://bugs.webkit.org/show_bug.cgi?id=81758
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/editor/indentation-expected.txt: Added.
+        * inspector/editor/indentation.html: Added.
+
 2012-03-25  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [Qt] Unreviewed morning gardening after r112023.
diff --git a/LayoutTests/inspector/editor/indentation-expected.txt b/LayoutTests/inspector/editor/indentation-expected.txt
new file mode 100644 (file)
index 0000000..28b16c0
--- /dev/null
@@ -0,0 +1,27 @@
+This test checks code indentation and unindentation of several lines of code.
+
+After indenting first fully selected line
+    /*
+ * a comment
+ */
+Selection 0,0 1,0
+
+After indenting first partially selected line
+        /*
+ * a comment
+ */
+Selection 0,9 1,0
+
+After unindenting two fully selected lines
+    /*
+* a comment
+ */
+Selection 0,0 2,0
+
+After unindenting three partially selected lines
+/*
+* a comment
+*/
+Selection 0,0 2,2
+
+
diff --git a/LayoutTests/inspector/editor/indentation.html b/LayoutTests/inspector/editor/indentation.html
new file mode 100644 (file)
index 0000000..2c44953
--- /dev/null
@@ -0,0 +1,47 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="highlighter-test.js"></script>
+<script>
+function test()
+{
+    var src = "/*\n" +
+        " * a comment\n" +
+        " */";
+
+    var model = new WebInspector.TextEditorModel();
+    model.setText(null, src);
+    function noop() {}
+    var textEditorMainPanel = new WebInspector.TextEditorMainPanel(model, '', noop, noop, noop, noop);
+
+    var selection;
+    function dumpTextModel(msg)
+    {
+        InspectorTest.addResult(msg);
+        InspectorTest.addResult(model.text);
+        InspectorTest.addResult('Selection ' + selection.startLine + ',' + selection.startColumn  + ' ' + selection.endLine + ',' + selection.endColumn + '\n');
+    }
+
+    selection = textEditorMainPanel._indentLines(new WebInspector.TextRange(0, 0, 1, 0));
+    dumpTextModel("After indenting first fully selected line");
+
+    selection = textEditorMainPanel._indentLines(new WebInspector.TextRange(0, 5, 1, 0));
+    dumpTextModel("After indenting first partially selected line");
+
+    selection = textEditorMainPanel._unindentLines(new WebInspector.TextRange(0, 0, 2, 0));
+    dumpTextModel("After unindenting two fully selected lines");
+
+    selection = textEditorMainPanel._unindentLines(new WebInspector.TextRange(0, 0, 2, 3));
+    dumpTextModel("After unindenting three partially selected lines");
+
+    InspectorTest.completeTest();
+}
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+This test checks code indentation and unindentation of several lines of code.
+</p>
+</body>
+</html>
index 18bcfe1..b1339dd 100644 (file)
@@ -1,3 +1,26 @@
+2012-03-25  Nikita Vasilyev  <me@elv1s.ru>
+
+        Web Inspector: Indenting fully selected line should not indent the line next to it
+        https://bugs.webkit.org/show_bug.cgi?id=81758
+
+        In the editor, you can select a whole line by moving caret at 0 column
+        position and pressing Shift + Arrow Down/Up. After that, pressing Tab
+        indents 2 lines: fully selected one and the line next to it. The patch
+        changes this behaviour to indent only fully selected line since that is
+        what pretty-match all the other code editors do.
+
+        Reviewed by Pavel Feldman.
+
+        Test: inspector/editor/indentation.html
+
+        * inspector/front-end/TextViewer.js:
+        (WebInspector.TextEditorMainPanel.prototype._indentLines):
+            Do not insert indent at the begging of the last line if a selection
+            ends on its 0 column.
+        (WebInspector.TextEditorMainPanel.prototype._unindentLines):
+            Do not remove indent at the begging of the last line if a selection
+            ends on its 0 column.
+
 2012-03-25  Abhishek Arya  <inferno@chromium.org>
 
         Crash in ContainerNode::resumePostAttachCallbacks.
index afa6a9b..f6024d1 100644 (file)
@@ -1126,12 +1126,21 @@ WebInspector.TextEditorMainPanel.prototype = {
         if (this._lastEditedRange)
             this._textModel.markUndoableState();
 
-        for (var lineNumber = range.startLine; lineNumber <= range.endLine; lineNumber++)
+        var newRange = range.clone();
+
+        // Do not change a selection start position when it is at the beginning of a line
+        if (range.startColumn)
+            newRange.startColumn += indent.length;
+
+        var indentEndLine = range.endLine;
+        if (range.endColumn)
+            newRange.endColumn += indent.length;
+        else
+            indentEndLine--;
+
+        for (var lineNumber = range.startLine; lineNumber <= indentEndLine; lineNumber++)
             this._textModel.setText(new WebInspector.TextRange(lineNumber, 0, lineNumber, 0), indent);
 
-        var newRange = range.clone();
-        newRange.startColumn += indent.length;
-        newRange.endColumn += indent.length;
         this._lastEditedRange = newRange;
 
         return newRange;
@@ -1147,7 +1156,11 @@ WebInspector.TextEditorMainPanel.prototype = {
         var lineIndentRegex = new RegExp("^ {1," + indentLength + "}");
         var newRange = range.clone();
 
-        for (var lineNumber = range.startLine; lineNumber <= range.endLine; lineNumber++) {
+        var indentEndLine = range.endLine;
+        if (!range.endColumn)
+            indentEndLine--;
+
+        for (var lineNumber = range.startLine; lineNumber <= indentEndLine; lineNumber++) {
             var line = this._textModel.line(lineNumber);
             var firstCharacter = line.charAt(0);
             var lineIndentLength;