Web Inspector: Settings: indent type and size settings aren't respected everywhere
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jun 2019 02:11:17 +0000 (02:11 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jun 2019 02:11:17 +0000 (02:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198804

Reviewed by Timothy Hatcher.

* UserInterface/Views/CodeMirrorEditor.js:
(WI.CodeMirrorEditor.create):
When creating a `CodeMirror` instance, default to using the global `Setting`s as the options.
If an override is specified in `options`, it will take precedence and the `CodeMirror` will
ignore any changes to the `Setting` as well.

* UserInterface/Views/TextEditor.js:
(WI.TextEditor):
(WI.TextEditor.prototype.close): Deleted.

* UserInterface/Views/AuditTestCaseContentView.js:
(WI.AuditTestCaseContentView.prototype.layout):
* UserInterface/Views/BreakpointActionView.js:
(WI.BreakpointActionView.prototype._updateBody):
* UserInterface/Views/ConsolePrompt.js:
(WI.ConsolePrompt):
* UserInterface/Views/ScopeChainDetailsSidebarPanel.js:
(WI.ScopeChainDetailsSidebarPanel.prototype._addWatchExpressionButtonClicked):
Remove overrides that aren't necessary for `CodeMirror` to fit in the container element:
 - `showWhitespaceCharacters`
 - `indentWithTabs`
 - `indentUnit`

* UserInterface/Views/SourceCodeTextEditor.js:
(WI.SourceCodeTextEditor.prototype.close):
* UserInterface/Views/ShaderProgramContentView.js:
(WI.ShaderProgramContentView.prototype.closed): Deleted.
* UserInterface/Views/TextContentView.js:
(WI.TextContentView.prototype.closed): Deleted.
* UserInterface/Views/TextResourceContentView.js:
(WI.TextResourceContentView.prototype.closed):
Delete the logic for removing event listeners from global `Setting`, as it didn't work
anyways, since none of the event listeners were added using a `thisObject`.

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

Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/AuditTestCaseContentView.js
Source/WebInspectorUI/UserInterface/Views/BreakpointActionView.js
Source/WebInspectorUI/UserInterface/Views/CodeMirrorEditor.js
Source/WebInspectorUI/UserInterface/Views/ConsolePrompt.js
Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.js
Source/WebInspectorUI/UserInterface/Views/ShaderProgramContentView.js
Source/WebInspectorUI/UserInterface/Views/SourceCodeTextEditor.js
Source/WebInspectorUI/UserInterface/Views/TextContentView.js
Source/WebInspectorUI/UserInterface/Views/TextEditor.js
Source/WebInspectorUI/UserInterface/Views/TextResourceContentView.js

index 5c0b8ff..615d5c6 100644 (file)
@@ -1,5 +1,46 @@
 2019-06-13  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Settings: indent type and size settings aren't respected everywhere
+        https://bugs.webkit.org/show_bug.cgi?id=198804
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/CodeMirrorEditor.js:
+        (WI.CodeMirrorEditor.create):
+        When creating a `CodeMirror` instance, default to using the global `Setting`s as the options.
+        If an override is specified in `options`, it will take precedence and the `CodeMirror` will
+        ignore any changes to the `Setting` as well.
+
+        * UserInterface/Views/TextEditor.js:
+        (WI.TextEditor):
+        (WI.TextEditor.prototype.close): Deleted.
+
+        * UserInterface/Views/AuditTestCaseContentView.js:
+        (WI.AuditTestCaseContentView.prototype.layout):
+        * UserInterface/Views/BreakpointActionView.js:
+        (WI.BreakpointActionView.prototype._updateBody):
+        * UserInterface/Views/ConsolePrompt.js:
+        (WI.ConsolePrompt):
+        * UserInterface/Views/ScopeChainDetailsSidebarPanel.js:
+        (WI.ScopeChainDetailsSidebarPanel.prototype._addWatchExpressionButtonClicked):
+        Remove overrides that aren't necessary for `CodeMirror` to fit in the container element:
+         - `showWhitespaceCharacters`
+         - `indentWithTabs`
+         - `indentUnit`
+
+        * UserInterface/Views/SourceCodeTextEditor.js:
+        (WI.SourceCodeTextEditor.prototype.close):
+        * UserInterface/Views/ShaderProgramContentView.js:
+        (WI.ShaderProgramContentView.prototype.closed): Deleted.
+        * UserInterface/Views/TextContentView.js:
+        (WI.TextContentView.prototype.closed): Deleted.
+        * UserInterface/Views/TextResourceContentView.js:
+        (WI.TextResourceContentView.prototype.closed):
+        Delete the logic for removing event listeners from global `Setting`, as it didn't work
+        anyways, since none of the event listeners were added using a `thisObject`.
+
+2019-06-13  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: Settings: sticky header disappears when over scrolling
         https://bugs.webkit.org/show_bug.cgi?id=198833
 
index 48686cd..1680288 100644 (file)
@@ -217,7 +217,6 @@ WI.AuditTestCaseContentView = class AuditTestCaseContentView extends WI.AuditTes
                         mode: "css",
                         readOnly: true,
                         lineWrapping: true,
-                        showWhitespaceCharacters: WI.settings.showWhitespaceCharacters.value,
                         styleSelectedText: true,
                     });
                     codeMirror.setValue(domNode);
