Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js b/third_party/WebKit/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js |
| index baa31c147badd6c98f0ac991a895018b8c30f3ea..b36c888a1256c3762acd4c32c75ce6a667d599bb 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/source_frame/CodeMirrorTextEditor.js |
| @@ -31,14 +31,10 @@ |
| /** |
| * @constructor |
| * @extends {WebInspector.VBox} |
| - * @param {?string} url |
| - * @param {!WebInspector.TextEditorDelegate} delegate |
| */ |
| -WebInspector.CodeMirrorTextEditor = function(url, delegate) |
| +WebInspector.CodeMirrorTextEditor = function() |
| { |
| WebInspector.VBox.call(this); |
| - this._delegate = delegate; |
| - this._url = url; |
| /** @type {!Array<string>} */ |
| this._gutters = ["CodeMirror-linenumbers"]; |
| @@ -73,9 +69,9 @@ WebInspector.CodeMirrorTextEditor = function(url, delegate) |
| "Backspace": "delCharBefore", |
| "Tab": "defaultTab", |
| "Shift-Tab": "indentLess", |
| - "Enter": "smartNewlineAndIndent", |
| + "Enter": "newlineAndIndent", |
| "Ctrl-Space": "autocomplete", |
| - "Esc": "dismissMultipleSelections", |
| + "Esc": "dismiss", |
| "Ctrl-M": "gotoMatchingBracket" |
| }; |
| @@ -148,8 +144,6 @@ WebInspector.CodeMirrorTextEditor = function(url, delegate) |
| this._shouldClearHistory = true; |
| this._lineSeparator = "\n"; |
| - this._tokenHighlighter = new WebInspector.CodeMirrorTextEditor.TokenHighlighter(this, this._codeMirror); |
| - this._blockIndentController = new WebInspector.CodeMirrorTextEditor.BlockIndentController(this._codeMirror); |
| this._fixWordMovement = new WebInspector.CodeMirrorTextEditor.FixWordMovement(this._codeMirror); |
| this._selectNextOccurrenceController = new WebInspector.CodeMirrorTextEditor.SelectNextOccurrenceController(this, this._codeMirror); |
| @@ -241,29 +235,6 @@ CodeMirror.commands.selectCamelRight = WebInspector.CodeMirrorTextEditor.moveCam |
| /** |
| * @param {!CodeMirror} codeMirror |
| */ |
| -CodeMirror.commands.smartNewlineAndIndent = function(codeMirror) |
| -{ |
| - codeMirror.operation(innerSmartNewlineAndIndent.bind(null, codeMirror)); |
| - |
| - function innerSmartNewlineAndIndent(codeMirror) |
| - { |
| - var selections = codeMirror.listSelections(); |
| - var replacements = []; |
| - for (var i = 0; i < selections.length; ++i) { |
| - var selection = selections[i]; |
| - var cur = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? selection.head : selection.anchor; |
| - var line = codeMirror.getLine(cur.line); |
| - var indent = WebInspector.TextUtils.lineIndent(line); |
| - replacements.push("\n" + indent.substring(0, Math.min(cur.ch, indent.length))); |
| - } |
| - codeMirror.replaceSelections(replacements); |
| - codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); |
| - } |
| -} |
| - |
| -/** |
| - * @param {!CodeMirror} codeMirror |
| - */ |
| CodeMirror.commands.gotoMatchingBracket = function(codeMirror) |
| { |
| var updatedSelections = []; |
| @@ -316,7 +287,7 @@ CodeMirror.commands.redoAndReveal = function(codemirror) |
| /** |
| * @return {!Object|undefined} |
| */ |
| -CodeMirror.commands.dismissMultipleSelections = function(codemirror) |
| +CodeMirror.commands.dismiss = function(codemirror) |
| { |
| var selections = codemirror.listSelections(); |
| var selection = selections[0]; |
| @@ -326,12 +297,12 @@ CodeMirror.commands.dismissMultipleSelections = function(codemirror) |
| if (WebInspector.CodeMirrorUtils.toRange(selection.anchor, selection.head).isEmpty()) |
| return CodeMirror.Pass; |
| codemirror.setSelection(selection.anchor, selection.anchor, {scroll: false}); |
| - codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line); |
| + codemirror._codeMirrorTextEditor.scrollIntoView(selection.anchor.line); |
| return; |
| } |
| codemirror.setSelection(selection.anchor, selection.head, {scroll: false}); |
| - codemirror._codeMirrorTextEditor._revealLine(selection.anchor.line); |
| + codemirror._codeMirrorTextEditor.scrollIntoView(selection.anchor.line); |
| } |
| /** |
| @@ -365,74 +336,20 @@ WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; |
| WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
| WebInspector.CodeMirrorTextEditor.MaxEditableTextSize = 1024 * 1024 * 10; |
| -WebInspector.CodeMirrorTextEditor.LinesToScanForIndentationGuessing = 1000; |
| - |
| -/** |
| - * @param {!Array.<string>} lines |
| - * @return {string} |
| - */ |
| -WebInspector.CodeMirrorTextEditor._guessIndentationLevel = function(lines) |
| -{ |
| - var tabRegex = /^\t+/; |
| - var tabLines = 0; |
| - var indents = {}; |
| - |
| - for (var lineNumber = 0; lineNumber < lines.length; ++lineNumber) { |
| - var text = lines[lineNumber]; |
| - if (text.length === 0 || !WebInspector.TextUtils.isSpaceChar(text[0])) |
| - continue; |
| - if (tabRegex.test(text)) { |
| - ++tabLines; |
| - continue; |
| - } |
| - var i = 0; |
| - while (i < text.length && WebInspector.TextUtils.isSpaceChar(text[i])) |
| - ++i; |
| - if (i % 2 !== 0) |
| - continue; |
| - indents[i] = 1 + (indents[i] || 0); |
| - } |
| - |
| - var linesCountPerIndentThreshold = 3 * lines.length / 100; |
| - if (tabLines && tabLines > linesCountPerIndentThreshold) |
| - return "\t"; |
| - var minimumIndent = Infinity; |
| - for (var i in indents) { |
| - if (indents[i] < linesCountPerIndentThreshold) |
| - continue; |
| - var indent = parseInt(i, 10); |
| - if (minimumIndent > indent) |
| - minimumIndent = indent; |
| - } |
| - if (minimumIndent === Infinity) |
| - return WebInspector.moduleSetting("textEditorIndent").get(); |
| - return " ".repeat(minimumIndent); |
| -} |
| - |
| - |
| WebInspector.CodeMirrorTextEditor.prototype = { |
| - _onKeyHandled: function() |
| + |
| + /** |
| + * @protected |
| + * @return {!CodeMirror} |
| + */ |
| + codeMirror: function() |
| { |
| - WebInspector.shortcutRegistry.dismissPendingShortcutAction(); |
| + return this._codeMirror; |
| }, |
| - _onAutoAppendedSpaces: function() |
| + _onKeyHandled: function() |
| { |
| - this._autoAppendedSpaces = this._autoAppendedSpaces || []; |
| - for (var i = 0; i < this._autoAppendedSpaces.length; ++i) { |
| - var position = this._autoAppendedSpaces[i].resolve(); |
| - if (!position) |
| - continue; |
| - var line = this.line(position.lineNumber); |
| - if (line.length === position.columnNumber && WebInspector.TextUtils.lineIndent(line).length === line.length) |
| - this._codeMirror.replaceRange("", new CodeMirror.Pos(position.lineNumber, 0), new CodeMirror.Pos(position.lineNumber, position.columnNumber)); |
| - } |
| - this._autoAppendedSpaces = []; |
| - var selections = this.selections(); |
| - for (var i = 0; i < selections.length; ++i) { |
| - var selection = selections[i]; |
| - this._autoAppendedSpaces.push(this.textEditorPositionHandle(selection.startLine, selection.startColumn)); |
| - } |
| + WebInspector.shortcutRegistry.dismissPendingShortcutAction(); |
| }, |
| /** |
| @@ -585,8 +502,6 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| dispose: function() |
| { |
| - WebInspector.moduleSetting("textEditorIndent").removeChangeListener(this._onUpdateEditorIndentation, this); |
| - WebInspector.moduleSetting("textEditorAutoDetectIndent").removeChangeListener(this._onUpdateEditorIndentation, this); |
| WebInspector.moduleSetting("showWhitespacesInEditor").removeChangeListener(this._updateCodeMirrorMode, this); |
|
dgozman
2016/08/15 23:16:07
All the settings should be in SourcesTextEditor.
einbinder
2016/08/16 19:00:58
I moved whitespaces, but bracket matching will be
|
| WebInspector.moduleSetting("textEditorBracketMatching").removeChangeListener(this._enableBracketMatchingIfNeeded, this); |
| }, |
| @@ -615,88 +530,6 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| delete this._editorSizeInSync; |
| }, |
| - _onUpdateEditorIndentation: function() |
| - { |
| - this._setEditorIndentation(WebInspector.CodeMirrorUtils.pullLines(this._codeMirror, WebInspector.CodeMirrorTextEditor.LinesToScanForIndentationGuessing)); |
| - }, |
| - |
| - /** |
| - * @param {!Array.<string>} lines |
| - */ |
| - _setEditorIndentation: function(lines) |
| - { |
| - var extraKeys = {}; |
| - var indent = WebInspector.moduleSetting("textEditorIndent").get(); |
| - if (WebInspector.moduleSetting("textEditorAutoDetectIndent").get()) |
| - indent = WebInspector.CodeMirrorTextEditor._guessIndentationLevel(lines); |
| - if (indent === WebInspector.TextUtils.Indent.TabCharacter) { |
| - this._codeMirror.setOption("indentWithTabs", true); |
| - this._codeMirror.setOption("indentUnit", 4); |
| - } else { |
| - this._codeMirror.setOption("indentWithTabs", false); |
| - this._codeMirror.setOption("indentUnit", indent.length); |
| - extraKeys.Tab = function(codeMirror) |
| - { |
| - if (codeMirror.somethingSelected()) |
| - return CodeMirror.Pass; |
| - var pos = codeMirror.getCursor("head"); |
| - codeMirror.replaceRange(indent.substring(pos.ch % indent.length), codeMirror.getCursor()); |
| - } |
| - } |
| - this._codeMirror.setOption("extraKeys", extraKeys); |
| - this._indentationLevel = indent; |
| - }, |
| - |
| - /** |
| - * @return {string} |
| - */ |
| - indent: function() |
| - { |
| - return this._indentationLevel; |
| - }, |
| - |
| - /** |
| - * @return {boolean} |
| - */ |
| - _isSearchActive: function() |
| - { |
| - return !!this._tokenHighlighter.highlightedRegex(); |
| - }, |
| - |
| - /** |
| - * @param {!RegExp} regex |
| - * @param {?WebInspector.TextRange} range |
| - */ |
| - highlightSearchResults: function(regex, range) |
| - { |
| - /** |
| - * @this {WebInspector.CodeMirrorTextEditor} |
| - */ |
| - function innerHighlightRegex() |
| - { |
| - if (range) { |
| - this._revealLine(range.startLine); |
| - if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighlightLength) |
| - this.setSelection(range); |
| - else |
| - this.setSelection(WebInspector.TextRange.createFromLocation(range.startLine, range.startColumn)); |
| - } |
| - this._tokenHighlighter.highlightSearchResults(regex, range); |
| - } |
| - if (!this._selectionBeforeSearch) |
| - this._selectionBeforeSearch = this.selection(); |
| - this._codeMirror.operation(innerHighlightRegex.bind(this)); |
| - }, |
| - |
| - cancelSearchResultsHighlight: function() |
| - { |
| - this._codeMirror.operation(this._tokenHighlighter.highlightSelectedTokens.bind(this._tokenHighlighter)); |
| - if (this._selectionBeforeSearch) { |
| - this._reportJump(this._selectionBeforeSearch, this.selection()); |
| - delete this._selectionBeforeSearch; |
| - } |
| - }, |
| - |
| undo: function() |
| { |
| this._codeMirror.undo(); |
| @@ -974,31 +807,6 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| - * @param {!Object} highlightDescriptor |
| - */ |
| - removeHighlight: function(highlightDescriptor) |
| - { |
| - highlightDescriptor.clear(); |
| - }, |
| - |
| - /** |
| - * @param {!WebInspector.TextRange} range |
| - * @param {string} cssClass |
| - * @return {!Object} |
| - */ |
| - highlightRange: function(range, cssClass) |
| - { |
| - cssClass = "CodeMirror-persist-highlight " + cssClass; |
| - var pos = WebInspector.CodeMirrorUtils.toPos(range); |
| - ++pos.end.ch; |
| - return this._codeMirror.markText(pos.start, pos.end, { |
| - className: cssClass, |
| - startStyle: cssClass + "-start", |
| - endStyle: cssClass + "-end" |
| - }); |
| - }, |
| - |
| - /** |
| * @param {number} lineNumber |
| * @param {number} columnNumber |
| * @param {!Element} element |
| @@ -1049,7 +857,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| /** |
| * @param {number} lineNumber |
| */ |
| - _revealLine: function(lineNumber) |
| + scrollIntoView: function(lineNumber) |
|
dgozman
2016/08/15 23:16:07
scrollLineIntoView
einbinder
2016/08/16 19:00:58
Done.
|
| { |
| this._innerRevealLine(lineNumber, this._codeMirror.getScrollInfo()); |
| }, |
| @@ -1072,184 +880,6 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| } |
| }, |
| - _gutterClick: function(instance, lineNumber, gutter, event) |
| - { |
| - this.dispatchEventToListeners(WebInspector.CodeMirrorTextEditor.Events.GutterClick, { lineNumber: lineNumber, event: event }); |
| - }, |
| - |
| - _contextMenu: function(event) |
| - { |
| - var contextMenu = new WebInspector.ContextMenu(event); |
| - event.consume(true); // Consume event now to prevent document from handling the async menu |
| - var target = event.target.enclosingNodeOrSelfWithClass("CodeMirror-gutter-elt"); |
| - var promise; |
| - if (target) |
| - promise = this._delegate.populateLineGutterContextMenu(contextMenu, parseInt(target.textContent, 10) - 1); |
| - else { |
| - var textSelection = this.selection(); |
| - promise = this._delegate.populateTextAreaContextMenu(contextMenu, textSelection.startLine, textSelection.startColumn); |
| - } |
| - |
| - promise.then(showAsync.bind(this)); |
| - |
| - /** |
| - * @this {WebInspector.CodeMirrorTextEditor} |
| - */ |
| - function showAsync() |
| - { |
| - contextMenu.appendApplicableItems(this); |
| - contextMenu.show(); |
| - } |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - * @param {boolean} disabled |
| - * @param {boolean} conditional |
| - */ |
| - addBreakpoint: function(lineNumber, disabled, conditional) |
| - { |
| - if (lineNumber < 0 || lineNumber >= this._codeMirror.lineCount()) |
| - return; |
| - var className = "cm-breakpoint" + (conditional ? " cm-breakpoint-conditional" : "") + (disabled ? " cm-breakpoint-disabled" : ""); |
| - this._codeMirror.addLineClass(lineNumber, "wrap", className); |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - */ |
| - removeBreakpoint: function(lineNumber) |
| - { |
| - if (lineNumber < 0 || lineNumber >= this._codeMirror.lineCount()) |
| - return; |
| - var wrapClasses = this._codeMirror.getLineHandle(lineNumber).wrapClass; |
| - if (!wrapClasses) |
| - return; |
| - var classes = wrapClasses.split(" "); |
| - for (var i = 0; i < classes.length; ++i) { |
| - if (classes[i].startsWith("cm-breakpoint")) |
| - this._codeMirror.removeLineClass(lineNumber, "wrap", classes[i]); |
| - } |
| - }, |
| - |
| - /** |
| - * @param {string} type |
| - * @param {boolean} leftToNumbers |
| - */ |
| - installGutter: function(type, leftToNumbers) |
| - { |
| - if (this._gutters.indexOf(type) !== -1) |
| - return; |
| - if (leftToNumbers) |
| - this._gutters.unshift(type); |
| - else |
| - this._gutters.push(type); |
| - this._codeMirror.setOption("gutters", this._gutters.slice()); |
| - this._codeMirror.refresh(); |
| - }, |
| - |
| - /** |
| - * @param {string} type |
| - */ |
| - uninstallGutter: function(type) |
| - { |
| - this._gutters = this._gutters.filter(gutter => gutter !== type); |
| - this._codeMirror.setOption("gutters", this._gutters.slice()); |
| - this._codeMirror.refresh(); |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - * @param {string} type |
| - * @param {?Element} element |
| - */ |
| - setGutterDecoration: function(lineNumber, type, element) |
| - { |
| - console.assert(this._gutters.indexOf(type) !== -1, "Cannot decorate unexisting gutter.") |
| - this._codeMirror.setGutterMarker(lineNumber, type, element); |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - * @param {number} columnNumber |
| - */ |
| - setExecutionLocation: function(lineNumber, columnNumber) |
| - { |
| - this.clearPositionHighlight(); |
| - this._executionLine = this._codeMirror.getLineHandle(lineNumber); |
| - if (!this._executionLine) |
| - return; |
| - this._codeMirror.addLineClass(this._executionLine, "wrap", "cm-execution-line"); |
| - this._executionLineTailMarker = this._codeMirror.markText({ line: lineNumber, ch: columnNumber }, { line: lineNumber, ch: this._codeMirror.getLine(lineNumber).length }, { className: "cm-execution-line-tail" }); |
| - }, |
| - |
| - clearExecutionLine: function() |
| - { |
| - this.clearPositionHighlight(); |
| - if (this._executionLine) |
| - this._codeMirror.removeLineClass(this._executionLine, "wrap", "cm-execution-line"); |
| - delete this._executionLine; |
| - |
| - if (this._executionLineTailMarker) |
| - this._executionLineTailMarker.clear(); |
| - delete this._executionLineTailMarker; |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - * @param {string} className |
| - * @param {boolean} toggled |
| - */ |
| - toggleLineClass: function(lineNumber, className, toggled) |
| - { |
| - if (this.hasLineClass(lineNumber, className) === toggled) |
| - return; |
| - var lineHandle = this._codeMirror.getLineHandle(lineNumber); |
| - if (!lineHandle) |
| - return; |
| - if (toggled) { |
| - this._codeMirror.addLineClass(lineHandle, "gutter", className); |
| - this._codeMirror.addLineClass(lineHandle, "wrap", className); |
| - } else { |
| - this._codeMirror.removeLineClass(lineHandle, "gutter", className); |
| - this._codeMirror.removeLineClass(lineHandle, "wrap", className); |
| - } |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - * @param {string} className |
| - * @return {boolean} |
| - */ |
| - hasLineClass: function(lineNumber, className) |
| - { |
| - var lineInfo = this._codeMirror.lineInfo(lineNumber); |
| - var wrapClass = lineInfo.wrapClass || ""; |
| - var classNames = wrapClass.split(" "); |
| - return classNames.indexOf(className) !== -1; |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - * @param {!Element} element |
| - */ |
| - addDecoration: function(lineNumber, element) |
| - { |
| - var widget = this._codeMirror.addLineWidget(lineNumber, element); |
| - this._elementToWidget.set(element, widget); |
| - }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - * @param {!Element} element |
| - */ |
| - removeDecoration: function(lineNumber, element) |
| - { |
| - var widget = this._elementToWidget.remove(element); |
| - if (widget) |
| - this._codeMirror.removeLineWidget(widget); |
| - }, |
| - |
| /** |
| * @param {number} lineNumber 0-based |
| * @param {number=} columnNumber |
| @@ -1266,7 +896,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); |
| if (!this._highlightedLine) |
| return; |
| - this._revealLine(lineNumber); |
| + this.scrollIntoView(lineNumber); |
| if (shouldHighlight) { |
| this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight"); |
| this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bind(this), 2000); |
| @@ -1343,23 +973,6 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| }, |
| /** |
| - * @param {!WebInspector.TextRange} range |
| - * @param {string} text |
| - * @param {string=} origin |
| - * @return {!WebInspector.TextRange} |
| - */ |
| - editRange: function(range, text, origin) |
| - { |
| - var pos = WebInspector.CodeMirrorUtils.toPos(range); |
| - this._codeMirror.replaceRange(text, pos.start, pos.end, origin); |
| - var newRange = WebInspector.CodeMirrorUtils.toRange(pos.start, this._codeMirror.posFromIndex(this._codeMirror.indexFromPos(pos.start) + text.length)); |
| - this._delegate.onTextChanged(range, newRange); |
| - if (WebInspector.moduleSetting("textEditorAutoDetectIndent").get()) |
| - this._onUpdateEditorIndentation(); |
| - return newRange; |
| - }, |
| - |
| - /** |
| * @param {number} lineNumber |
| * @param {number} column |
| * @param {function(string):boolean} isWordChar |
| @@ -1393,29 +1006,6 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| if (hasOneLine !== this._hasOneLine) |
| this._resizeEditor(); |
| this._hasOneLine = hasOneLine; |
| - var widgets = this._elementToWidget.valuesArray(); |
| - for (var i = 0; i < widgets.length; ++i) |
| - this._codeMirror.removeLineWidget(widgets[i]); |
| - this._elementToWidget.clear(); |
| - |
| - if (this._muteTextChangedEvent) |
| - return; |
| - var edits = []; |
| - var currentEdit; |
| - for (var changeIndex = 0; changeIndex < changes.length; ++changeIndex) { |
| - var changeObject = changes[changeIndex]; |
| - var edit = WebInspector.CodeMirrorUtils.changeObjectToEditOperation(changeObject); |
| - if (currentEdit && edit.oldRange.equal(currentEdit.newRange)) { |
| - currentEdit.newRange = edit.newRange; |
| - } else { |
| - currentEdit = edit; |
| - edits.push(currentEdit); |
| - } |
| - } |
| - for (var i = 0; i < edits.length; ++i) { |
| - var edit = edits[i]; |
| - this._delegate.onTextChanged(edit.oldRange, edit.newRange); |
| - } |
| }, |
| _cursorActivity: function() |
| @@ -1434,34 +1024,6 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| _beforeSelectionChange: function(codeMirror, selection) |
| { |
| this._selectNextOccurrenceController.selectionWillChange(); |
| - if (!this._isHandlingMouseDownEvent) |
| - return; |
| - if (!selection.ranges.length) |
| - return; |
| - var primarySelection = selection.ranges[0]; |
| - this._reportJump(this.selection(), WebInspector.CodeMirrorUtils.toRange(primarySelection.anchor, primarySelection.head)); |
| - }, |
| - |
| - /** |
| - * @param {?WebInspector.TextRange} from |
| - * @param {?WebInspector.TextRange} to |
| - */ |
| - _reportJump: function(from, to) |
| - { |
| - if (from && to && from.equal(to)) |
| - return; |
| - this._delegate.onJumpToPosition(from, to); |
| - }, |
| - |
| - _scroll: function() |
| - { |
| - var topmostLineNumber = this._codeMirror.lineAtHeight(this._codeMirror.getScrollInfo().top, "local"); |
| - this._delegate.scrollChanged(topmostLineNumber); |
| - }, |
| - |
| - _focus: function() |
| - { |
| - this._delegate.editorFocused(); |
| }, |
| /** |
| @@ -1585,20 +1147,16 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| */ |
| setText: function(text) |
| { |
| - this._muteTextChangedEvent = true; |
| if (text.length > WebInspector.CodeMirrorTextEditor.MaxEditableTextSize) { |
| this.configureAutocomplete(null); |
| this.setReadOnly(true); |
| } |
| - |
| - this._setEditorIndentation(text.split("\n").slice(0, WebInspector.CodeMirrorTextEditor.LinesToScanForIndentationGuessing)); |
| this._codeMirror.setValue(text); |
| if (this._shouldClearHistory) { |
| this._codeMirror.clearHistory(); |
| this._shouldClearHistory = false; |
| } |
| this._detectLineSeparator(text); |
| - delete this._muteTextChangedEvent; |
| }, |
| /** |
| @@ -1731,273 +1289,6 @@ WebInspector.CodeMirrorPositionHandle.prototype = { |
| /** |
| * @constructor |
| - * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
| - * @param {!CodeMirror} codeMirror |
| - */ |
| -WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(textEditor, codeMirror) |
| -{ |
| - this._textEditor = textEditor; |
| - this._codeMirror = codeMirror; |
| -} |
| - |
| -WebInspector.CodeMirrorTextEditor.TokenHighlighter.prototype = { |
| - /** |
| - * @param {!RegExp} regex |
| - * @param {?WebInspector.TextRange} range |
| - */ |
| - highlightSearchResults: function(regex, range) |
| - { |
| - var oldRegex = this._highlightRegex; |
| - this._highlightRegex = regex; |
| - this._highlightRange = range; |
| - if (this._searchResultMarker) { |
| - this._searchResultMarker.clear(); |
| - delete this._searchResultMarker; |
| - } |
| - if (this._highlightDescriptor && this._highlightDescriptor.selectionStart) |
| - this._codeMirror.removeLineClass(this._highlightDescriptor.selectionStart.line, "wrap", "cm-line-with-selection"); |
| - var selectionStart = this._highlightRange ? new CodeMirror.Pos(this._highlightRange.startLine, this._highlightRange.startColumn) : null; |
| - if (selectionStart) |
| - this._codeMirror.addLineClass(selectionStart.line, "wrap", "cm-line-with-selection"); |
| - if (this._highlightRegex === oldRegex) { |
| - // Do not re-add overlay mode if regex did not change for better performance. |
| - if (this._highlightDescriptor) |
| - this._highlightDescriptor.selectionStart = selectionStart; |
| - } else { |
| - this._removeHighlight(); |
| - this._setHighlighter(this._searchHighlighter.bind(this, this._highlightRegex), selectionStart); |
| - } |
| - if (this._highlightRange) { |
| - var pos = WebInspector.CodeMirrorUtils.toPos(this._highlightRange); |
| - this._searchResultMarker = this._codeMirror.markText(pos.start, pos.end, {className: "cm-column-with-selection"}); |
| - } |
| - }, |
| - |
| - /** |
| - * @return {!RegExp|undefined} |
| - */ |
| - highlightedRegex: function() |
| - { |
| - return this._highlightRegex; |
| - }, |
| - |
| - highlightSelectedTokens: function() |
| - { |
| - delete this._highlightRegex; |
| - delete this._highlightRange; |
| - |
| - if (this._highlightDescriptor && this._highlightDescriptor.selectionStart) |
| - this._codeMirror.removeLineClass(this._highlightDescriptor.selectionStart.line, "wrap", "cm-line-with-selection"); |
| - this._removeHighlight(); |
| - var selectionStart = this._codeMirror.getCursor("start"); |
| - var selectionEnd = this._codeMirror.getCursor("end"); |
| - if (selectionStart.line !== selectionEnd.line) |
| - return; |
| - if (selectionStart.ch === selectionEnd.ch) |
| - return; |
| - |
| - var selections = this._codeMirror.getSelections(); |
| - if (selections.length > 1) |
| - return; |
| - var selectedText = selections[0]; |
| - if (this._isWord(selectedText, selectionStart.line, selectionStart.ch, selectionEnd.ch)) { |
| - if (selectionStart) |
| - this._codeMirror.addLineClass(selectionStart.line, "wrap", "cm-line-with-selection"); |
| - this._setHighlighter(this._tokenHighlighter.bind(this, selectedText, selectionStart), selectionStart); |
| - } |
| - }, |
| - |
| - /** |
| - * @param {string} selectedText |
| - * @param {number} lineNumber |
| - * @param {number} startColumn |
| - * @param {number} endColumn |
| - */ |
| - _isWord: function(selectedText, lineNumber, startColumn, endColumn) |
| - { |
| - var line = this._codeMirror.getLine(lineNumber); |
| - var leftBound = startColumn === 0 || !WebInspector.TextUtils.isWordChar(line.charAt(startColumn - 1)); |
| - var rightBound = endColumn === line.length || !WebInspector.TextUtils.isWordChar(line.charAt(endColumn)); |
| - return leftBound && rightBound && WebInspector.TextUtils.isWord(selectedText); |
| - }, |
| - |
| - _removeHighlight: function() |
| - { |
| - if (this._highlightDescriptor) { |
| - this._codeMirror.removeOverlay(this._highlightDescriptor.overlay); |
| - delete this._highlightDescriptor; |
| - } |
| - }, |
| - |
| - /** |
| - * @param {!RegExp} regex |
| - * @param {!CodeMirror.StringStream} stream |
| - */ |
| - _searchHighlighter: function(regex, stream) |
| - { |
| - if (stream.column() === 0) |
| - delete this._searchMatchLength; |
| - if (this._searchMatchLength) { |
| - if (this._searchMatchLength > 2) { |
| - for (var i = 0; i < this._searchMatchLength - 2; ++i) |
| - stream.next(); |
| - this._searchMatchLength = 1; |
| - return "search-highlight"; |
| - } else { |
| - stream.next(); |
| - delete this._searchMatchLength; |
| - return "search-highlight search-highlight-end"; |
| - } |
| - } |
| - var match = stream.match(regex, false); |
| - if (match) { |
| - stream.next(); |
| - var matchLength = match[0].length; |
| - if (matchLength === 1) |
| - return "search-highlight search-highlight-full"; |
| - this._searchMatchLength = matchLength; |
| - return "search-highlight search-highlight-start"; |
| - } |
| - |
| - while (!stream.match(regex, false) && stream.next()) {} |
| - }, |
| - |
| - /** |
| - * @param {string} token |
| - * @param {!CodeMirror.Pos} selectionStart |
| - * @param {!CodeMirror.StringStream} stream |
| - */ |
| - _tokenHighlighter: function(token, selectionStart, stream) |
| - { |
| - var tokenFirstChar = token.charAt(0); |
| - if (stream.match(token) && (stream.eol() || !WebInspector.TextUtils.isWordChar(stream.peek()))) |
| - return stream.column() === selectionStart.ch ? "token-highlight column-with-selection" : "token-highlight"; |
| - |
| - var eatenChar; |
| - do { |
| - eatenChar = stream.next(); |
| - } while (eatenChar && (WebInspector.TextUtils.isWordChar(eatenChar) || stream.peek() !== tokenFirstChar)); |
| - }, |
| - |
| - /** |
| - * @param {function(!CodeMirror.StringStream)} highlighter |
| - * @param {?CodeMirror.Pos} selectionStart |
| - */ |
| - _setHighlighter: function(highlighter, selectionStart) |
| - { |
| - var overlayMode = { |
| - token: highlighter |
| - }; |
| - this._codeMirror.addOverlay(overlayMode); |
| - this._highlightDescriptor = { |
| - overlay: overlayMode, |
| - selectionStart: selectionStart |
| - }; |
| - } |
| -} |
| - |
| -/** |
| - * @constructor |
| - * @param {!CodeMirror} codeMirror |
| - */ |
| -WebInspector.CodeMirrorTextEditor.BlockIndentController = function(codeMirror) |
| -{ |
| - codeMirror.addKeyMap(this); |
| -} |
| - |
| -WebInspector.CodeMirrorTextEditor.BlockIndentController.prototype = { |
| - name: "blockIndentKeymap", |
| - |
| - /** |
| - * @return {*} |
| - */ |
| - Enter: function(codeMirror) |
| - { |
| - var selections = codeMirror.listSelections(); |
| - var replacements = []; |
| - var allSelectionsAreCollapsedBlocks = false; |
| - for (var i = 0; i < selections.length; ++i) { |
| - var selection = selections[i]; |
| - var start = CodeMirror.cmpPos(selection.head, selection.anchor) < 0 ? selection.head : selection.anchor; |
| - var line = codeMirror.getLine(start.line); |
| - var indent = WebInspector.TextUtils.lineIndent(line); |
| - var indentToInsert = "\n" + indent + codeMirror._codeMirrorTextEditor.indent(); |
| - var isCollapsedBlock = false; |
| - if (selection.head.ch === 0) |
| - return CodeMirror.Pass; |
| - if (line.substr(selection.head.ch - 1, 2) === "{}") { |
| - indentToInsert += "\n" + indent; |
| - isCollapsedBlock = true; |
| - } else if (line.substr(selection.head.ch - 1, 1) !== "{") { |
| - return CodeMirror.Pass; |
| - } |
| - if (i > 0 && allSelectionsAreCollapsedBlocks !== isCollapsedBlock) |
| - return CodeMirror.Pass; |
| - replacements.push(indentToInsert); |
| - allSelectionsAreCollapsedBlocks = isCollapsedBlock; |
| - } |
| - codeMirror.replaceSelections(replacements); |
| - if (!allSelectionsAreCollapsedBlocks) { |
| - codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); |
| - return; |
| - } |
| - selections = codeMirror.listSelections(); |
| - var updatedSelections = []; |
| - for (var i = 0; i < selections.length; ++i) { |
| - var selection = selections[i]; |
| - var line = codeMirror.getLine(selection.head.line - 1); |
| - var position = new CodeMirror.Pos(selection.head.line - 1, line.length); |
| - updatedSelections.push({ |
| - head: position, |
| - anchor: position |
| - }); |
| - } |
| - codeMirror.setSelections(updatedSelections); |
| - codeMirror._codeMirrorTextEditor._onAutoAppendedSpaces(); |
| - }, |
| - |
| - /** |
| - * @return {*} |
| - */ |
| - "'}'": function(codeMirror) |
| - { |
| - if (codeMirror.somethingSelected()) |
| - return CodeMirror.Pass; |
| - |
| - var selections = codeMirror.listSelections(); |
| - var replacements = []; |
| - for (var i = 0; i < selections.length; ++i) { |
| - var selection = selections[i]; |
| - var line = codeMirror.getLine(selection.head.line); |
| - if (line !== WebInspector.TextUtils.lineIndent(line)) |
| - return CodeMirror.Pass; |
| - replacements.push("}"); |
| - } |
| - |
| - codeMirror.replaceSelections(replacements); |
| - selections = codeMirror.listSelections(); |
| - replacements = []; |
| - var updatedSelections = []; |
| - for (var i = 0; i < selections.length; ++i) { |
| - var selection = selections[i]; |
| - var matchingBracket = codeMirror.findMatchingBracket(selection.head); |
| - if (!matchingBracket || !matchingBracket.match) |
| - return; |
| - updatedSelections.push({ |
| - head: selection.head, |
| - anchor: new CodeMirror.Pos(selection.head.line, 0) |
| - }); |
| - var line = codeMirror.getLine(matchingBracket.to.line); |
| - var indent = WebInspector.TextUtils.lineIndent(line); |
| - replacements.push(indent + "}"); |
| - } |
| - codeMirror.setSelections(updatedSelections); |
| - codeMirror.replaceSelections(replacements); |
| - } |
| -} |
| - |
| -/** |
| - * @constructor |
| * @param {!CodeMirror} codeMirror |
| */ |
| WebInspector.CodeMirrorTextEditor.FixWordMovement = function(codeMirror) |
| @@ -2115,7 +1406,7 @@ WebInspector.CodeMirrorTextEditor.SelectNextOccurrenceController.prototype = { |
| this._textEditor.setSelections(selections, selections.length - 1); |
| delete this._muteSelectionListener; |
| - this._textEditor._revealLine(next.startLine); |
| + this._textEditor.scrollIntoView(next.startLine); |
| }, |
| /** |
| @@ -2237,64 +1528,10 @@ WebInspector.TextEditorPositionHandle.prototype = { |
| equal: function(positionHandle) { } |
| } |
| -/** |
| - * @interface |
| - */ |
| -WebInspector.TextEditorDelegate = function() {} |
| - |
| -WebInspector.TextEditorDelegate.prototype = { |
| - /** |
| - * @param {!WebInspector.TextRange} oldRange |
| - * @param {!WebInspector.TextRange} newRange |
| - */ |
| - onTextChanged: function(oldRange, newRange) { }, |
| - |
| - /** |
| - * @param {!WebInspector.TextRange} textRange |
| - */ |
| - selectionChanged: function(textRange) { }, |
| - |
| - /** |
| - * @param {number} lineNumber |
| - */ |
| - scrollChanged: function(lineNumber) { }, |
| - |
| - editorFocused: function() { }, |
| - |
| - /** |
| - * @param {!WebInspector.ContextMenu} contextMenu |
| - * @param {number} lineNumber |
| - * @return {!Promise} |
| - */ |
| - populateLineGutterContextMenu: function(contextMenu, lineNumber) { }, |
| - |
| - /** |
| - * @param {!WebInspector.ContextMenu} contextMenu |
| - * @param {number} lineNumber |
| - * @param {number} columnNumber |
| - * @return {!Promise} |
| - */ |
| - populateTextAreaContextMenu: function(contextMenu, lineNumber, columnNumber) { }, |
| - |
| - /** |
| - * @param {?WebInspector.TextRange} from |
| - * @param {?WebInspector.TextRange} to |
| - */ |
| - onJumpToPosition: function(from, to) { } |
| -} |
| - |
| WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("css", "css-"); |
| WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("javascript", "js-"); |
| WebInspector.CodeMirrorTextEditor._overrideModeWithPrefixedTokens("xml", "xml-"); |
| -/** @typedef {{lineNumber: number, event: !Event}} */ |
| -WebInspector.CodeMirrorTextEditor.GutterClickEventData; |
| - |
| -/** @enum {string} */ |
| -WebInspector.CodeMirrorTextEditor.Events = { |
| - GutterClick: "GutterClick" |
| -} |
| - |
| /** @type {!Set<!Runtime.Extension>} */ |
| WebInspector.CodeMirrorTextEditor._loadedMimeModeExtensions = new Set(); |