Title: [192551] trunk/Source/WebInspectorUI
Revision
192551
Author
mattba...@apple.com
Date
2015-11-17 16:23:56 -0800 (Tue, 17 Nov 2015)

Log Message

Web Inspector: Breakpoint condition field should use CodeMirror
https://bugs.webkit.org/show_bug.cgi?id=151333

Reviewed by Joseph Pecoraro.

Updated breakpoint popover's condition field to use CodeMirror.

* UserInterface/Controllers/BreakpointPopoverController.js:
Removed keyboard shortcuts. Now handled by CodeMirror.
(WebInspector.BreakpointPopoverController.prototype.completionControllerShouldAllowEscapeCompletion):
Prevent handling of escape to allow tabbing to next element.
(WebInspector.BreakpointPopoverController.prototype._createPopoverContent):
Create CodeMirror instance.
(WebInspector.BreakpointPopoverController.prototype._conditionCodeMirrorChanged):
(WebInspector.BreakpointPopoverController.prototype._conditionCodeMirrorBeforeChange):
Enforce single-line editor.
(WebInspector.BreakpointPopoverController.prototype._conditionCodeMirrorEscapeOrEnterKey):
(WebInspector.BreakpointPopoverController): Deleted.
(WebInspector.BreakpointPopoverController.prototype.appendContextMenuItems.editBreakpoint):
Removed condition element select. CodeMirror sets focus when popover content is created.
(WebInspector.BreakpointPopoverController.prototype._popoverConditionInputChanged): Deleted.
Replaced by BreakpointPopoverController.prototype._conditionCodeMirrorChanged.
(WebInspector.BreakpointPopoverController.prototype._popoverConditionInputKeyDown): Deleted.
Replaced by BreakpointPopoverController.prototype._conditionCodeMirrorEscapeOrEnterKey.

* UserInterface/Views/BreakpointPopoverController.css:
(.edit-breakpoint-popover-condition):
(.edit-breakpoint-popover-condition > .CodeMirror):
(#edit-breakpoint-popover-condition): Deleted.
Replace selector id with class, styled CodeMirror element to match original input element.

* UserInterface/Views/CSSStyleDeclarationTextEditor.css:
(.css-style-text-editor > .CodeMirror .CodeMirror-placeholder): Deleted.
Moved common CodeMirror placeholder text style to CodeMirrorOverrides.css.

* UserInterface/Views/CodeMirrorOverrides.css:
(.CodeMirror .CodeMirror-placeholder):
Add placeholder style.

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (192550 => 192551)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-11-18 00:16:56 UTC (rev 192550)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-11-18 00:23:56 UTC (rev 192551)
@@ -1,3 +1,44 @@
+2015-11-17  Matt Baker  <mattba...@apple.com>
+
+        Web Inspector: Breakpoint condition field should use CodeMirror
+        https://bugs.webkit.org/show_bug.cgi?id=151333
+
+        Reviewed by Joseph Pecoraro.
+
+        Updated breakpoint popover's condition field to use CodeMirror.
+
+        * UserInterface/Controllers/BreakpointPopoverController.js:
+        Removed keyboard shortcuts. Now handled by CodeMirror.
+        (WebInspector.BreakpointPopoverController.prototype.completionControllerShouldAllowEscapeCompletion):
+        Prevent handling of escape to allow tabbing to next element.
+        (WebInspector.BreakpointPopoverController.prototype._createPopoverContent):
+        Create CodeMirror instance.
+        (WebInspector.BreakpointPopoverController.prototype._conditionCodeMirrorChanged):
+        (WebInspector.BreakpointPopoverController.prototype._conditionCodeMirrorBeforeChange):
+        Enforce single-line editor.
+        (WebInspector.BreakpointPopoverController.prototype._conditionCodeMirrorEscapeOrEnterKey):
+        (WebInspector.BreakpointPopoverController): Deleted.
+        (WebInspector.BreakpointPopoverController.prototype.appendContextMenuItems.editBreakpoint):
+        Removed condition element select. CodeMirror sets focus when popover content is created.
+        (WebInspector.BreakpointPopoverController.prototype._popoverConditionInputChanged): Deleted.
+        Replaced by BreakpointPopoverController.prototype._conditionCodeMirrorChanged.
+        (WebInspector.BreakpointPopoverController.prototype._popoverConditionInputKeyDown): Deleted.
+        Replaced by BreakpointPopoverController.prototype._conditionCodeMirrorEscapeOrEnterKey.
+
+        * UserInterface/Views/BreakpointPopoverController.css:
+        (.edit-breakpoint-popover-condition):
+        (.edit-breakpoint-popover-condition > .CodeMirror):
+        (#edit-breakpoint-popover-condition): Deleted.
+        Replace selector id with class, styled CodeMirror element to match original input element.
+
+        * UserInterface/Views/CSSStyleDeclarationTextEditor.css:
+        (.css-style-text-editor > .CodeMirror .CodeMirror-placeholder): Deleted.
+        Moved common CodeMirror placeholder text style to CodeMirrorOverrides.css.
+
+        * UserInterface/Views/CodeMirrorOverrides.css:
+        (.CodeMirror .CodeMirror-placeholder):
+        Add placeholder style.
+
 2015-11-12  Matt Baker  <mattba...@apple.com>
 
         Web Inspector: Deleting a probe should remove probe breakpoint actions only.

Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/BreakpointPopoverController.js (192550 => 192551)


--- trunk/Source/WebInspectorUI/UserInterface/Controllers/BreakpointPopoverController.js	2015-11-18 00:16:56 UTC (rev 192550)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/BreakpointPopoverController.js	2015-11-18 00:23:56 UTC (rev 192551)
@@ -32,8 +32,6 @@
         this._breakpoint = null;
         this._popover = null;
         this._popoverContentElement = null;
-        this._keyboardShortcutEsc = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Escape);
-        this._keyboardShortcutEnter = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Enter);
     }
 
     // Public
