Web Inspector: CodeMirror still inserts a tab even when "Prefer indent using" is...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 19:32:14 +0000 (19:32 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 19:32:14 +0000 (19:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200770

Reviewed by Ross Kirsling.

* UserInterface/Views/CodeMirrorAdditions.js:
Remap the `insertTab` command to use `insertSoftTab` when "Prefer indent using" is set to
"Spaces" so that CodeMirror inserts the number of spaces that would match a tab ("\t") being
inserted at the same spot.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/CodeMirrorAdditions.js

index c2319b9..7724562 100644 (file)
@@ -1,5 +1,17 @@
 2019-08-15  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: CodeMirror still inserts a tab even when "Prefer indent using" is set to "Spaces"
+        https://bugs.webkit.org/show_bug.cgi?id=200770
+
+        Reviewed by Ross Kirsling.
+
+        * UserInterface/Views/CodeMirrorAdditions.js:
+        Remap the `insertTab` command to use `insertSoftTab` when "Prefer indent using" is set to
+        "Spaces" so that CodeMirror inserts the number of spaces that would match a tab ("\t") being
+        inserted at the same spot.
+
+2019-08-15  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Sources: the "No Filter Results" message sits on top of all of the content, preventing any interaction
         https://bugs.webkit.org/show_bug.cgi?id=200755
 
index 46314a1..8363b40 100644 (file)
         fallthrough: mac ? "macDefault" : "pcDefault"
     };
 
+    {
+        // CodeMirror's default behavior is to always insert a tab ("\t") regardless of `indentWithTabs`.
+        let original = CodeMirror.commands.insertTab;
+        CodeMirror.commands.insertTab = function(cm) {
+            if (cm.options.indentWithTabs)
+                original(cm);
+            else
+                CodeMirror.commands.insertSoftTab(cm);
+        };
+    }
+
     // Register some extra MIME-types for CodeMirror. These are in addition to the
     // ones CodeMirror already registers, like text/html, text/javascript, etc.
     var extraXMLTypes = ["text/xml", "text/xsl"];