Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(950)

Unified Diff: Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js

Issue 670163002: DevTools: [CodeMirrro] defer autocomplete controller initialization (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebaseline test Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/inspector/editor/text-editor-autocomplete-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js
diff --git a/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js b/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js
index 54d8b462022d93701bad87c0676c253ded1a9d2a..9ee55ad5e34405553ef1ee96d74a1d91f05f8671 100644
--- a/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js
+++ b/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js
@@ -1990,17 +1990,14 @@ WebInspector.CodeMirrorTextEditor.AutocompleteController = function(textEditor,
this._changes = this._changes.bind(this);
this._beforeChange = this._beforeChange.bind(this);
this._blur = this._blur.bind(this);
- this._codeMirror.on("scroll", this._onScroll);
- this._codeMirror.on("cursorActivity", this._onCursorActivity);
+
this._codeMirror.on("changes", this._changes);
- this._codeMirror.on("beforeChange", this._beforeChange);
- this._codeMirror.on("blur", this._blur);
this._additionalWordChars = WebInspector.CodeMirrorTextEditor._NoAdditionalWordChars;
this._enabled = true;
this._dictionary = dictionary;
- this._addTextToCompletionDictionary(this._textEditor.text());
+ this._initialized = false;
}
WebInspector.CodeMirrorTextEditor.AutocompleteController.Dummy = new WebInspector.CodeMirrorTextEditor.DummyAutocompleteController();
@@ -2008,11 +2005,25 @@ WebInspector.CodeMirrorTextEditor._NoAdditionalWordChars = {};
WebInspector.CodeMirrorTextEditor._CSSAdditionalWordChars = { ".": true, "-": true };
WebInspector.CodeMirrorTextEditor.AutocompleteController.prototype = {
+ _initializeIfNeeded: function()
+ {
+ if (this._initialized)
+ return;
+ this._initialized = true;
+ this._codeMirror.on("scroll", this._onScroll);
+ this._codeMirror.on("cursorActivity", this._onCursorActivity);
+ this._codeMirror.on("beforeChange", this._beforeChange);
+ this._codeMirror.on("blur", this._blur);
+ this._addTextToCompletionDictionary(this._textEditor.text());
+ },
+
dispose: function()
{
+ this._codeMirror.off("changes", this._changes);
+ if (!this._initialized)
+ return;
this._codeMirror.off("scroll", this._onScroll);
this._codeMirror.off("cursorActivity", this._onCursorActivity);
- this._codeMirror.off("changes", this._changes);
this._codeMirror.off("beforeChange", this._beforeChange);
this._codeMirror.off("blur", this._blur);
},
@@ -2067,7 +2078,7 @@ WebInspector.CodeMirrorTextEditor.AutocompleteController.prototype = {
*/
_addTextToCompletionDictionary: function(text)
{
- if (!this._enabled)
+ if (!this._enabled || !this._initialized)
return;
var words = WebInspector.TextUtils.textToWords(text, this._isWordChar.bind(this));
for (var i = 0; i < words.length; ++i) {
@@ -2081,7 +2092,7 @@ WebInspector.CodeMirrorTextEditor.AutocompleteController.prototype = {
*/
_removeTextFromCompletionDictionary: function(text)
{
- if (!this._enabled)
+ if (!this._enabled || !this._initialized)
return;
var words = WebInspector.TextUtils.textToWords(text, this._isWordChar.bind(this));
for (var i = 0; i < words.length; ++i) {
@@ -2172,6 +2183,7 @@ WebInspector.CodeMirrorTextEditor.AutocompleteController.prototype = {
autocomplete: function()
{
+ this._initializeIfNeeded();
var dictionary = this._dictionary;
if (this._codeMirror.somethingSelected()) {
this.finishAutocomplete();
« no previous file with comments | « LayoutTests/inspector/editor/text-editor-autocomplete-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698