@@ -55,8 +53,6 @@
             let bounds = WebInspector.Rect.rectFromClientRect(breakpointDisplayElement.getBoundingClientRect());
             bounds.origin.x -= 1; // Move the anchor left one pixel so it looks more centered.
             this._popover.present(bounds.pad(2), [WebInspector.RectEdge.MAX_Y]);
-
-            document.getElementById(WebInspector.BreakpointPopoverController.PopoverConditionInputId).select();
         }
 
         function removeBreakpoint()
@@ -104,6 +100,13 @@
         }
     }
 
+    // CodeMirrorCompletionController delegate
+
+    completionControllerShouldAllowEscapeCompletion()
+    {
+        return false;
+    }
+
     // Private
 
     _createPopoverContent(breakpoint)
@@ -132,16 +135,42 @@
         let conditionHeader = conditionRow.appendChild(document.createElement("th"));
         let conditionData = conditionRow.appendChild(document.createElement("td"));
         let conditionLabel = conditionHeader.appendChild(document.createElement("label"));
-        let conditionInput = conditionData.appendChild(document.createElement("input"));
-        conditionInput.id = WebInspector.BreakpointPopoverController.PopoverConditionInputId;
-        conditionInput.value = this._breakpoint.condition || "";
-        conditionInput.spellcheck = false;
-        conditionInput.addEventListener("change", this._popoverConditionInputChanged.bind(this));
-        conditionInput.addEventListener("keydown", this._popoverConditionInputKeyDown.bind(this));
-        conditionInput.placeholder = WebInspector.UIString("Conditional _expression_");
-        conditionLabel.setAttribute("for", conditionInput.id);
         conditionLabel.textContent = WebInspector.UIString("Condition");
+        let conditionEditorElement = conditionData.appendChild(document.createElement("div"));
+        conditionEditorElement.classList.add("edit-breakpoint-popover-condition", WebInspector.SyntaxHighlightedStyleClassName);
 
+        this._conditionCodeMirror = CodeMirror(conditionEditorElement, {
+            extraKeys: {Tab: false},
+            lineWrapping: false,
+            mode: "text/_javascript_",
+            matchBrackets: true,
+            placeholder: WebInspector.UIString("Conditional _expression_"),
+            scrollbarStyle: null,
+            value: this._breakpoint.condition || "",
+        });
+
+        let conditionCodeMirrorInputField = this._conditionCodeMirror.getInputField();
+        conditionCodeMirrorInputField.id = "codemirror-condition-input-field";
+        conditionLabel.setAttribute("for", conditionCodeMirrorInputField.id);
+
+        this._conditionCodeMirrorEscapeOrEnterKeyHandler = this._conditionCodeMirrorEscapeOrEnterKey.bind(this);
+        this._conditionCodeMirror.addKeyMap({
+            "Esc": this._conditionCodeMirrorEscapeOrEnterKeyHandler,
+            "Enter": this._conditionCodeMirrorEscapeOrEnterKeyHandler,
+        });
+
+        this._conditionCodeMirror.on("change", this._conditionCodeMirrorChanged.bind(this));
+        this._conditionCodeMirror.on("beforeChange", this._conditionCodeMirrorBeforeChange.bind(this));
+
+        let completionController = new WebInspector.CodeMirrorCompletionController(this._conditionCodeMirror, this);
+        completionController.addExtendedCompletionProvider("_javascript_", WebInspector._javascript_RuntimeCompletionProvider);
+
+        // CodeMirror needs a refresh after the popover displays, to layout, otherwise it doesn't appear.
+        setTimeout(function() {
+            this._conditionCodeMirror.refresh();
+            this._conditionCodeMirror.focus();
+        }.bind(this), 0);
+
         // COMPATIBILITY (iOS 7): Debugger.setBreakpoint did not support options.
         if (DebuggerAgent.setBreakpoint.supports("options")) {
             // COMPATIBILITY (iOS 9): Legacy backends don't support breakpoint ignore count. Since support
@@ -207,11 +236,23 @@
         this._breakpoint.disabled = !event.target.checked;
     }
 
-    _popoverConditionInputChanged(event)
+    _conditionCodeMirrorChanged(codeMirror, change)
     {
-        this._breakpoint.condition = event.target.value;
+        this._breakpoint.condition = (codeMirror.getValue() || "").trim();
     }
 
+    _conditionCodeMirrorBeforeChange(codeMirror, change)
+    {
+        let newText = change.text.join("").replace(/\n/g, "");
+        change.update(change.from, change.to, [newText]);
+        return true;
+    }
+
+    _conditionCodeMirrorEscapeOrEnterKey()
+    {
+        this._popover.dismiss();
+    }
+
     _popoverIgnoreInputChanged(event)
     {
         let ignoreCount = 0;
@@ -230,15 +271,6 @@
         this._breakpoint.autoContinue = event.target.checked;
     }
 
-    _popoverConditionInputKeyDown(event)
-    {
-        if (this._keyboardShortcutEsc.matchesEvent(event) || this._keyboardShortcutEnter.matchesEvent(event)) {
-            this._popover.dismiss();
-            event.stopPropagation();
-            event.preventDefault();
-        }
-    }
-
     _popoverActionsCreateAddActionButton()
     {
         this._popoverContentElement.classList.remove(WebInspector.BreakpointPopoverController.WidePopoverClassName);
@@ -335,5 +367,4 @@
 };
 
 WebInspector.BreakpointPopoverController.WidePopoverClassName = "wide";
-WebInspector.BreakpointPopoverController.PopoverConditionInputId = "edit-breakpoint-popover-condition";
 WebInspector.BreakpointPopoverController.HiddenStyleClassName = "hidden";

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/BreakpointPopoverController.css (192550 => 192551)


--- trunk/Source/WebInspectorUI/UserInterface/Views/BreakpointPopoverController.css	2015-11-18 00:16:56 UTC (rev 192550)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/BreakpointPopoverController.css	2015-11-18 00:23:56 UTC (rev 192551)
@@ -56,10 +56,19 @@
     padding-left: 5px;
 }
 
-#edit-breakpoint-popover-condition {
+.edit-breakpoint-popover-condition {
     width: 100%;
+    padding: 4px 0 2px 0;
+    -webkit-appearance: textfield;
+    border: 1px solid hsl(0, 0%, 78%);
+    background: white;
 }
 
+.edit-breakpoint-popover-condition > .CodeMirror {
+    width: 320px; /* NOTE: Fixed value, manually tuned to .edit-breakpoint-popover-content width. */
+    height: auto;
+}
+
 #edit-breakpoint-popover-ignore {
     width: 40px;
     margin-right: 4px;

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.css (192550 => 192551)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.css	2015-11-18 00:16:56 UTC (rev 192550)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.css	2015-11-18 00:23:56 UTC (rev 192551)
@@ -37,10 +37,7 @@
 }
 
 .css-style-text-editor > .CodeMirror .CodeMirror-placeholder {
-    font-family: -apple-system, sans-serif;
-    color: hsl(0, 0%, 65%);
     padding: 0 5px 0 25px;
-    text-indent: 0;
 }
 
 .css-style-text-editor > .CodeMirror pre {

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorOverrides.css (192550 => 192551)


--- trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorOverrides.css	2015-11-18 00:16:56 UTC (rev 192550)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorOverrides.css	2015-11-18 00:23:56 UTC (rev 192551)
@@ -83,3 +83,9 @@
 .CodeMirror-linewidget {
     -webkit-user-select: text;
 }
+
+.CodeMirror .CodeMirror-placeholder {
+    font-family: -apple-system, sans-serif;
+    color: hsl(0, 0%, 65%);
+    text-indent: 0;
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to