index 86e260a..35ae795 100644 (file)
@@ -158,8 +158,6 @@ WI.BreakpointActionView = class BreakpointActionView extends WI.Object
             this._codeMirror = WI.CodeMirrorEditor.create(editorElement, {
                 lineWrapping: true,
                 mode: "text/javascript",
-                indentWithTabs: true,
-                indentUnit: 4,
                 matchBrackets: true,
                 value: this._action.data || "",
             });
index f453cc7..e445dd3 100644 (file)
@@ -33,7 +33,29 @@ WI.CodeMirrorEditor = class CodeMirrorEditor
         element.setAttribute("dir", "ltr");
         element.classList.toggle("read-only", options.readOnly);
 
-        let codeMirror = new CodeMirror(element, options);
+        let codeMirror = new CodeMirror(element, {
+            // These values will be overridden by any value with the same key in `options`.
+            indentWithTabs: WI.settings.indentWithTabs.value,
+            indentUnit: WI.settings.indentUnit.value,
+            tabSize: WI.settings.tabSize.value,
+            lineWrapping: WI.settings.enableLineWrapping.value,
+            showWhitespaceCharacters: WI.settings.showWhitespaceCharacters.value,
+            ...options,
+        });
+
+        function listenForChange(setting, codeMirrorOption) {
+            if (options[codeMirrorOption] !== undefined)
+                return;
+
+            setting.addEventListener(WI.Setting.Event.Changed, (event) => {
+                codeMirror.setOption(codeMirrorOption, setting.value);
+            });
+        }
+        listenForChange(WI.settings.indentWithTabs, "indentWithTabs");
+        listenForChange(WI.settings.indentUnit, "indentUnit");
+        listenForChange(WI.settings.tabSize, "tabSize");
+        listenForChange(WI.settings.enableLineWrapping, "lineWrapping");
+        listenForChange(WI.settings.showWhitespaceCharacters, "showWhitespaceCharacters");
 
         // Override some Mac specific keybindings.
         if (WI.Platform.name === "mac") {
index 549cab4..80faca6 100644 (file)
@@ -40,8 +40,6 @@ WI.ConsolePrompt = class ConsolePrompt extends WI.View
         this._codeMirror = WI.CodeMirrorEditor.create(this.element, {
             lineWrapping: true,
             mode: {name: mimeType, globalVars: true},
-            indentWithTabs: true,
-            indentUnit: 4,
             matchBrackets: true
         });
 
index 226a269..eb2ff6f 100644 (file)
@@ -364,8 +364,6 @@ WI.ScopeChainDetailsSidebarPanel = class ScopeChainDetailsSidebarPanel extends W
         this._codeMirror = WI.CodeMirrorEditor.create(editorElement, {
             lineWrapping: true,
             mode: "text/javascript",
-            indentWithTabs: true,
-            indentUnit: 4,
             matchBrackets: true,
             value: "",
         });
index 7e8da82..dd9254e 100644 (file)
@@ -99,14 +99,6 @@ WI.ShaderProgramContentView = class ShaderProgramContentView extends WI.ContentV
         super.hidden();
     }
 
