Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / CodeMirrorTextEditor.js
index 52f799d..401f321 100644 (file)
@@ -177,7 +177,6 @@ WebInspector.CodeMirrorTextEditor = function(url, delegate)
     this.element.addEventListener("keydown", this._handlePostKeyDown.bind(this), false);
     this.element.tabIndex = 0;
 
-    this._setupSelectionColor();
     this._setupWhitespaceHighlight();
 }
 
@@ -227,6 +226,7 @@ CodeMirror.commands.undoAndReveal = function(codemirror)
     codemirror.execCommand("undo");
     var cursor = codemirror.getCursor("start");
     codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo);
+    codemirror._codeMirrorTextEditor._autocompleteController.finishAutocomplete();
 }
 
 CodeMirror.commands.redoAndReveal = function(codemirror)
@@ -235,6 +235,7 @@ CodeMirror.commands.redoAndReveal = function(codemirror)
     codemirror.execCommand("redo");
     var cursor = codemirror.getCursor("start");
     codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo);
+    codemirror._codeMirrorTextEditor._autocompleteController.finishAutocomplete();
 }
 
 WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000;
@@ -248,6 +249,9 @@ WebInspector.CodeMirrorTextEditor.prototype = {
 
     wasShown: function()
     {
+        if (this._wasOnceShown)
+            return;
+        this._wasOnceShown = true;
         this._codeMirror.refresh();
     },
 
@@ -369,23 +373,6 @@ WebInspector.CodeMirrorTextEditor.prototype = {
         this._codeMirror.redo();
     },
 
-    _setupSelectionColor: function()
-    {
-        if (WebInspector.CodeMirrorTextEditor._selectionStyleInjected)
-            return;
-        WebInspector.CodeMirrorTextEditor._selectionStyleInjected = true;
-        var backgroundColor = InspectorFrontendHost.getSelectionBackgroundColor();
-        var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selected { background-color: " + backgroundColor + ";}" : "";
-        var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor();
-        var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selectedtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!important;}" : "";
-        if (!foregroundColorRule && !backgroundColorRule)
-            return;
-
-        var style = document.createElement("style");
-        style.textContent = backgroundColorRule + foregroundColorRule;
-        document.head.appendChild(style);
-    },
-
     _setupWhitespaceHighlight: function()
     {
         if (WebInspector.CodeMirrorTextEditor._whitespaceStyleInjected || !WebInspector.settings.showWhitespacesInEditor.get())
@@ -805,11 +792,10 @@ WebInspector.CodeMirrorTextEditor.prototype = {
      */
     highlightPosition: function(lineNumber, columnNumber)
     {
-        if (lineNumber < 0)
-            return;
-        lineNumber = Math.min(lineNumber, this._codeMirror.lineCount() - 1);
-        if (typeof columnNumber !== "number" || columnNumber < 0 || columnNumber > this._codeMirror.getLine(lineNumber).length)
+        lineNumber = Number.constrain(lineNumber, 0, this._codeMirror.lineCount() - 1);
+        if (typeof columnNumber !== "number")
             columnNumber = 0;
+        columnNumber = Number.constrain(columnNumber, 0, this._codeMirror.getLine(lineNumber).length);
 
         this.clearPositionHighlight();
         this._highlightedLine = this._codeMirror.getLineHandle(lineNumber);
@@ -872,16 +858,18 @@ WebInspector.CodeMirrorTextEditor.prototype = {
         var parentElement = this.element.parentElement;
         if (!parentElement || !this.isShowing())
             return;
-        var scrollInfo = this._codeMirror.getScrollInfo();
+        var scrollLeft = this._codeMirror.doc.scrollLeft;
+        var scrollTop = this._codeMirror.doc.scrollTop;
         var width = parentElement.offsetWidth;
         var height = parentElement.offsetHeight;
         this._codeMirror.setSize(width, height);
         this._updatePaddingBottom(width, height);
-        this._codeMirror.scrollTo(scrollInfo.left, scrollInfo.top);
+        this._codeMirror.scrollTo(scrollLeft, scrollTop);
     },
 
     onResize: function()
     {
+        this._autocompleteController.finishAutocomplete();
         this._resizeEditor();
     },
 
@@ -1716,3 +1704,16 @@ WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens = function(mod
 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("css", "css-");
 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("javascript", "js-");
 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("xml", "xml-");
+
+(function() {
+    var backgroundColor = InspectorFrontendHost.getSelectionBackgroundColor();
+    var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selected { background-color: " + backgroundColor + ";}" : "";
+    var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor();
+    var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selectedtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!important;}" : "";
+    if (!foregroundColorRule && !backgroundColorRule)
+        return;
+
+    var style = document.createElement("style");
+    style.textContent = backgroundColorRule + foregroundColorRule;
+    document.head.appendChild(style);
+})();