Chromium Code Reviews| Index: Source/devtools/front_end/CodeMirrorTextEditor.js |
| diff --git a/Source/devtools/front_end/CodeMirrorTextEditor.js b/Source/devtools/front_end/CodeMirrorTextEditor.js |
| index e9787da944752e9dabec500b6d65031d656bf565..2b8551b413ba870124d53fddd66099a9f3b15426 100644 |
| --- a/Source/devtools/front_end/CodeMirrorTextEditor.js |
| +++ b/Source/devtools/front_end/CodeMirrorTextEditor.js |
| @@ -148,10 +148,17 @@ WebInspector.CodeMirrorTextEditor = function(url, delegate) |
| this._codeMirror.on("beforeChange", this._beforeChange.bind(this)); |
| this._codeMirror.on("gutterClick", this._gutterClick.bind(this)); |
| this._codeMirror.on("cursorActivity", this._cursorActivity.bind(this)); |
| + this._codeMirror.on("beforeSelectionChange", this._beforeSelectionChange.bind(this)); |
| this._codeMirror.on("scroll", this._scroll.bind(this)); |
| this._codeMirror.on("focus", this._focus.bind(this)); |
| this._codeMirror.on("blur", this._blur.bind(this)); |
| this.element.addEventListener("contextmenu", this._contextMenu.bind(this), false); |
| + this.element.addEventListener("mousedown", function() { |
|
vsevik
2013/09/04 09:46:22
FWIW We agreed to allow anonymous function only wh
lushnikov
2014/01/02 14:06:09
Done.
|
| + this._anticipateJump = true; |
| + }.bind(this), true); |
| + this.element.addEventListener("mousedown", function() { |
|
vsevik
2013/09/04 09:46:22
ditto.
lushnikov
2014/01/02 14:06:09
Done.
|
| + delete this._anticipateJump; |
| + }.bind(this), false); |
| this.element.addStyleClass("fill"); |
| this.element.style.overflow = "hidden"; |
| @@ -220,9 +227,15 @@ WebInspector.CodeMirrorTextEditor.LongLineModeLineLengthThreshold = 2000; |
| WebInspector.CodeMirrorTextEditor.MaximumNumberOfWhitespacesPerSingleSpan = 16; |
| WebInspector.CodeMirrorTextEditor.prototype = { |
| + willHide: function() |
| + { |
| + this._reportJump(this._codeMirror.getCursor("head"), null); |
| + }, |
| + |
| wasShown: function() |
| { |
| this._codeMirror.refresh(); |
| + this._reportJump(null, this._codeMirror.getCursor("head")); |
| }, |
| _guessIndentationLevel: function() |
| @@ -780,8 +793,11 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| this.revealLine(lineNumber); |
| this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight"); |
| this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bind(this), 2000); |
| - if (!this.readOnly()) |
| - this._codeMirror.setSelection(new CodeMirror.Pos(lineNumber, columnNumber)); |
| + if (!this.readOnly()) { |
| + this._anticipateJump = true; |
| + this.setSelection(WebInspector.TextRange.createFromLocation(lineNumber, columnNumber)); |
| + delete this._anticipateJump; |
| + } |
| }, |
| clearPositionHighlight: function() |
| @@ -970,6 +986,30 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| this._codeMirror.operation(this._tokenHighlighter.highlightSelectedTokens.bind(this._tokenHighlighter)); |
| }, |
| + /** |
| + * @param {CodeMirror} codeMirror |
| + * @param {{head: CodeMirror.Pos, anchor: CodeMirror.Pos}} selection |
| + */ |
| + _beforeSelectionChange: function(codeMirror, selection) |
| + { |
| + if (!this._anticipateJump) |
| + return; |
| + this._reportJump(codeMirror.getCursor("head"), selection.head) |
|
vsevik
2013/09/04 09:46:22
; is missing
lushnikov
2014/01/02 14:06:09
Done.
|
| + }, |
| + |
| + /** |
| + * @param {?CodeMirror.Pos} from |
| + * @param {?CodeMirror.Pos} to |
| + */ |
| + _reportJump: function(from, to) |
| + { |
| + if (from && to && from.line === to.line && from.ch === to.ch) |
| + return; |
| + var fromHandle = from ? new WebInspector.CodeMirrorPositionHandle(this._codeMirror, from) : null; |
| + var toHandle = to ? new WebInspector.CodeMirrorPositionHandle(this._codeMirror, to) : null; |
| + this._delegate.onJumpToPosition(fromHandle, toHandle); |
| + }, |
| + |
| _scroll: function() |
| { |
| if (this._scrollTimer) |
| @@ -1165,6 +1205,45 @@ WebInspector.CodeMirrorTextEditor.prototype = { |
| /** |
| * @constructor |
| + * @implements {WebInspector.TextEditorPositionHandle} |
| + * @param {CodeMirror} codeMirror |
| + * @param {CodeMirror.Pos} pos |
| + */ |
| +WebInspector.CodeMirrorPositionHandle = function(codeMirror, pos) |
| +{ |
| + this._codeMirror = codeMirror; |
| + this._lineHandle = codeMirror.getLineHandle(pos.line); |
| + this._columnNumber = pos.ch; |
| +} |
| + |
| +WebInspector.CodeMirrorPositionHandle.prototype = { |
| + /** |
| + * @return {?{lineNumber: number, columnNumber: number}} |
| + */ |
| + resolve: function() |
| + { |
| + var lineNumber = this._codeMirror.getLineNumber(this._lineHandle); |
| + if (typeof lineNumber !== "number") |
| + return null; |
| + return { |
| + lineNumber: lineNumber, |
| + columnNumber: this._columnNumber |
| + }; |
| + }, |
| + |
| + /** |
| + * @param {WebInspector.TextEditorPositionHandle} positionHandle |
| + * @return {boolean} |
| + */ |
| + equal: function(positionHandle) |
| + { |
| + return positionHandle._lineHandle === this._lineHandle && positionHandle._columnNumber == this._columnNumber && |
|
vsevik
2013/09/04 09:46:22
No need to split this line, but I'd name the param
lushnikov
2014/01/02 14:06:09
I love "_lineHandle" more - that's not too verbose
|
| + positionHandle._codeMirror === this._codeMirror; |
| + } |
| +} |
| + |
| +/** |
| + * @constructor |
| * @param {CodeMirror} codeMirror |
| */ |
| WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror) |