<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[192551] trunk/Source/WebInspectorUI</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/192551">192551</a></dd>
<dt>Author</dt> <dd>mattbaker@apple.com</dd>
<dt>Date</dt> <dd>2015-11-17 16:23:56 -0800 (Tue, 17 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>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 &gt; .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 &gt; .CodeMirror .CodeMirror-placeholder): Deleted.
Moved common CodeMirror placeholder text style to CodeMirrorOverrides.css.

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

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersBreakpointPopoverControllerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/BreakpointPopoverController.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsBreakpointPopoverControllercss">trunk/Source/WebInspectorUI/UserInterface/Views/BreakpointPopoverController.css</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationTextEditorcss">trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.css</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsCodeMirrorOverridescss">trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorOverrides.css</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (192550 => 192551)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,44 @@
</span><ins>+2015-11-17  Matt Baker  &lt;mattbaker@apple.com&gt;
+
+        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 &gt; .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 &gt; .CodeMirror .CodeMirror-placeholder): Deleted.
+        Moved common CodeMirror placeholder text style to CodeMirrorOverrides.css.
+
+        * UserInterface/Views/CodeMirrorOverrides.css:
+        (.CodeMirror .CodeMirror-placeholder):
+        Add placeholder style.
+
</ins><span class="cx"> 2015-11-12  Matt Baker  &lt;mattbaker@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Deleting a probe should remove probe breakpoint actions only.
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersBreakpointPopoverControllerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/BreakpointPopoverController.js (192550 => 192551)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -32,8 +32,6 @@
</span><span class="cx">         this._breakpoint = null;
</span><span class="cx">         this._popover = null;
</span><span class="cx">         this._popoverContentElement = null;
</span><del>-        this._keyboardShortcutEsc = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Escape);
-        this._keyboardShortcutEnter = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Enter);
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Public
</span><span class="lines">@@ -55,8 +53,6 @@
</span><span class="cx">             let bounds = WebInspector.Rect.rectFromClientRect(breakpointDisplayElement.getBoundingClientRect());
</span><span class="cx">             bounds.origin.x -= 1; // Move the anchor left one pixel so it looks more centered.
</span><span class="cx">             this._popover.present(bounds.pad(2), [WebInspector.RectEdge.MAX_Y]);
</span><del>-
-            document.getElementById(WebInspector.BreakpointPopoverController.PopoverConditionInputId).select();
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function removeBreakpoint()
</span><span class="lines">@@ -104,6 +100,13 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    // CodeMirrorCompletionController delegate
+
+    completionControllerShouldAllowEscapeCompletion()
+    {
+        return false;
+    }
+
</ins><span class="cx">     // Private
</span><span class="cx"> 
</span><span class="cx">     _createPopoverContent(breakpoint)
</span><span class="lines">@@ -132,16 +135,42 @@
</span><span class="cx">         let conditionHeader = conditionRow.appendChild(document.createElement(&quot;th&quot;));
</span><span class="cx">         let conditionData = conditionRow.appendChild(document.createElement(&quot;td&quot;));
</span><span class="cx">         let conditionLabel = conditionHeader.appendChild(document.createElement(&quot;label&quot;));
</span><del>-        let conditionInput = conditionData.appendChild(document.createElement(&quot;input&quot;));
-        conditionInput.id = WebInspector.BreakpointPopoverController.PopoverConditionInputId;
-        conditionInput.value = this._breakpoint.condition || &quot;&quot;;
-        conditionInput.spellcheck = false;
-        conditionInput.addEventListener(&quot;change&quot;, this._popoverConditionInputChanged.bind(this));
-        conditionInput.addEventListener(&quot;keydown&quot;, this._popoverConditionInputKeyDown.bind(this));
-        conditionInput.placeholder = WebInspector.UIString(&quot;Conditional expression&quot;);
-        conditionLabel.setAttribute(&quot;for&quot;, conditionInput.id);
</del><span class="cx">         conditionLabel.textContent = WebInspector.UIString(&quot;Condition&quot;);
</span><ins>+        let conditionEditorElement = conditionData.appendChild(document.createElement(&quot;div&quot;));
+        conditionEditorElement.classList.add(&quot;edit-breakpoint-popover-condition&quot;, WebInspector.SyntaxHighlightedStyleClassName);
</ins><span class="cx"> 
</span><ins>+        this._conditionCodeMirror = CodeMirror(conditionEditorElement, {
+            extraKeys: {Tab: false},
+            lineWrapping: false,
+            mode: &quot;text/javascript&quot;,
+            matchBrackets: true,
+            placeholder: WebInspector.UIString(&quot;Conditional expression&quot;),
+            scrollbarStyle: null,
+            value: this._breakpoint.condition || &quot;&quot;,
+        });
+
+        let conditionCodeMirrorInputField = this._conditionCodeMirror.getInputField();
+        conditionCodeMirrorInputField.id = &quot;codemirror-condition-input-field&quot;;
+        conditionLabel.setAttribute(&quot;for&quot;, conditionCodeMirrorInputField.id);
+
+        this._conditionCodeMirrorEscapeOrEnterKeyHandler = this._conditionCodeMirrorEscapeOrEnterKey.bind(this);
+        this._conditionCodeMirror.addKeyMap({
+            &quot;Esc&quot;: this._conditionCodeMirrorEscapeOrEnterKeyHandler,
+            &quot;Enter&quot;: this._conditionCodeMirrorEscapeOrEnterKeyHandler,
+        });
+
+        this._conditionCodeMirror.on(&quot;change&quot;, this._conditionCodeMirrorChanged.bind(this));
+        this._conditionCodeMirror.on(&quot;beforeChange&quot;, this._conditionCodeMirrorBeforeChange.bind(this));
+
+        let completionController = new WebInspector.CodeMirrorCompletionController(this._conditionCodeMirror, this);
+        completionController.addExtendedCompletionProvider(&quot;javascript&quot;, WebInspector.javaScriptRuntimeCompletionProvider);
+
+        // 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);
+
</ins><span class="cx">         // COMPATIBILITY (iOS 7): Debugger.setBreakpoint did not support options.
</span><span class="cx">         if (DebuggerAgent.setBreakpoint.supports(&quot;options&quot;)) {
</span><span class="cx">             // COMPATIBILITY (iOS 9): Legacy backends don't support breakpoint ignore count. Since support
</span><span class="lines">@@ -207,11 +236,23 @@
</span><span class="cx">         this._breakpoint.disabled = !event.target.checked;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _popoverConditionInputChanged(event)
</del><ins>+    _conditionCodeMirrorChanged(codeMirror, change)
</ins><span class="cx">     {
</span><del>-        this._breakpoint.condition = event.target.value;
</del><ins>+        this._breakpoint.condition = (codeMirror.getValue() || &quot;&quot;).trim();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    _conditionCodeMirrorBeforeChange(codeMirror, change)
+    {
+        let newText = change.text.join(&quot;&quot;).replace(/\n/g, &quot;&quot;);
+        change.update(change.from, change.to, [newText]);
+        return true;
+    }
+
+    _conditionCodeMirrorEscapeOrEnterKey()
+    {
+        this._popover.dismiss();
+    }
+
</ins><span class="cx">     _popoverIgnoreInputChanged(event)
</span><span class="cx">     {
</span><span class="cx">         let ignoreCount = 0;
</span><span class="lines">@@ -230,15 +271,6 @@
</span><span class="cx">         this._breakpoint.autoContinue = event.target.checked;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _popoverConditionInputKeyDown(event)
-    {
-        if (this._keyboardShortcutEsc.matchesEvent(event) || this._keyboardShortcutEnter.matchesEvent(event)) {
-            this._popover.dismiss();
-            event.stopPropagation();
-            event.preventDefault();
-        }
-    }
-
</del><span class="cx">     _popoverActionsCreateAddActionButton()
</span><span class="cx">     {
</span><span class="cx">         this._popoverContentElement.classList.remove(WebInspector.BreakpointPopoverController.WidePopoverClassName);
</span><span class="lines">@@ -335,5 +367,4 @@
</span><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.BreakpointPopoverController.WidePopoverClassName = &quot;wide&quot;;
</span><del>-WebInspector.BreakpointPopoverController.PopoverConditionInputId = &quot;edit-breakpoint-popover-condition&quot;;
</del><span class="cx"> WebInspector.BreakpointPopoverController.HiddenStyleClassName = &quot;hidden&quot;;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsBreakpointPopoverControllercss"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/BreakpointPopoverController.css (192550 => 192551)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -56,10 +56,19 @@
</span><span class="cx">     padding-left: 5px;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#edit-breakpoint-popover-condition {
</del><ins>+.edit-breakpoint-popover-condition {
</ins><span class="cx">     width: 100%;
</span><ins>+    padding: 4px 0 2px 0;
+    -webkit-appearance: textfield;
+    border: 1px solid hsl(0, 0%, 78%);
+    background: white;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.edit-breakpoint-popover-condition &gt; .CodeMirror {
+    width: 320px; /* NOTE: Fixed value, manually tuned to .edit-breakpoint-popover-content width. */
+    height: auto;
+}
+
</ins><span class="cx"> #edit-breakpoint-popover-ignore {
</span><span class="cx">     width: 40px;
</span><span class="cx">     margin-right: 4px;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCSSStyleDeclarationTextEditorcss"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CSSStyleDeclarationTextEditor.css (192550 => 192551)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -37,10 +37,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .css-style-text-editor &gt; .CodeMirror .CodeMirror-placeholder {
</span><del>-    font-family: -apple-system, sans-serif;
-    color: hsl(0, 0%, 65%);
</del><span class="cx">     padding: 0 5px 0 25px;
</span><del>-    text-indent: 0;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> .css-style-text-editor &gt; .CodeMirror pre {
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsCodeMirrorOverridescss"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/CodeMirrorOverrides.css (192550 => 192551)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -83,3 +83,9 @@
</span><span class="cx"> .CodeMirror-linewidget {
</span><span class="cx">     -webkit-user-select: text;
</span><span class="cx"> }
</span><ins>+
+.CodeMirror .CodeMirror-placeholder {
+    font-family: -apple-system, sans-serif;
+    color: hsl(0, 0%, 65%);
+    text-indent: 0;
+}
</ins></span></pre>
</div>
</div>

</body>
</html>