Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Probes: enable code completion within quick-add probe expression popup.

Fixes #356.
  • Loading branch information...
commit 0df59b9b9f608e70addfd91c84d8fd2cad245a7f 1 parent 81593e4
Brian Burg authored December 09, 2013
53  Source/WebInspectorUI/UserInterface/SourceCodeTextEditor.js
@@ -753,14 +753,13 @@ WebInspector.SourceCodeTextEditor.prototype = {
753 753
         }
754 754
 
755 755
         // Adding probe expressions directly.
756  
-        function addProbeBreakpointAction(popover, event)
  756
+        function addProbeBreakpointAction(popover, codeMirror)
757 757
         {
758  
-            if (event.keyCode !== 13) // enter/return
759  
-                return;
760  
-
761  
-            var expression = event.target.value;
762  
-            if (!expression)
  758
+            var expression = codeMirror.getValue();
  759
+            if (!expression) {
  760
+                popover.dismiss();
763 761
                 return;
  762
+            }
764 763
 
765 764
             // If no breakpoints exist yet at this line, create one.
766 765
             if (!breakpoints.length)
@@ -793,18 +792,40 @@ WebInspector.SourceCodeTextEditor.prototype = {
793 792
         function promptForProbeExpression()
794 793
         {
795 794
             var popover = new WebInspector.Popover;
796  
-            var content = document.createElement("div");
797  
-            content.classList.add(WebInspector.ProbeSetDetailsSection.ProbePopoverElementStyleClassName);
798  
-            content.createChild("div").textContent = WebInspector.UIString("Expression To Evaluate Here:");
799  
-            var textBox = content.createChild("input");
800  
-            textBox.addEventListener("keypress", addProbeBreakpointAction.bind(this, popover));
801  
-            textBox.addEventListener("click", function (event) {event.target.select()});
802  
-            textBox.type = "text";
803  
-            textBox.value = WebInspector.UIString("Enter Expression");
804  
-            popover.content = content;
  795
+            var bodyElement = document.createElement("div");
  796
+            bodyElement.classList.add(WebInspector.ProbeSetDetailsSection.ProbePopoverElementStyleClassName);
  797
+            bodyElement.createChild("div").textContent = WebInspector.UIString("Expression To Evaluate Here:");
  798
+
  799
+            var editorElement = bodyElement.appendChild(document.createElement("div"));
  800
+            editorElement.classList.add("breakpoint-action-eval-editor");
  801
+            editorElement.classList.add(WebInspector.SyntaxHighlightedStyleClassName);
  802
+
  803
+            codeMirror = CodeMirror(editorElement, {
  804
+                lineWrapping: true,
  805
+                mode: "text/javascript",
  806
+                indentWithTabs: true,
  807
+                indentUnit: 4,
  808
+                matchBrackets: true,
  809
+                value: WebInspector.UIString("Enter Expression"),
  810
+            });
  811
+
  812
+            codeMirror.on("viewportChange", popover.update.bind(popover));
  813
+            codeMirror.on("blur", addProbeBreakpointAction.bind(this, popover, codeMirror));
  814
+
  815
+            var completionController = new WebInspector.CodeMirrorCompletionController(codeMirror);
  816
+            completionController.addExtendedCompletionProvider("javascript", WebInspector.javaScriptRuntimeCompletionProvider);
  817
+
  818
+            // CodeMirror needs a refresh after the popover displays, to layout, otherwise it doesn't appear.
  819
+            setTimeout(function() {
  820
+                codeMirror.refresh();
  821
+                codeMirror.focus();
  822
+                codeMirror.setCursor({line: 0, ch: 0});
  823
+                codeMirror.setSelection({line: codeMirror.firstLine(), ch: 0}, {line: codeMirror.lastLine()});
  824
+            }.bind(this), 0);
  825
+
  826
+            popover.content = bodyElement;
805 827
             var target = WebInspector.Rect.rectFromClientRect(event.target.getBoundingClientRect());
806 828
             popover.present(target, [WebInspector.RectEdge.MAX_Y, WebInspector.RectEdge.MIN_Y, WebInspector.RectEdge.MAX_X]);
807  
-            textBox.select();
808 829
         }
809 830
 
810 831
         contextMenu.appendItem(WebInspector.UIString("Add Probe Expression"), promptForProbeExpression.bind(this));

0 notes on commit 0df59b9

Please sign in to comment.
Something went wrong with that request. Please try again.