Commit 7d2f813d authored by vsevik@chromium.org's avatar vsevik@chromium.org

DevTools: Merge highlightPosition and revealLine methods on SourceFrame.

This patch keeps highlightPosition method on SourceFrame for backwards compatibility with corresponding virtual methods on View.

R=lushnikov@chromium.org, lushnikov, pfeldman

Review URL: https://codereview.chromium.org/204323003

git-svn-id: svn://svn.chromium.org/blink/trunk@169551 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 966dfcf1
...@@ -7,6 +7,7 @@ InspectorTest.createTestEditor = function(clientHeight, textEditorDelegate) ...@@ -7,6 +7,7 @@ InspectorTest.createTestEditor = function(clientHeight, textEditorDelegate)
var textEditor = new WebInspector.CodeMirrorTextEditor("", textEditorDelegate || new WebInspector.TextEditorDelegate()); var textEditor = new WebInspector.CodeMirrorTextEditor("", textEditorDelegate || new WebInspector.TextEditorDelegate());
if (clientHeight) if (clientHeight)
textEditor.element.style.height = clientHeight + "px"; textEditor.element.style.height = clientHeight + "px";
textEditor.element.style.flex = "none";
textEditor.show(WebInspector.inspectorView.element); textEditor.show(WebInspector.inspectorView.element);
return textEditor; return textEditor;
}; };
......
...@@ -27,7 +27,7 @@ function test() ...@@ -27,7 +27,7 @@ function test()
function testLineReveal(lineNumber) function testLineReveal(lineNumber)
{ {
textEditor.revealLine(lineNumber); textEditor.revealPosition(lineNumber);
var firstLine = textEditor.firstVisibleLine(); var firstLine = textEditor.firstVisibleLine();
var lastLine = textEditor.lastVisibleLine(); var lastLine = textEditor.lastVisibleLine();
var lineCentered = Math.abs(2 * lineNumber - firstLine - lastLine) <= 1; var lineCentered = Math.abs(2 * lineNumber - firstLine - lastLine) <= 1;
......
...@@ -16,7 +16,7 @@ var test = function() ...@@ -16,7 +16,7 @@ var test = function()
{ {
var executionLineSet = false; var executionLineSet = false;
var executionLineRevealed = false; var executionLineRevealed = false;
InspectorTest.addSniffer(WebInspector.SourceFrame.prototype, "revealLine", didRevealLine); InspectorTest.addSniffer(WebInspector.SourceFrame.prototype, "revealPosition", didRevealLine);
InspectorTest.addSniffer(WebInspector.JavaScriptSourceFrame.prototype, "setExecutionLine", didSetExecutionLine); InspectorTest.addSniffer(WebInspector.JavaScriptSourceFrame.prototype, "setExecutionLine", didSetExecutionLine);
InspectorTest.runTestFunctionAndWaitUntilPaused(didPaused); InspectorTest.runTestFunctionAndWaitUntilPaused(didPaused);
......
...@@ -339,7 +339,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { ...@@ -339,7 +339,7 @@ WebInspector.CodeMirrorTextEditor.prototype = {
function innerHighlightRegex() function innerHighlightRegex()
{ {
if (range) { if (range) {
this.revealLine(range.startLine); this._revealLine(range.startLine);
if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighlightLength) if (range.endColumn > WebInspector.CodeMirrorTextEditor.maxHighlightLength)
this.setSelection(range); this.setSelection(range);
else else
...@@ -685,7 +685,7 @@ WebInspector.CodeMirrorTextEditor.prototype = { ...@@ -685,7 +685,7 @@ WebInspector.CodeMirrorTextEditor.prototype = {
/** /**
* @param {number} lineNumber * @param {number} lineNumber
*/ */
revealLine: function(lineNumber) _revealLine: function(lineNumber)
{ {
this._innerRevealLine(lineNumber, this._codeMirror.getScrollInfo()); this._innerRevealLine(lineNumber, this._codeMirror.getScrollInfo());
}, },
...@@ -794,8 +794,9 @@ WebInspector.CodeMirrorTextEditor.prototype = { ...@@ -794,8 +794,9 @@ WebInspector.CodeMirrorTextEditor.prototype = {
/** /**
* @param {number} lineNumber * @param {number} lineNumber
* @param {number=} columnNumber * @param {number=} columnNumber
* @param {boolean=} shouldHighlight
*/ */
highlightPosition: function(lineNumber, columnNumber) revealPosition: function(lineNumber, columnNumber, shouldHighlight)
{ {
lineNumber = Number.constrain(lineNumber, 0, this._codeMirror.lineCount() - 1); lineNumber = Number.constrain(lineNumber, 0, this._codeMirror.lineCount() - 1);
if (typeof columnNumber !== "number") if (typeof columnNumber !== "number")
...@@ -806,9 +807,11 @@ WebInspector.CodeMirrorTextEditor.prototype = { ...@@ -806,9 +807,11 @@ WebInspector.CodeMirrorTextEditor.prototype = {
this._highlightedLine = this._codeMirror.getLineHandle(lineNumber); this._highlightedLine = this._codeMirror.getLineHandle(lineNumber);
if (!this._highlightedLine) if (!this._highlightedLine)
return; return;
this.revealLine(lineNumber); this._revealLine(lineNumber);
this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight"); if (shouldHighlight) {
this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bind(this), 2000); this._codeMirror.addLineClass(this._highlightedLine, null, "cm-highlight");
this._clearHighlightTimeout = setTimeout(this.clearPositionHighlight.bind(this), 2000);
}
this.setSelection(WebInspector.TextRange.createFromLocation(lineNumber, columnNumber)); this.setSelection(WebInspector.TextRange.createFromLocation(lineNumber, columnNumber));
}, },
......
...@@ -125,8 +125,7 @@ WebInspector.SourceFrame.prototype = { ...@@ -125,8 +125,7 @@ WebInspector.SourceFrame.prototype = {
{ {
WebInspector.View.prototype.willHide.call(this); WebInspector.View.prototype.willHide.call(this);
this._clearPositionHighlight(); this._clearPositionToReveal();
this._clearLineToReveal();
}, },
/** /**
...@@ -213,56 +212,38 @@ WebInspector.SourceFrame.prototype = { ...@@ -213,56 +212,38 @@ WebInspector.SourceFrame.prototype = {
*/ */
highlightPosition: function(line, column) highlightPosition: function(line, column)
{ {
this._clearLineToReveal(); this.revealPosition(line, column, true);
this._clearLineToScrollTo();
this._clearSelectionToSet();
this._positionToHighlight = { line: line, column: column };
this._innerHighlightPositionIfNeeded();
},
_innerHighlightPositionIfNeeded: function()
{
if (!this._positionToHighlight)
return;
if (!this.loaded || !this._isEditorShowing())
return;
this._textEditor.highlightPosition(this._positionToHighlight.line, this._positionToHighlight.column);
delete this._positionToHighlight;
},
_clearPositionHighlight: function()
{
this._textEditor.clearPositionHighlight();
delete this._positionToHighlight;
}, },
/** /**
* @param {number} line * @param {number} line
* @param {number=} column
* @param {boolean=} shouldHighlight
*/ */
revealLine: function(line) revealPosition: function(line, column, shouldHighlight)
{ {
this._clearPositionHighlight();
this._clearLineToScrollTo(); this._clearLineToScrollTo();
this._clearSelectionToSet(); this._clearSelectionToSet();
this._lineToReveal = line; this._positionToReveal = { line: line, column: column, shouldHighlight: shouldHighlight };
this._innerRevealLineIfNeeded(); this._innerRevealPositionIfNeeded();
}, },
_innerRevealLineIfNeeded: function() _innerRevealPositionIfNeeded: function()
{ {
if (typeof this._lineToReveal === "number") { if (!this._positionToReveal)
if (this.loaded && this._isEditorShowing()) { return;
this._textEditor.revealLine(this._lineToReveal);
delete this._lineToReveal; if (!this.loaded || !this._isEditorShowing())
} return;
}
this._textEditor.revealPosition(this._positionToReveal.line, this._positionToReveal.column, this._positionToReveal.shouldHighlight);
delete this._positionToReveal;
}, },
_clearLineToReveal: function() _clearPositionToReveal: function()
{ {
delete this._lineToReveal; this._textEditor.clearPositionHighlight();
delete this._positionToReveal;
}, },
/** /**
...@@ -270,8 +251,7 @@ WebInspector.SourceFrame.prototype = { ...@@ -270,8 +251,7 @@ WebInspector.SourceFrame.prototype = {
*/ */
scrollToLine: function(line) scrollToLine: function(line)
{ {
this._clearPositionHighlight(); this._clearPositionToReveal();
this._clearLineToReveal();
this._lineToScrollTo = line; this._lineToScrollTo = line;
this._innerScrollToLineIfNeeded(); this._innerScrollToLineIfNeeded();
}, },
...@@ -323,8 +303,7 @@ WebInspector.SourceFrame.prototype = { ...@@ -323,8 +303,7 @@ WebInspector.SourceFrame.prototype = {
_wasShownOrLoaded: function() _wasShownOrLoaded: function()
{ {
this._innerHighlightPositionIfNeeded(); this._innerRevealPositionIfNeeded();
this._innerRevealLineIfNeeded();
this._innerSetSelectionIfNeeded(); this._innerSetSelectionIfNeeded();
this._innerScrollToLineIfNeeded(); this._innerScrollToLineIfNeeded();
}, },
......
...@@ -716,7 +716,7 @@ WebInspector.SourcesPanel.prototype = { ...@@ -716,7 +716,7 @@ WebInspector.SourcesPanel.prototype = {
this._skipExecutionLineRevealing = true; this._skipExecutionLineRevealing = true;
var sourceFrame = this._showFile(uiSourceCode); var sourceFrame = this._showFile(uiSourceCode);
sourceFrame.revealLine(uiLocation.lineNumber); sourceFrame.revealPosition(uiLocation.lineNumber);
this._historyManager.pushNewState(); this._historyManager.pushNewState();
if (sourceFrame.canEditSource()) if (sourceFrame.canEditSource())
......
...@@ -112,11 +112,6 @@ WebInspector.TextEditor.prototype = { ...@@ -112,11 +112,6 @@ WebInspector.TextEditor.prototype = {
*/ */
removeHighlight: function(highlightDescriptor) { }, removeHighlight: function(highlightDescriptor) { },
/**
* @param {number} lineNumber
*/
revealLine: function(lineNumber) { },
/** /**
* @param {number} lineNumber * @param {number} lineNumber
* @param {boolean} disabled * @param {boolean} disabled
...@@ -157,8 +152,9 @@ WebInspector.TextEditor.prototype = { ...@@ -157,8 +152,9 @@ WebInspector.TextEditor.prototype = {
/** /**
* @param {number} lineNumber * @param {number} lineNumber
* @param {number=} columnNumber * @param {number=} columnNumber
* @param {boolean=} shouldHighlight
*/ */
highlightPosition: function(lineNumber, columnNumber) { }, revealPosition: function(lineNumber, columnNumber, shouldHighlight) { },
clearPositionHighlight: function() { }, clearPositionHighlight: function() { },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment