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

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

Issue 23474010: DevTools: "Jump between editing locations" experiment (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebaseline Created 7 years, 4 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
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..fbb3c227303d99cdfe753786d8ff14d49884bb1d 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() {
+ this._anticipateJump = true;
+ }.bind(this), true);
+ this.element.addEventListener("mousedown", function() {
+ 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)
+ },
+
+ /**
+ * @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.CodeMirrorTextEditor.TextEditorPositionHandler(this._codeMirror, from) : null;
+ var toHandle = to ? new WebInspector.CodeMirrorTextEditor.TextEditorPositionHandler(this._codeMirror, to) : null;
+ this._delegate.onJumpToPosition(fromHandle, toHandle);
+ },
+
_scroll: function()
{
if (this._scrollTimer)
@@ -1165,6 +1205,45 @@ WebInspector.CodeMirrorTextEditor.prototype = {
/**
* @constructor
+ * @implements {WebInspector.TextEditorPositionHandler}
+ * @param {CodeMirror} codeMirror
+ * @param {CodeMirror.Pos} pos
+ */
+WebInspector.CodeMirrorTextEditor.TextEditorPositionHandler = function(codeMirror, pos)
+{
+ this._codeMirror = codeMirror;
+ this._lineHandle = codeMirror.getLineHandle(pos.line);
+ this._columnNumber = pos.ch;
+}
+
+WebInspector.CodeMirrorTextEditor.TextEditorPositionHandler.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.TextEditorPositionHandler} positionHandle
+ * @return {boolean}
+ */
+ equal: function(positionHandle)
+ {
+ return positionHandle._lineHandle === this._lineHandle && positionHandle._columnNumber == this._columnNumber &&
+ positionHandle._codeMirror === this._codeMirror;
+ }
+}
+
+/**
+ * @constructor
* @param {CodeMirror} codeMirror
*/
WebInspector.CodeMirrorTextEditor.TokenHighlighter = function(codeMirror)

Powered by Google App Engine
This is Rietveld 408576698