-    closed()
-    {
-        this._vertexEditor.close();
-        this._fragmentEditor.close();
-
-        super.closed();
-    }
-
     get supportsSave()
     {
         return true;
index 9ee9df4..be8ca15 100644 (file)
@@ -165,8 +165,6 @@ WI.SourceCodeTextEditor = class SourceCodeTextEditor extends WI.TextEditor
 
     close()
     {
-        super.close();
-
         if (this._supportsDebugging) {
             WI.Breakpoint.removeEventListener(null, null, this);
             WI.debuggerManager.removeEventListener(null, null, this);
index 25709b3..37bc503 100644 (file)
@@ -92,13 +92,6 @@ WI.TextContentView = class TextContentView extends WI.ContentView
         this._textEditor.hidden();
     }
 
-    closed()
-    {
-        super.closed();
-
-        this._textEditor.close();
-    }
-
     get supportsSave()
     {
         return true;
index f16ee73..645f979 100644 (file)
@@ -33,37 +33,12 @@ WI.TextEditor = class TextEditor extends WI.View
 
         this._codeMirror = WI.CodeMirrorEditor.create(this.element, {
             readOnly: true,
-            indentWithTabs: WI.settings.indentWithTabs.value,
-            indentUnit: WI.settings.indentUnit.value,
-            tabSize: WI.settings.tabSize.value,
             lineNumbers: true,
-            lineWrapping: WI.settings.enableLineWrapping.value,
             matchBrackets: true,
             autoCloseBrackets: true,
-            showWhitespaceCharacters: WI.settings.showWhitespaceCharacters.value,
             styleSelectedText: true,
         });
 
-        WI.settings.indentWithTabs.addEventListener(WI.Setting.Event.Changed, (event) => {
-            this._codeMirror.setOption("indentWithTabs", WI.settings.indentWithTabs.value);
-        });
-
-        WI.settings.indentUnit.addEventListener(WI.Setting.Event.Changed, (event) => {
-            this._codeMirror.setOption("indentUnit", WI.settings.indentUnit.value);
-        });
-
-        WI.settings.tabSize.addEventListener(WI.Setting.Event.Changed, (event) => {
-            this._codeMirror.setOption("tabSize", WI.settings.tabSize.value);
-        });
-
-        WI.settings.enableLineWrapping.addEventListener(WI.Setting.Event.Changed, (event) => {
-            this._codeMirror.setOption("lineWrapping", WI.settings.enableLineWrapping.value);
-        });
-
-        WI.settings.showWhitespaceCharacters.addEventListener(WI.Setting.Event.Changed, (event) => {
-            this._codeMirror.setOption("showWhitespaceCharacters", WI.settings.showWhitespaceCharacters.value);
-        });
-
         this._codeMirror.on("focus", this._editorFocused.bind(this));
         this._codeMirror.on("change", this._contentChanged.bind(this));
         this._codeMirror.on("gutterClick", this._gutterMouseDown.bind(this));
@@ -587,15 +562,6 @@ WI.TextEditor = class TextEditor extends WI.View
         this._visible = false;
     }
 
-    close()
-    {
-        WI.settings.indentWithTabs.removeEventListener(null, null, this);
-        WI.settings.indentUnit.removeEventListener(null, null, this);
-        WI.settings.tabSize.removeEventListener(null, null, this);
-        WI.settings.enableLineWrapping.removeEventListener(null, null, this);
-        WI.settings.showWhitespaceCharacters.removeEventListener(null, null, this);
-    }
-
     setBreakpointInfoForLineAndColumn(lineNumber, columnNumber, breakpointInfo)
     {
         if (this._ignoreSetBreakpointInfoCalls)
index 49a9b95..2f9f53b 100644 (file)
@@ -127,8 +127,6 @@ WI.TextResourceContentView = class TextResourceContentView extends WI.ResourceCo
         WI.debuggerManager.removeEventListener(null, null, this);
         WI.settings.showJavaScriptTypeInformation.removeEventListener(null, null, this);
         WI.settings.enableControlFlowProfiler.removeEventListener(null, null, this);
-
-        this._textEditor.close();
     }
 
     contentAvailable(content, base64Encoded)