Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js b/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js |
| index 5195fa73a6d4aeba78c88fd15aa7394feac90aee..7d8dbf4a57d078a90e10931395696ad7cf3f0043 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/text_editor/CodeMirrorTextEditor.js |
| @@ -30,13 +30,14 @@ |
| /** |
| * @constructor |
| + * @implements {WebInspector.TextEditor} |
| * @extends {WebInspector.VBox} |
| + * @param {!WebInspector.TextEditor.Options} options |
| */ |
| -WebInspector.CodeMirrorTextEditor = function() |
| +WebInspector.CodeMirrorTextEditor = function(options) |
| { |
| WebInspector.VBox.call(this); |
| - /** @type {!Array<string>} */ |
| - this._gutters = ["CodeMirror-linenumbers"]; |
| + this._options = options; |
| this.registerRequiredCSS("cm/codemirror.css"); |
| this.registerRequiredCSS("text_editor/cmdevtools.css"); |
| @@ -44,13 +45,13 @@ WebInspector.CodeMirrorTextEditor = function() |
| WebInspector.CodeMirrorUtils.appendThemeStyle(this.element); |
| this._codeMirror = new window.CodeMirror(this.element, { |
| - lineNumbers: true, |
| - gutters: ["CodeMirror-linenumbers"], |
| + lineNumbers: options.lineNumbers, |
| matchBrackets: true, |
| smartIndent: false, |
| styleSelectedText: true, |
| electricChars: false, |
| - styleActiveLine: true |
| + styleActiveLine: true, |
| + lineWrapping: options.lineWrapping |
| }); |
| this._codeMirrorElement = this.element.lastElementChild; |
| @@ -120,8 +121,8 @@ WebInspector.CodeMirrorTextEditor = function() |
| "Cmd-U": "undoLastSelection", |
| fallthrough: "devtools-common" |
| }; |
| - |
| - WebInspector.moduleSetting("textEditorBracketMatching").addChangeListener(this._enableBracketMatchingIfNeeded, this); |
| + if (options.bracketMatchingFlag) |
| + WebInspector.moduleSetting(options.bracketMatchingFlag).addChangeListener(this._enableBracketMatchingIfNeeded, this); |
|
dgozman
2016/08/26 19:03:24
Pass a WI.Setting instance directly.
einbinder
2016/08/26 23:05:33
Done.
|
| this._enableBracketMatchingIfNeeded(); |
| this._codeMirror.setOption("keyMap", WebInspector.isMac() ? "devtools-mac" : "devtools-pc"); |
| @@ -153,12 +154,16 @@ WebInspector.CodeMirrorTextEditor = function() |
| /** @type {!Multimap<number, !WebInspector.CodeMirrorTextEditor.Decoration>} */ |
| this._decorations = new Multimap(); |
| + if (options.additionalClass) |
|
dgozman
2016/08/26 19:03:24
Can we add this class on the widget's element inst
einbinder
2016/08/26 23:05:33
Yeah, we should be able to add it to the surroundi
|
| + this._codeMirrorElement.classList.add(options.additionalClass); |
| this._nestedUpdatesCounter = 0; |
| this.element.addEventListener("focus", this._handleElementFocus.bind(this), false); |
| this.element.addEventListener("keydown", this._handleKeyDown.bind(this), true); |
| this.element.addEventListener("keydown", this._handlePostKeyDown.bind(this), false); |
| this.element.tabIndex = 0; |
| + if (options.mimeType) |
| + this.setMimeType(options.mimeType); |
| } |
| WebInspector.CodeMirrorTextEditor.maxHighlightLength = 1000; |
| @@ -249,7 +254,7 @@ CodeMirror.commands.undoAndReveal = function(codemirror) |
| codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo); |
| var autocompleteController = codemirror._codeMirrorTextEditor._autocompleteController; |
| if (autocompleteController) |
| - autocompleteController.finishAutocomplete(); |
| + autocompleteController.clearAutocomplete(); |
| } |
| /** |
| @@ -263,7 +268,7 @@ CodeMirror.commands.redoAndReveal = function(codemirror) |
| codemirror._codeMirrorTextEditor._innerRevealLine(cursor.line, scrollInfo); |
| var autocompleteController = codemirror._codeMirrorTextEditor._autocompleteController; |
| if (autocompleteController) |
| - autocompleteController.finishAutocomplete(); |
| + autocompleteController.clearAutocomplete(); |
| } |
| /** |
| @@ -293,7 +298,7 @@ CodeMirror.commands.dismiss = function(codemirror) |
| WebInspector.CodeMirrorTextEditor._maybeAvoidSmartQuotes = function(quoteCharacter, codeMirror) |
| { |
| var textEditor = codeMirror._codeMirrorTextEditor; |
| - if (!WebInspector.moduleSetting("textEditorBracketMatching").get()) |
| + if (!codeMirror.getOption("autoCloseBrackets")) |
| return CodeMirror.Pass; |
| var selections = textEditor.selections(); |
| if (selections.length !== 1 || !selections[0].isEmpty()) |
| @@ -325,6 +330,15 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| return this._codeMirror; |
| }, |
| + /** |
| + * @override |
| + * @return {!WebInspector.Widget} |
| + */ |
| + widget: function() |
| + { |
| + return this; |
| + }, |
| + |
| _onKeyHandled: function() |
| { |
| WebInspector.shortcutRegistry.dismissPendingShortcutAction(); |
| @@ -481,12 +495,13 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| dispose: function() |
| { |
| - WebInspector.moduleSetting("textEditorBracketMatching").removeChangeListener(this._enableBracketMatchingIfNeeded, this); |
| + if (this._options.bracketMatchingFlag) |
| + WebInspector.moduleSetting(this._options.bracketMatchingFlag).removeChangeListener(this._enableBracketMatchingIfNeeded, this); |
| }, |
| _enableBracketMatchingIfNeeded: function() |
| { |
| - this._codeMirror.setOption("autoCloseBrackets", WebInspector.moduleSetting("textEditorBracketMatching").get() ? { explode: false } : false); |
| + this._codeMirror.setOption("autoCloseBrackets", (this._options.bracketMatchingFlag && WebInspector.moduleSetting(this._options.bracketMatchingFlag).get()) ? { explode: false } : false); |
| }, |
| /** |
| @@ -518,12 +533,18 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| this._codeMirror.redo(); |
| }, |
| + /** |
| + * @param {!Event} e |
| + */ |
| _handleKeyDown: function(e) |
| { |
| if (this._autocompleteController && this._autocompleteController.keyDown(e)) |
| e.consume(true); |
| }, |
| + /** |
| + * @param {!Event} e |
| + */ |
| _handlePostKeyDown: function(e) |
| { |
| if (e.defaultPrevented) |
| @@ -531,6 +552,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| * @param {?WebInspector.AutocompleteConfig} config |
| */ |
| configureAutocomplete: function(config) |
| @@ -611,6 +633,9 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| this._codeMirror.markClean(); |
| }, |
| + /** |
| + * @return {boolean} |
| + */ |
| _hasLongLines: function() |
| { |
| function lineIterator(lineHandle) |
| @@ -685,6 +710,15 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| + * @param {function(!KeyboardEvent)} handler |
| + */ |
| + onKeyDown: function(handler) |
| + { |
| + this._codeMirror.on("keydown", (CodeMirror, event) => handler(event)); |
| + }, |
| + |
| + /** |
| * @param {number} lineNumber |
| * @param {number} columnNumber |
| * @param {!Element} element |
| @@ -730,6 +764,15 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| this._codeMirror.focus(); |
| }, |
| + /** |
| + * @override |
| + * @return {boolean} |
| + */ |
| + hasFocus: function() |
| + { |
| + return this._codeMirror.hasFocus(); |
| + }, |
| + |
| _handleElementFocus: function() |
| { |
| this._codeMirror.focus(); |
| @@ -929,7 +972,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| onResize: function() |
| { |
| if (this._autocompleteController) |
| - this._autocompleteController.finishAutocomplete(); |
| + this._autocompleteController.clearAutocomplete(); |
| this._resizeEditor(); |
| this._editorSizeInSync = true; |
| if (this._selectionSetScheduled) { |
| @@ -952,6 +995,15 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| + */ |
| + clearAutocomplete: function() |
| + { |
| + if (this._autocompleteController) |
| + this._autocompleteController.clearAutocomplete(); |
| + }, |
| + |
| + /** |
| * @param {number} lineNumber |
| * @param {number} column |
| * @param {function(string):boolean} isWordChar |
| @@ -1043,6 +1095,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| * @return {!WebInspector.TextRange} |
| */ |
| selection: function() |
| @@ -1076,6 +1129,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| * @param {!WebInspector.TextRange} textRange |
| */ |
| setSelection: function(textRange) |
| @@ -1116,6 +1170,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| * @param {string} text |
| */ |
| setText: function(text) |
| @@ -1133,6 +1188,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| * @param {!WebInspector.TextRange=} textRange |
| * @return {string} |
| */ |
| @@ -1145,6 +1201,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| * @return {!WebInspector.TextRange} |
| */ |
| range: function() |
| @@ -1155,6 +1212,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| + * @override |
| * @param {number} lineNumber |
| * @return {string} |
| */ |
| @@ -1626,3 +1684,21 @@ WebInspector.TextEditorBookMark.prototype = { |
| * }} |
| */ |
| WebInspector.CodeMirrorTextEditor.Decoration; |
| + |
| +/** |
| + * @constructor |
| + * @implements {WebInspector.TextEditorFactory} |
| + */ |
| +WebInspector.CodeMirrorTextEditorFactory = function(){ } |
| +WebInspector.CodeMirrorTextEditorFactory.prototype = { |
| + /** |
| + * @override |
| + * @param {!WebInspector.TextEditor.Options} options |
| + * @return {!WebInspector.CodeMirrorTextEditor} |
| + */ |
| + createEditor: function(options) |
| + { |
| + return new WebInspector.CodeMirrorTextEditor(options); |
| + } |
| +} |
| + |