| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 1972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 WebInspector.CodeMirrorTextEditor.AutocompleteController = function(textEditor,
codeMirror, dictionary) | 1983 WebInspector.CodeMirrorTextEditor.AutocompleteController = function(textEditor,
codeMirror, dictionary) |
| 1984 { | 1984 { |
| 1985 this._textEditor = textEditor; | 1985 this._textEditor = textEditor; |
| 1986 this._codeMirror = codeMirror; | 1986 this._codeMirror = codeMirror; |
| 1987 | 1987 |
| 1988 this._onScroll = this._onScroll.bind(this); | 1988 this._onScroll = this._onScroll.bind(this); |
| 1989 this._onCursorActivity = this._onCursorActivity.bind(this); | 1989 this._onCursorActivity = this._onCursorActivity.bind(this); |
| 1990 this._changes = this._changes.bind(this); | 1990 this._changes = this._changes.bind(this); |
| 1991 this._beforeChange = this._beforeChange.bind(this); | 1991 this._beforeChange = this._beforeChange.bind(this); |
| 1992 this._blur = this._blur.bind(this); | 1992 this._blur = this._blur.bind(this); |
| 1993 this._codeMirror.on("scroll", this._onScroll); | 1993 |
| 1994 this._codeMirror.on("cursorActivity", this._onCursorActivity); | |
| 1995 this._codeMirror.on("changes", this._changes); | 1994 this._codeMirror.on("changes", this._changes); |
| 1996 this._codeMirror.on("beforeChange", this._beforeChange); | |
| 1997 this._codeMirror.on("blur", this._blur); | |
| 1998 | 1995 |
| 1999 this._additionalWordChars = WebInspector.CodeMirrorTextEditor._NoAdditionalW
ordChars; | 1996 this._additionalWordChars = WebInspector.CodeMirrorTextEditor._NoAdditionalW
ordChars; |
| 2000 this._enabled = true; | 1997 this._enabled = true; |
| 2001 | 1998 |
| 2002 this._dictionary = dictionary; | 1999 this._dictionary = dictionary; |
| 2003 this._addTextToCompletionDictionary(this._textEditor.text()); | 2000 this._initialized = false; |
| 2004 } | 2001 } |
| 2005 | 2002 |
| 2006 WebInspector.CodeMirrorTextEditor.AutocompleteController.Dummy = new WebInspecto
r.CodeMirrorTextEditor.DummyAutocompleteController(); | 2003 WebInspector.CodeMirrorTextEditor.AutocompleteController.Dummy = new WebInspecto
r.CodeMirrorTextEditor.DummyAutocompleteController(); |
| 2007 WebInspector.CodeMirrorTextEditor._NoAdditionalWordChars = {}; | 2004 WebInspector.CodeMirrorTextEditor._NoAdditionalWordChars = {}; |
| 2008 WebInspector.CodeMirrorTextEditor._CSSAdditionalWordChars = { ".": true, "-": tr
ue }; | 2005 WebInspector.CodeMirrorTextEditor._CSSAdditionalWordChars = { ".": true, "-": tr
ue }; |
| 2009 | 2006 |
| 2010 WebInspector.CodeMirrorTextEditor.AutocompleteController.prototype = { | 2007 WebInspector.CodeMirrorTextEditor.AutocompleteController.prototype = { |
| 2008 _initializeIfNeeded: function() |
| 2009 { |
| 2010 if (this._initialized) |
| 2011 return; |
| 2012 this._initialized = true; |
| 2013 this._codeMirror.on("scroll", this._onScroll); |
| 2014 this._codeMirror.on("cursorActivity", this._onCursorActivity); |
| 2015 this._codeMirror.on("beforeChange", this._beforeChange); |
| 2016 this._codeMirror.on("blur", this._blur); |
| 2017 this._addTextToCompletionDictionary(this._textEditor.text()); |
| 2018 }, |
| 2019 |
| 2011 dispose: function() | 2020 dispose: function() |
| 2012 { | 2021 { |
| 2022 this._codeMirror.off("changes", this._changes); |
| 2023 if (!this._initialized) |
| 2024 return; |
| 2013 this._codeMirror.off("scroll", this._onScroll); | 2025 this._codeMirror.off("scroll", this._onScroll); |
| 2014 this._codeMirror.off("cursorActivity", this._onCursorActivity); | 2026 this._codeMirror.off("cursorActivity", this._onCursorActivity); |
| 2015 this._codeMirror.off("changes", this._changes); | |
| 2016 this._codeMirror.off("beforeChange", this._beforeChange); | 2027 this._codeMirror.off("beforeChange", this._beforeChange); |
| 2017 this._codeMirror.off("blur", this._blur); | 2028 this._codeMirror.off("blur", this._blur); |
| 2018 }, | 2029 }, |
| 2019 | 2030 |
| 2020 /** | 2031 /** |
| 2021 * @param {boolean} enabled | 2032 * @param {boolean} enabled |
| 2022 */ | 2033 */ |
| 2023 setEnabled: function(enabled) | 2034 setEnabled: function(enabled) |
| 2024 { | 2035 { |
| 2025 if (enabled === this._enabled) | 2036 if (enabled === this._enabled) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2060 _shouldProcessWordForAutocompletion: function(word) | 2071 _shouldProcessWordForAutocompletion: function(word) |
| 2061 { | 2072 { |
| 2062 return !!word.length && (word[0] < '0' || word[0] > '9'); | 2073 return !!word.length && (word[0] < '0' || word[0] > '9'); |
| 2063 }, | 2074 }, |
| 2064 | 2075 |
| 2065 /** | 2076 /** |
| 2066 * @param {string} text | 2077 * @param {string} text |
| 2067 */ | 2078 */ |
| 2068 _addTextToCompletionDictionary: function(text) | 2079 _addTextToCompletionDictionary: function(text) |
| 2069 { | 2080 { |
| 2070 if (!this._enabled) | 2081 if (!this._enabled || !this._initialized) |
| 2071 return; | 2082 return; |
| 2072 var words = WebInspector.TextUtils.textToWords(text, this._isWordChar.bi
nd(this)); | 2083 var words = WebInspector.TextUtils.textToWords(text, this._isWordChar.bi
nd(this)); |
| 2073 for (var i = 0; i < words.length; ++i) { | 2084 for (var i = 0; i < words.length; ++i) { |
| 2074 if (this._shouldProcessWordForAutocompletion(words[i])) | 2085 if (this._shouldProcessWordForAutocompletion(words[i])) |
| 2075 this._dictionary.addWord(words[i]); | 2086 this._dictionary.addWord(words[i]); |
| 2076 } | 2087 } |
| 2077 }, | 2088 }, |
| 2078 | 2089 |
| 2079 /** | 2090 /** |
| 2080 * @param {string} text | 2091 * @param {string} text |
| 2081 */ | 2092 */ |
| 2082 _removeTextFromCompletionDictionary: function(text) | 2093 _removeTextFromCompletionDictionary: function(text) |
| 2083 { | 2094 { |
| 2084 if (!this._enabled) | 2095 if (!this._enabled || !this._initialized) |
| 2085 return; | 2096 return; |
| 2086 var words = WebInspector.TextUtils.textToWords(text, this._isWordChar.bi
nd(this)); | 2097 var words = WebInspector.TextUtils.textToWords(text, this._isWordChar.bi
nd(this)); |
| 2087 for (var i = 0; i < words.length; ++i) { | 2098 for (var i = 0; i < words.length; ++i) { |
| 2088 if (this._shouldProcessWordForAutocompletion(words[i])) | 2099 if (this._shouldProcessWordForAutocompletion(words[i])) |
| 2089 this._dictionary.removeWord(words[i]); | 2100 this._dictionary.removeWord(words[i]); |
| 2090 } | 2101 } |
| 2091 }, | 2102 }, |
| 2092 | 2103 |
| 2093 /** | 2104 /** |
| 2094 * @param {!CodeMirror} codeMirror | 2105 * @param {!CodeMirror} codeMirror |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2165 return false; | 2176 return false; |
| 2166 var context = this._textEditor.copyRange(wordRange); | 2177 var context = this._textEditor.copyRange(wordRange); |
| 2167 if (context !== mainSelectionContext) | 2178 if (context !== mainSelectionContext) |
| 2168 return false; | 2179 return false; |
| 2169 } | 2180 } |
| 2170 return true; | 2181 return true; |
| 2171 }, | 2182 }, |
| 2172 | 2183 |
| 2173 autocomplete: function() | 2184 autocomplete: function() |
| 2174 { | 2185 { |
| 2186 this._initializeIfNeeded(); |
| 2175 var dictionary = this._dictionary; | 2187 var dictionary = this._dictionary; |
| 2176 if (this._codeMirror.somethingSelected()) { | 2188 if (this._codeMirror.somethingSelected()) { |
| 2177 this.finishAutocomplete(); | 2189 this.finishAutocomplete(); |
| 2178 return; | 2190 return; |
| 2179 } | 2191 } |
| 2180 | 2192 |
| 2181 var selections = this._codeMirror.listSelections().slice(); | 2193 var selections = this._codeMirror.listSelections().slice(); |
| 2182 var topSelection = selections.shift(); | 2194 var topSelection = selections.shift(); |
| 2183 var cursor = topSelection.head; | 2195 var cursor = topSelection.head; |
| 2184 var substituteRange = this._autocompleteWordRange(cursor.line, cursor.ch
); | 2196 var substituteRange = this._autocompleteWordRange(cursor.line, cursor.ch
); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2471 function tokenOverride(superToken, stream, state) | 2483 function tokenOverride(superToken, stream, state) |
| 2472 { | 2484 { |
| 2473 var token = superToken(stream, state); | 2485 var token = superToken(stream, state); |
| 2474 return token ? tokenPrefix + token.split(/ +/).join(" " + tokenPrefix) :
token; | 2486 return token ? tokenPrefix + token.split(/ +/).join(" " + tokenPrefix) :
token; |
| 2475 } | 2487 } |
| 2476 } | 2488 } |
| 2477 | 2489 |
| 2478 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("css", "css-")
; | 2490 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("css", "css-")
; |
| 2479 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("javascript",
"js-"); | 2491 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("javascript",
"js-"); |
| 2480 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("xml", "xml-")
; | 2492 WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("xml", "xml-")
; |
| OLD | NEW |